amap-yunjing-cesiumjs
Version:
云镜给CesiumJS 实现的高斯渲染插件
2 lines • 1.3 MB
JavaScript
!function(t,e){"use strict";var n="undefined"!=typeof document?document.currentScript:null;function i(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var r=i(e);class s extends r.Terrain{constructor(t){let e;switch(t.crs){case"gcj02":default:e="China02";break;case"wgs84":e="China"}const n=t.url||`https://amappc.oss-cn-zhangjiakou.aliyuncs.com/gis/gaus/Terrain/${e}`;super(r.CesiumTerrainProvider.fromUrl(n))}}class o extends r.ImageryLayer{constructor(t){super(new r.UrlTemplateImageryProvider({url:"https://webst0{S}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",minimumLevel:3,maximumLevel:t?.maximumLevel||18,customTags:{S:function(t,e,n,i){return(e+n)%4+1}}}))}}class a extends r.ImageryLayer{constructor(t){t.zooms=t.zooms||[3,18],super(new r.UrlTemplateImageryProvider({url:t.url,tileWidth:t.tileSize||256,tileHeight:t.tileSize||256,minimumLevel:t.zooms[0],maximumLevel:t.zooms[1],customTags:{S:function(t,e,n,i){return(e+n)%4+1}}}))}}var u,h,l,c,f,d,p,v,m,y,w,g,b,_,x,k,$,S,M,E,C,A,O,I,T,z,R,F,P,D,N,U,q,j=Object.defineProperty,B=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyNames,H={}.hasOwnProperty,W=(u=function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')},typeof require<"u"?require:typeof Proxy<"u"?new Proxy(u,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):u),V=(t,e)=>()=>(t&&(e=t(t=0)),e),G=(t,e)=>{for(var n in e)j(t,n,{get:e[n],enumerable:!0})},Y=t=>((t,e,n,i)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let n of L(e))!H.call(t,n)&&void 0!==n&&j(t,n,{get:()=>e[n],enumerable:!(i=B(e,n))||i.enumerable});return t})(j({},"__esModule",{value:!0}),t),K=V((()=>{h=new Map,l=[],c=(t,e,n)=>{if(!e||"function"!=typeof e.init||"function"!=typeof e.createInferenceSessionHandler)throw new TypeError("not a valid backend");{let i=h.get(t);if(void 0===i)h.set(t,{backend:e,priority:n});else{if(i.priority>n)return;if(i.priority===n&&i.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${n}`)}if(n>=0){let e=l.indexOf(t);-1!==e&&l.splice(e,1);for(let e=0;e<l.length;e++)if(h.get(l[e]).priority<=n)return void l.splice(e,0,t);l.push(t)}}},f=async t=>{let e=h.get(t);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let n=!!e.initPromise;try{return n||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(t){return n||(e.error=`${t}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},d=async t=>{let e,n=t.executionProviders||[],i=n.map((t=>"string"==typeof t?t:t.name)),r=0===i.length?l:i,s=[],o=new Set;for(let t of r){let n=await f(t);"string"==typeof n?s.push({name:t,err:n}):(e||(e=n),e===n&&o.add(t))}if(!e)throw new Error(`no available backend found. ERR: ${s.map((t=>`[${t.name}] ${t.err}`)).join(", ")}`);for(let{name:t,err:e}of s)i.includes(t);let a=n.filter((t=>o.has("string"==typeof t?t:t.name)));return[e,new Proxy(t,{get:(t,e)=>"executionProviders"===e?a:Reflect.get(t,e)})]}})),X=V((()=>{K()})),Q=V((()=>{p="1.19.2"})),Z=V((()=>{Q(),v="warning",m={wasm:{},webgl:{},webgpu:{},versions:{common:p},set logLevel(t){if(void 0!==t){if("string"!=typeof t||-1===["verbose","info","warning","error","fatal"].indexOf(t))throw new Error(`Unsupported logging level: ${t}`);v=t}},get logLevel(){return v}},Object.defineProperty(m,"logLevel",{enumerable:!0})})),J=V((()=>{Z(),y=m})),tt=V((()=>{w=(t,e)=>{let n=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=t.dims[3],n.height=t.dims[2];let i=n.getContext("2d");if(null!=i){let r,s;void 0!==e?.tensorLayout&&"NHWC"===e.tensorLayout?(r=t.dims[2],s=t.dims[3]):(r=t.dims[3],s=t.dims[2]);let o,a,u=void 0!==e?.format?e.format:"RGB",h=e?.norm;void 0===h||void 0===h.mean?o=[255,255,255,255]:"number"==typeof h.mean?o=[h.mean,h.mean,h.mean,h.mean]:(o=[h.mean[0],h.mean[1],h.mean[2],0],void 0!==h.mean[3]&&(o[3]=h.mean[3])),void 0===h||void 0===h.bias?a=[0,0,0,0]:"number"==typeof h.bias?a=[h.bias,h.bias,h.bias,h.bias]:(a=[h.bias[0],h.bias[1],h.bias[2],0],void 0!==h.bias[3]&&(a[3]=h.bias[3]));let l=s*r,c=0,f=l,d=2*l,p=-1;"RGBA"===u?(c=0,f=l,d=2*l,p=3*l):"RGB"===u?(c=0,f=l,d=2*l):"RBG"===u&&(c=0,d=l,f=2*l);for(let e=0;e<s;e++)for(let n=0;n<r;n++){let r=(t.data[c++]-a[0])*o[0],s=(t.data[f++]-a[1])*o[1],u=(t.data[d++]-a[2])*o[2],h=-1===p?255:(t.data[p++]-a[3])*o[3];i.fillStyle="rgba("+r+","+s+","+u+","+h+")",i.fillRect(n,e,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")},g=(t,e)=>{let n,i=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");if(null==i)throw new Error("Can not access image data");{let r,s,o;void 0!==e?.tensorLayout&&"NHWC"===e.tensorLayout?(r=t.dims[2],s=t.dims[1],o=t.dims[3]):(r=t.dims[3],s=t.dims[2],o=t.dims[1]);let a,u,h=void 0!==e&&void 0!==e.format?e.format:"RGB",l=e?.norm;void 0===l||void 0===l.mean?a=[255,255,255,255]:"number"==typeof l.mean?a=[l.mean,l.mean,l.mean,l.mean]:(a=[l.mean[0],l.mean[1],l.mean[2],255],void 0!==l.mean[3]&&(a[3]=l.mean[3])),void 0===l||void 0===l.bias?u=[0,0,0,0]:"number"==typeof l.bias?u=[l.bias,l.bias,l.bias,l.bias]:(u=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(u[3]=l.bias[3]));let c=s*r;if(void 0!==e&&(void 0!==e.format&&4===o&&"RGBA"!==e.format||3===o&&"RGB"!==e.format&&"BGR"!==e.format))throw new Error("Tensor format doesn't match input tensor dims");let f=4,d=0,p=1,v=2,m=3,y=0,w=c,g=2*c,b=-1;"RGBA"===h?(y=0,w=c,g=2*c,b=3*c):"RGB"===h?(y=0,w=c,g=2*c):"RBG"===h&&(y=0,g=c,w=2*c),n=i.createImageData(r,s);for(let e=0;e<s*r;d+=f,p+=f,v+=f,m+=f,e++)n.data[d]=(t.data[y++]-u[0])*a[0],n.data[p]=(t.data[w++]-u[1])*a[1],n.data[v]=(t.data[g++]-u[2])*a[2],n.data[m]=-1===b?255:(t.data[b++]-u[3])*a[3]}return n}})),et=V((()=>{rt(),b=(t,e)=>{if(void 0===t)throw new Error("Image buffer must be defined");if(void 0===e.height||void 0===e.width)throw new Error("Image height and width must be defined");if("NHWC"===e.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");let n,i,{height:r,width:s}=e,o=e.norm??{mean:255,bias:0};n="number"==typeof o.mean?[o.mean,o.mean,o.mean,o.mean]:[o.mean[0],o.mean[1],o.mean[2],o.mean[3]??255],i="number"==typeof o.bias?[o.bias,o.bias,o.bias,o.bias]:[o.bias[0],o.bias[1],o.bias[2],o.bias[3]??0];let a=void 0!==e.format?e.format:"RGBA",u=void 0!==e.tensorFormat&&void 0!==e.tensorFormat?e.tensorFormat:"RGB",h=r*s,l="RGBA"===u?new Float32Array(4*h):new Float32Array(3*h),c=4,f=0,d=1,p=2,v=3,m=0,y=h,w=2*h,g=-1;"RGB"===a&&(c=3,f=0,d=1,p=2,v=-1),"RGBA"===u?g=3*h:"RBG"===u?(m=0,w=h,y=2*h):"BGR"===u&&(w=0,y=h,m=2*h);for(let e=0;e<h;e++,f+=c,p+=c,d+=c,v+=c)l[m++]=(t[f]+i[0])/n[0],l[y++]=(t[d]+i[1])/n[1],l[w++]=(t[p]+i[2])/n[2],-1!==g&&-1!==v&&(l[g++]=(t[v]+i[3])/n[3]);return new I("float32",l,"RGBA"===u?[1,4,r,s]:[1,3,r,s])},_=async(t,e)=>{let n,i=typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement,r=typeof ImageData<"u"&&t instanceof ImageData,s=typeof ImageBitmap<"u"&&t instanceof ImageBitmap,o="string"==typeof t,a=e??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},h=t=>t instanceof HTMLCanvasElement||t instanceof OffscreenCanvas?t.getContext("2d"):null;if(i){let i=u();i.width=t.width,i.height=t.height;let r=h(i);if(null==r)throw new Error("Can not access image data");{let i=t.height,s=t.width;if(void 0!==e&&void 0!==e.resizedHeight&&void 0!==e.resizedWidth&&(i=e.resizedHeight,s=e.resizedWidth),void 0!==e){if(a=e,void 0!==e.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");a.tensorFormat="RGBA",a.height=i,a.width=s}else a.tensorFormat="RGBA",a.height=i,a.width=s;r.drawImage(t,0,0),n=r.getImageData(0,0,s,i).data}}else{if(!r){if(s){if(void 0===e)throw new Error("Please provide image config with format for Imagebitmap");let i=u();i.width=t.width,i.height=t.height;let r=h(i);if(null!=r){let e=t.height,i=t.width;return r.drawImage(t,0,0,i,e),n=r.getImageData(0,0,i,e).data,a.height=e,a.width=i,b(n,a)}throw new Error("Can not access image data")}if(o)return new Promise(((e,n)=>{let i=u(),r=h(i);if(!t||!r)return n();let s=new Image;s.crossOrigin="Anonymous",s.src=t,s.onload=()=>{i.width=s.width,i.height=s.height,r.drawImage(s,0,0,i.width,i.height);let t=r.getImageData(0,0,i.width,i.height);a.height=i.height,a.width=i.width,e(b(t.data,a))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let i,r;if(void 0!==e&&void 0!==e.resizedWidth&&void 0!==e.resizedHeight?(i=e.resizedHeight,r=e.resizedWidth):(i=t.height,r=t.width),void 0!==e&&(a=e),a.format="RGBA",a.height=i,a.width=r,void 0!==e){let e=u();e.width=r,e.height=i;let s=h(e);if(null==s)throw new Error("Can not access image data");s.putImageData(t,0,0),n=s.getImageData(0,0,r,i).data}else n=t.data}}if(void 0!==n)return b(n,a);throw new Error("Input data provided is not supported - aborted tensor creation")},x=(t,e)=>{let{width:n,height:i,download:r,dispose:s}=e;return new I({location:"texture",type:"float32",texture:t,dims:[1,i,n,4],download:r,dispose:s})},k=(t,e)=>{let{dataType:n,dims:i,download:r,dispose:s}=e;return new I({location:"gpu-buffer",type:n??"float32",gpuBuffer:t,dims:i,download:r,dispose:s})},$=(t,e,n)=>new I({location:"cpu-pinned",type:t,data:e,dims:n??[e.length]})})),nt=V((()=>{S=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),M=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),E=!1,C=()=>{if(!E){E=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,n=typeof Float16Array<"u"&&Float16Array.from;t&&(S.set("int64",BigInt64Array),M.set(BigInt64Array,"int64")),e&&(S.set("uint64",BigUint64Array),M.set(BigUint64Array,"uint64")),n?(S.set("float16",Float16Array),M.set(Float16Array,"float16")):S.set("float16",Uint16Array)}}})),it=V((()=>{rt(),A=t=>{let e=1;for(let n=0;n<t.length;n++){let i=t[n];if("number"!=typeof i||!Number.isSafeInteger(i))throw new TypeError(`dims[${n}] must be an integer, got: ${i}`);if(i<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${i}`);e*=i}return e},O=(t,e)=>{switch(t.location){case"cpu":return new I(t.type,t.data,e);case"cpu-pinned":return new I({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new I({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new I({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}})),rt=V((()=>{tt(),et(),nt(),it(),I=class{constructor(t,e,n){let i,r;if(C(),"object"==typeof t&&"location"in t)switch(this.dataLocation=t.location,i=t.type,r=t.dims,t.location){case"cpu-pinned":{let e=S.get(i);if(!e)throw new TypeError(`unsupported type "${i}" to create tensor from pinned buffer`);if(!(t.data instanceof e))throw new TypeError(`buffer should be of type ${e.name}`);this.cpuData=t.data;break}case"texture":if("float32"!==i)throw new TypeError(`unsupported type "${i}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break;case"gpu-buffer":if("float32"!==i&&"float16"!==i&&"int32"!==i&&"int64"!==i&&"uint32"!==i&&"uint8"!==i&&"bool"!==i)throw new TypeError(`unsupported type "${i}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break;default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let s,o;if("string"==typeof t)if(i=t,o=n,"string"===t){if(!Array.isArray(e))throw new TypeError("A string tensor's data must be a string array.");s=e}else{let n=S.get(t);if(void 0===n)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(e)){if("float16"===t&&n===Uint16Array)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");s="uint64"===t||"int64"===t?n.from(e,BigInt):n.from(e)}else{if(!(e instanceof n))throw new TypeError(`A ${i} tensor's data must be type of ${n}`);s=e}}else if(o=e,Array.isArray(t)){if(0===t.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");let e=typeof t[0];if("string"===e)i="string",s=t;else{if("boolean"!==e)throw new TypeError(`Invalid element type of data array: ${e}.`);i="bool",s=Uint8Array.from(t)}}else{let e=M.get(t.constructor);if(void 0===e)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);i=e,s=t}if(void 0===o)o=[s.length];else if(!Array.isArray(o))throw new TypeError("A tensor's dims must be a number array");r=o,this.cpuData=s,this.dataLocation="cpu"}let s=A(r);if(this.cpuData&&s!==this.cpuData.length)throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=i,this.dims=r,this.size=s}static async fromImage(t,e){return _(t,e)}static fromTexture(t,e){return x(t,e)}static fromGpuBuffer(t,e){return k(t,e)}static fromPinnedBuffer(t,e,n){return $(t,e,n)}toDataURL(t){return w(this,t)}toImageData(t){return g(this,t)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}async getData(t){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let e=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=e,t&&this.disposer&&(this.disposer(),this.disposer=void 0),e}finally{this.isDownloading=!1}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if("none"===this.dataLocation)throw new Error("The tensor is disposed.")}reshape(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return O(this,t)}}})),st=V((()=>{rt(),T=I})),ot=V((()=>{Z(),z=(t,e)=>{typeof m.trace>"u"?m.wasm.trace:m.trace},R=(t,e)=>{let n=(new Error).stack?.split(/\r\n|\r|\n/g)||[],i=!1;for(let r=0;r<n.length;r++){if(i&&!n[r].includes("TRACE_FUNC")){let i=`FUNC_${t}::${n[r].trim().split(" ")[1]}`;return e&&(i+=`::${e}`),void z("CPU",i)}n[r].includes("TRACE_FUNC")&&(i=!0)}},F=t=>{(typeof m.trace>"u"?!m.wasm.trace:!m.trace)||R("BEGIN",t)},P=t=>{(typeof m.trace>"u"?!m.wasm.trace:!m.trace)||R("END",t)}})),at=V((()=>{K(),st(),ot(),D=class t{constructor(t){this.handler=t}async run(t,e,n){F();let i={},r={};if("object"!=typeof t||null===t||t instanceof T||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if("object"==typeof e){if(null===e)throw new TypeError("Unexpected argument[1]: cannot be null.");if(e instanceof T)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(e)){if(0===e.length)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let t of e){if("string"!=typeof t)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(t))throw new RangeError(`'fetches' contains invalid output name: ${t}.`);i[t]=null}if("object"==typeof n&&null!==n)r=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let t=!1,o=Object.getOwnPropertyNames(e);for(let n of this.outputNames)if(-1!==o.indexOf(n)){let r=e[n];(null===r||r instanceof T)&&(t=!0,s=!1,i[n]=r)}if(t){if("object"==typeof n&&null!==n)r=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else r=e}}else if(typeof e<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let e of this.inputNames)if(typeof t[e]>"u")throw new Error(`input '${e}' is missing in 'feeds'.`);if(s)for(let t of this.outputNames)i[t]=null;let o=await this.handler.run(t,i,r),a={};for(let t in o)if(Object.hasOwnProperty.call(o,t)){let e=o[t];a[t]=e instanceof T?e:new T(e.type,e.data,e.dims)}return P(),a}async release(){return this.handler.dispose()}static async create(e,n,i,r){F();let s,o={};if("string"==typeof e){if(s=e,"object"==typeof n&&null!==n)o=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(s=e,"object"==typeof n&&null!==n)o=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{if(!(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{let t=e,a=0,u=e.byteLength;if("object"==typeof n&&null!==n)o=n;else if("number"==typeof n){if(a=n,!Number.isSafeInteger(a))throw new RangeError("'byteOffset' must be an integer.");if(a<0||a>=t.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${t.byteLength}).`);if(u=e.byteLength-a,"number"==typeof i){if(u=i,!Number.isSafeInteger(u))throw new RangeError("'byteLength' must be an integer.");if(u<=0||a+u>t.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${t.byteLength-a}].`);if("object"==typeof r&&null!==r)o=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(typeof i<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof n<"u")throw new TypeError("'options' must be an object.");s=new Uint8Array(t,a,u)}}let[a,u]=await d(o),h=await a.createInferenceSessionHandler(s,u);return P(),new t(h)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}})),ut=V((()=>{at(),N=D})),ht=V((()=>{})),lt=V((()=>{})),ct=V((()=>{})),ft=V((()=>{})),dt=V((()=>{K(),st(),U=class t{constructor(t,e,n){this.handler=t,this.hasOptimizerModel=e,this.hasEvalModel=n}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,n){let i=e.evalModel||"",r=e.optimizerModel||"",s=n||{},[o,a]=await d(s);if(o.createTrainingSessionHandler){let n=await o.createTrainingSessionHandler(e.checkpointState,e.trainModel,i,r,a);return new t(n,!!e.optimizerModel,!!e.evalModel)}throw new Error("Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.")}typeNarrowingForRunStep(t,e,n,i,r){let s={},o={};if("object"!=typeof n||null===n||n instanceof T||Array.isArray(n))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if("object"==typeof i){if(null===i)throw new TypeError("Unexpected argument[1]: cannot be null.");if(i instanceof T)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(i)){if(0===i.length)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let t of i){if("string"!=typeof t)throw new TypeError("'fetches' must be a string array or an object.");if(-1===e.indexOf(t))throw new RangeError(`'fetches' contains invalid output name: ${t}.`);s[t]=null}if("object"==typeof r&&null!==r)o=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else{let t=!1,n=Object.getOwnPropertyNames(i);for(let r of e)if(-1!==n.indexOf(r)){let e=i[r];(null===e||e instanceof T)&&(t=!0,a=!1,s[r]=e)}if(t){if("object"==typeof r&&null!==r)o=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else o=i}}else if(typeof i<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let e of t)if(typeof n[e]>"u")throw new Error(`input '${e}' is missing in 'feeds'.`);if(a)for(let t of e)s[t]=null;return[s,o]}convertHandlerReturnTypeToMapOfTensors(t){let e={};for(let n in t)if(Object.hasOwnProperty.call(t,n)){let i=t[n];e[n]=i instanceof T?i:new T(i.type,i.data,i.dims)}return e}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(t,e,n){let[i,r]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,t,e,n),s=await this.handler.runTrainStep(t,i,r);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(t){if(!this.hasOptimizerModel)throw new Error("This TrainingSession has no OptimizerModel loaded.");await this.handler.runOptimizerStep(t||{})}async runEvalStep(t,e,n){if(this.hasEvalModel){let[i,r]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,t,e,n),s=await this.handler.runEvalStep(t,i,r);return this.convertHandlerReturnTypeToMapOfTensors(s)}throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(t=!0){return this.handler.getParametersSize(t)}async loadParametersBuffer(t,e=!0){let n=await this.getParametersSize(e);if(t.length!==4*n)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(t,e)}async getContiguousParameters(t=!0){return this.handler.getContiguousParameters(t)}async release(){return this.handler.dispose()}}})),pt=V((()=>{dt(),q=U})),vt={};G(vt,{InferenceSession:()=>N,TRACE:()=>z,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>P,Tensor:()=>T,TrainingSession:()=>q,env:()=>y,registerBackend:()=>c});var mt=V((()=>{X(),J(),ut(),st(),ht(),lt(),ot(),ct(),ft(),pt()})),yt=V((()=>{})),wt={};G(wt,{default:()=>_t});var gt,bt,_t,xt=V((()=>{ll(),vu(),pu(),gt="ort-wasm-proxy-worker",(bt=globalThis.self?.name===gt)&&(self.onmessage=t=>{let{type:e,in:n}=t.data;try{switch(e){case"init-wasm":jt(n.wasm).then((()=>{Ah(n).then((()=>{postMessage({type:e})}),(t=>{postMessage({type:e,err:t})}))}),(t=>{postMessage({type:e,err:t})}));break;case"init-ep":{let{epName:t,env:i}=n;Oh(i,t).then((()=>{postMessage({type:e})}),(t=>{postMessage({type:e,err:t})}));break}case"copy-from":{let{buffer:t}=n,i=zh(t);postMessage({type:e,out:i});break}case"create":{let{model:t,options:i}=n;Rh(t,i).then((t=>{postMessage({type:e,out:t})}),(t=>{postMessage({type:e,err:t})}));break}case"release":Fh(n),postMessage({type:e});break;case"run":{let{sessionId:t,inputIndices:i,inputs:r,outputIndices:s,options:o}=n;Dh(t,i,r,s,new Array(s.length).fill(null),o).then((t=>{t.some((t=>"cpu"!==t[3]))?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:t},Uh([...r,...t]))}),(t=>{postMessage({type:e,err:t})}));break}case"end-profiling":Nh(n),postMessage({type:e})}}catch(t){postMessage({type:e,err:t})}}),_t=bt?null:t=>new Worker(t??Et,{type:"module",name:gt})})),kt={};G(kt,{default:()=>Mt});var $t,St,Mt,Et,Ct,At,Ot,It,Tt,zt,Rt,Ft,Pt,Dt,Nt,Ut,qt,jt,Bt,Lt,Ht,Wt,Vt,Gt,Yt,Kt,Xt,Qt,Zt,Jt,te,ee,ne,ie,re,se,oe,ae,ue,he,le,ce,fe,de,pe,ve,me,ye,we,ge,be,_e,xe,ke,$e,Se,Me,Ee,Ce,Ae,Oe,Ie,Te,ze,Re,Fe,Pe,De,Ne,Ue,qe,je,Be,Le,He,We,Ve,Ge,Ye,Ke,Xe,Qe,Ze,Je,tn,en,nn,rn,sn,on,an,un,hn,ln,cn,fn,dn,pn,vn,mn,yn,wn,gn,bn,_n,xn,kn,$n,Sn,Mn,En,Cn,An,On,In,Tn,zn,Rn,Fn,Pn,Dn,Nn,Un,qn,jn,Bn,Ln,Hn,Wn,Vn,Gn,Yn,Kn,Xn,Qn,Zn,Jn,ti,ei,ni,ii,ri,si,oi,ai,ui,hi,li,ci,fi,di,pi,vi,mi,yi,wi,gi,bi,_i,xi,ki,$i,Si,Mi,Ei,Ci,Ai,Oi,Ii,Ti,zi,Ri,Fi,Pi,Di,Ni,Ui,qi,ji,Bi,Li,Hi,Wi,Vi,Gi,Yi,Ki,Xi,Qi,Zi,Ji,tr,er,nr,ir,rr,sr,or,ar,ur,hr,lr,cr,fr,dr,pr,vr,mr,yr,wr,gr,br,_r,xr,kr,$r,Sr,Mr,Er,Cr,Ar,Or,Ir,Tr,zr,Rr,Fr,Pr,Dr,Nr,Ur,qr,jr,Br,Lr,Hr,Wr,Vr,Gr,Yr,Kr,Xr,Qr,Zr,Jr,ts,es,ns,is,rs,ss,os,as,us,hs,ls,cs,fs,ds,ps,vs,ms,ys,ws,gs,bs,_s,xs,ks,$s,Ss,Ms,Es,Cs,As,Os,Is,Ts,zs,Rs,Fs,Ps,Ds,Ns,Us,qs,js,Bs,Ls,Hs,Ws,Vs,Gs,Ys,Ks,Xs,Qs,Zs,Js,to,eo,no,io,ro,so,oo,ao,uo,ho,lo,co,fo,po,vo,mo,yo,wo,go,bo,_o,xo,ko,$o,So,Mo,Eo,Co,Ao,Oo,Io,To,zo,Ro,Fo,Po,Do,No,Uo,qo,jo,Bo,Lo,Ho,Wo,Vo,Go,Yo,Ko,Xo,Qo,Zo,Jo,ta,ea,na,ia,ra,sa,oa,aa,ua,ha,la,ca,fa,da,pa,va,ma,ya,wa,ga,ba,_a,xa,ka,$a,Sa,Ma,Ea,Ca,Aa,Oa,Ia,Ta,za,Ra,Fa,Pa,Da,Na,Ua,qa,ja,Ba,La,Ha,Wa,Va,Ga,Ya,Ka,Xa,Qa,Za,Ja,tu,eu,nu,iu,ru,su,ou,au,uu,hu,lu,cu,fu,du=V((()=>{$t=n&&"SCRIPT"===n.tagName.toUpperCase()&&n.src||new URL("yunjing-for-cesium.js",document.baseURI).href,St=async function(t={}){function e(){return I.buffer!=R.buffer&&W(),R}function i(){return I.buffer!=R.buffer&&W(),F}function r(){return I.buffer!=R.buffer&&W(),P}function s(){return I.buffer!=R.buffer&&W(),D}function o(){return I.buffer!=R.buffer&&W(),N}function a(){return I.buffer!=R.buffer&&W(),U}function u(){return I.buffer!=R.buffer&&W(),q}function h(){return I.buffer!=R.buffer&&W(),L}var l,c,f=Object.assign({},t),d=new Promise(((t,e)=>{l=t,c=e})),p="object"==typeof window,v="function"==typeof importScripts,m=v&&"em-pthread"==self.name;f.mountExternalData=(t,e)=>{(f.Fb||(f.Fb=new Map)).set(t,e)},f.unmountExternalData=()=>{delete f.Fb};var y=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor;let w=()=>{let t=(t,e,n)=>(...i)=>{let r=We,s=e?.();i=t(...i);let o=e?.();return s!==o&&(t=o,n(s),e=n=null),We!=r?new Promise(((t,e)=>{Qe={resolve:t,reject:e}})):i},e=t=>async(...e)=>{try{if(f.Eb)throw Error("Session already started");let n=f.Eb={bc:e[0],errors:[]},i=await t(...e);if(f.Eb!==n)throw Error("Session mismatch");f.Mb?.flush();let r=n.errors;if(0<r.length){let t=await Promise.all(r);if(t=t.filter((t=>t)),0<t.length)throw Error(t.join("\n"))}return i}finally{f.Eb=null}};f._=t(f._,(()=>f._),(t=>f._=t)),f.tt=e(t(f.tt,(()=>f.tt),(t=>f.tt=t))),f.et=e(t(f.et,(()=>f.et),(t=>f.et=t))),f.nt=t(f.nt,(()=>f.nt),(t=>f.nt=t)),w=void 0};f.jsepInit=(t,e)=>{if(w?.(),"webgpu"===t){[f.Mb,f.Tb,f.Xb,f.Nb,f.Wb,f.jb,f.Yb,f.$b,f.Ub,f.Vb,f.Zb]=e;let t=f.Mb;f.jsepRegisterBuffer=(e,n,i,r)=>t.registerBuffer(e,n,i,r),f.jsepGetBuffer=e=>t.getBuffer(e),f.jsepCreateDownloader=(e,n,i)=>t.createDownloader(e,n,i),f.jsepOnReleaseSession=e=>{t.onReleaseSession(e)},f.jsepOnRunStart=e=>t.onRunStart(e)}};var g,b,_=Object.assign({},f),x=(t,e)=>{throw e},k="";(p||v)&&(v?k=self.location.href:typeof document<"u"&&document.currentScript&&(k=document.currentScript.src),$t&&(k=$t),k=k.startsWith("blob:")?"":k.substr(0,k.replace(/[?#].*/,"").lastIndexOf("/")+1),v&&(b=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),g=(t,e,n)=>{var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=()=>{200==i.status||0==i.status&&i.response?e(i.response):n()},i.onerror=n,i.send(null)});var $,S=function(){}.bind(),M=function(){}.bind(),E=S,C=M;if(Object.assign(f,_),_=null,m){let t=function(e){try{var n=e.data,i=n.cmd;if("load"===i){let e=[];self.onmessage=t=>e.push(t),self.startWorker=()=>{postMessage({cmd:"loaded"});for(let n of e)t(n);self.onmessage=t};for(let t of n.handlers)f[t]&&!f[t].proxy||(f[t]=(...e)=>{postMessage({Lb:"callHandler",kc:t,args:e})},"print"==t&&(E=f[t]),"printErr"==t&&(C=f[t]));I=n.wasmMemory,W(),A(n.wasmModule)}else if("run"===i){_i(n.pthread_ptr,0,0,1,0,0),ze(n.pthread_ptr),Mt(),_t(),O||(mi(),O=!0);try{Et(n.start_routine,n.arg)}catch(t){if("unwind"!=t)throw t}}else"cancel"===i?wi()&&Si(-1):"setimmediate"!==n.target&&("checkMailbox"===i?O&&Re():i&&(C(`worker: received unknown command ${i}`),C(n)))}catch(t){throw xi(),t}};var A,O=!1;C=function(...t){t=t.join(" ")},self.alert=function(...t){postMessage({Lb:"alert",text:t.join(" "),mc:wi()})},f.instantiateWasm=(t,e)=>new Promise((t=>{A=n=>{n=new WebAssembly.Instance(n,rt()),e(n),t()}})),self.onunhandledrejection=t=>{throw t.reason||t},self.onmessage=t}f.wasmBinary&&($=f.wasmBinary);var I,T,z,R,F,P,D,N,U,q,j,B,L,H=!1;function W(){var t=I.buffer;f.HEAP8=R=new Int8Array(t),f.HEAP16=P=new Int16Array(t),f.HEAPU8=F=new Uint8Array(t),f.HEAPU16=D=new Uint16Array(t),f.HEAP32=N=new Int32Array(t),f.HEAPU32=U=new Uint32Array(t),f.HEAPF32=q=new Float32Array(t),f.HEAPF64=L=new Float64Array(t),f.HEAP64=j=new BigInt64Array(t),f.HEAPU64=B=new BigUint64Array(t)}if(!m){if(!((I=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0})).buffer instanceof y))throw C("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");W()}var V=[],G=[],Y=[],K=0,X=null;function Q(){if(0==--K&&X){var t=X;X=null,t()}}function Z(t){throw C(t="Aborted("+t+")"),H=!0,z=1,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),c(t),t}var J,tt=t=>t.startsWith("data:application/octet-stream;base64,"),et=t=>t.startsWith("file://");function nt(t){if(t==J&&$)return new Uint8Array($);if(b)return b(t);throw"both async and sync fetching of the wasm failed"}function it(t,e,n){return function(t){if(!$&&(p||v)){if("function"==typeof fetch&&!et(t))return fetch(t,{credentials:"same-origin"}).then((e=>{if(!e.ok)throw`failed to load wasm binary file at '${t}'`;return e.arrayBuffer()})).catch((()=>nt(t)));if(g)return new Promise(((e,n)=>{g(t,(t=>e(new Uint8Array(t))),n)}))}return Promise.resolve().then((()=>nt(t)))}(t).then((t=>WebAssembly.instantiate(t,e))).then(n,(t=>{C(`failed to asynchronously prepare wasm: ${t}`),Z(t)}))}function rt(){return{a:{M:at,za:ot,b:At,$:It,z:Ft,pa:Pt,X:qt,Z:jt,qa:Bt,na:Lt,ga:Ht,ma:Wt,J:Vt,Y:Gt,V:Yt,oa:Kt,W:Xt,va:Jt,D:se,P:ae,O:ve,C:ye,s:we,p:ge,E:be,y:Ce,Q:Ae,ta:Oe,ja:Ie,T:Fe,aa:De,F:Ne,ia:ze,sa:Ue,u:Be,B:tn,o:nn,m:on,c:le,n:un,k:fn,Aa:dn,r:pn,f:vn,v:mn,l:yn,g:wn,i:gn,j:bn,h:_n,e:xn,da:kn,ea:En,fa:Cn,ba:An,ca:On,S:In,d:Rn,N:Fn,G:Pn,K:Dn,w:Nn,ra:qn,U:jn,t:Un,x:Bn,L:Ln,R:Hn,ya:Yn,xa:Kn,ka:Jn,la:ti,it:vt,A:ei,I:ni,ha:ii,H:si,a:I,wa:dt,ua:hi,q:li}}}var st={849620:(t,e,n,r)=>{if(void 0===f||!f.Fb)return 1;if((t=Rt(t>>>0)).startsWith("./")&&(t=t.substring(2)),!(t=f.Fb.get(t)))return 2;if(r>>>=0,(e>>>=0)+(n>>>=0)>t.byteLength)return 3;try{return i().set(t.subarray(e,e+n),r>>>0),0}catch{return 4}},850121:()=>{f.Ub()},850152:()=>{f.Vb()},850181:()=>{f.Zb()},850206:t=>f.Tb(t),850239:t=>f.Xb(t),850271:(t,e,n)=>{f.Nb(t,e,n,!0)},850310:(t,e,n)=>{f.Nb(t,e,n)},850343:()=>typeof wasmOffsetConverter<"u",850400:t=>{f.jb("Abs",t,void 0)},850451:t=>{f.jb("Neg",t,void 0)},850502:t=>{f.jb("Floor",t,void 0)},850555:t=>{f.jb("Ceil",t,void 0)},850607:t=>{f.jb("Reciprocal",t,void 0)},850665:t=>{f.jb("Sqrt",t,void 0)},850717:t=>{f.jb("Exp",t,void 0)},850768:t=>{f.jb("Erf",t,void 0)},850819:t=>{f.jb("Sigmoid",t,void 0)},850874:(t,e,n)=>{f.jb("HardSigmoid",t,{alpha:e,beta:n})},850953:t=>{f.jb("Log",t,void 0)},851004:t=>{f.jb("Sin",t,void 0)},851055:t=>{f.jb("Cos",t,void 0)},851106:t=>{f.jb("Tan",t,void 0)},851157:t=>{f.jb("Asin",t,void 0)},851209:t=>{f.jb("Acos",t,void 0)},851261:t=>{f.jb("Atan",t,void 0)},851313:t=>{f.jb("Sinh",t,void 0)},851365:t=>{f.jb("Cosh",t,void 0)},851417:t=>{f.jb("Asinh",t,void 0)},851470:t=>{f.jb("Acosh",t,void 0)},851523:t=>{f.jb("Atanh",t,void 0)},851576:t=>{f.jb("Tanh",t,void 0)},851628:t=>{f.jb("Not",t,void 0)},851679:(t,e,n)=>{f.jb("Clip",t,{min:e,max:n})},851748:t=>{f.jb("Clip",t,void 0)},851800:(t,e)=>{f.jb("Elu",t,{alpha:e})},851858:t=>{f.jb("Relu",t,void 0)},851910:(t,e)=>{f.jb("LeakyRelu",t,{alpha:e})},851974:(t,e)=>{f.jb("ThresholdedRelu",t,{alpha:e})},852044:(t,e)=>{f.jb("Cast",t,{to:e})},852102:t=>{f.jb("Add",t,void 0)},852153:t=>{f.jb("Sub",t,void 0)},852204:t=>{f.jb("Mul",t,void 0)},852255:t=>{f.jb("Div",t,void 0)},852306:t=>{f.jb("Pow",t,void 0)},852357:t=>{f.jb("Equal",t,void 0)},852410:t=>{f.jb("Greater",t,void 0)},852465:t=>{f.jb("GreaterOrEqual",t,void 0)},852527:t=>{f.jb("Less",t,void 0)},852579:t=>{f.jb("LessOrEqual",t,void 0)},852638:(t,e,n,i,r)=>{f.jb("ReduceMean",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},852797:(t,e,n,i,r)=>{f.jb("ReduceMax",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},852955:(t,e,n,i,r)=>{f.jb("ReduceMin",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853113:(t,e,n,i,r)=>{f.jb("ReduceProd",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853272:(t,e,n,i,r)=>{f.jb("ReduceSum",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853430:(t,e,n,i,r)=>{f.jb("ReduceL1",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853587:(t,e,n,i,r)=>{f.jb("ReduceL2",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853744:(t,e,n,i,r)=>{f.jb("ReduceLogSum",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},853905:(t,e,n,i,r)=>{f.jb("ReduceSumSquare",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},854069:(t,e,n,i,r)=>{f.jb("ReduceLogSumExp",t,{keepDims:!!e,noopWithEmptyAxes:!!n,axes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},854233:t=>{f.jb("Where",t,void 0)},854286:(t,e,n)=>{f.jb("Transpose",t,{perm:e?Array.from(o().subarray(e>>>0,n>>>0)):[]})},854394:(t,e,n,i)=>{f.jb("DepthToSpace",t,{blocksize:e,mode:Rt(n),format:i?"NHWC":"NCHW"})},854527:(t,e,n,i)=>{f.jb("DepthToSpace",t,{blocksize:e,mode:Rt(n),format:i?"NHWC":"NCHW"})},854660:(t,n,i,r,s,a,u,h,l,c,d,p,v,m,y)=>{f.jb("ConvTranspose",t,{format:l?"NHWC":"NCHW",autoPad:n,dilations:[i],group:r,kernelShape:[s],pads:[a,u],strides:[h],wIsConst:()=>!!e()[c>>>0],outputPadding:d?Array.from(o().subarray(d>>>0,p>>>0)):[],outputShape:v?Array.from(o().subarray(v>>>0,m>>>0)):[],activation:Rt(y)})},855061:(t,n,i,r,s,a,u,h,l,c,d,p,v,m)=>{f.jb("ConvTranspose",t,{format:h?"NHWC":"NCHW",autoPad:n,dilations:Array.from(o().subarray(i>>>0,2+(i>>>0)>>>0)),group:r,kernelShape:Array.from(o().subarray(s>>>0,2+(s>>>0)>>>0)),pads:Array.from(o().subarray(a>>>0,4+(a>>>0)>>>0)),strides:Array.from(o().subarray(u>>>0,2+(u>>>0)>>>0)),wIsConst:()=>!!e()[l>>>0],outputPadding:c?Array.from(o().subarray(c>>>0,d>>>0)):[],outputShape:p?Array.from(o().subarray(p>>>0,v>>>0)):[],activation:Rt(m)})},855626:(t,n,i,r,s,a,u,h,l,c,d,p,v,m,y)=>{f.jb("ConvTranspose",t,{format:l?"NHWC":"NCHW",autoPad:n,dilations:[i],group:r,kernelShape:[s],pads:[a,u],strides:[h],wIsConst:()=>!!e()[c>>>0],outputPadding:d?Array.from(o().subarray(d>>>0,p>>>0)):[],outputShape:v?Array.from(o().subarray(v>>>0,m>>>0)):[],activation:Rt(y)})},856027:(t,n,i,r,s,a,u,h,l,c,d,p,v,m)=>{f.jb("ConvTranspose",t,{format:h?"NHWC":"NCHW",autoPad:n,dilations:Array.from(o().subarray(i>>>0,2+(i>>>0)>>>0)),group:r,kernelShape:Array.from(o().subarray(s>>>0,2+(s>>>0)>>>0)),pads:Array.from(o().subarray(a>>>0,4+(a>>>0)>>>0)),strides:Array.from(o().subarray(u>>>0,2+(u>>>0)>>>0)),wIsConst:()=>!!e()[l>>>0],outputPadding:c?Array.from(o().subarray(c>>>0,d>>>0)):[],outputShape:p?Array.from(o().subarray(p>>>0,v>>>0)):[],activation:Rt(m)})},856592:(t,e)=>{f.jb("GlobalAveragePool",t,{format:e?"NHWC":"NCHW"})},856683:(t,e,n,i,r,s,o,a,u,h,l,c,d,p,v,m)=>{f.jb("AveragePool",t,{format:m?"NHWC":"NCHW",auto_pad:e,ceil_mode:n,count_include_pad:i,storage_order:r,dilations:[s,o],kernel_shape:[a,u],pads:[h,l,c,d],strides:[p,v]})},856967:(t,e)=>{f.jb("GlobalAveragePool",t,{format:e?"NHWC":"NCHW"})},857058:(t,e,n,i,r,s,o,a,u,h,l,c,d,p,v,m)=>{f.jb("AveragePool",t,{format:m?"NHWC":"NCHW",auto_pad:e,ceil_mode:n,count_include_pad:i,storage_order:r,dilations:[s,o],kernel_shape:[a,u],pads:[h,l,c,d],strides:[p,v]})},857342:(t,e)=>{f.jb("GlobalMaxPool",t,{format:e?"NHWC":"NCHW"})},857429:(t,e,n,i,r,s,o,a,u,h,l,c,d,p,v,m)=>{f.jb("MaxPool",t,{format:m?"NHWC":"NCHW",auto_pad:e,ceil_mode:n,count_include_pad:i,storage_order:r,dilations:[s,o],kernel_shape:[a,u],pads:[h,l,c,d],strides:[p,v]})},857709:(t,e)=>{f.jb("GlobalMaxPool",t,{format:e?"NHWC":"NCHW"})},857796:(t,e,n,i,r,s,o,a,u,h,l,c,d,p,v,m)=>{f.jb("MaxPool",t,{format:m?"NHWC":"NCHW",auto_pad:e,ceil_mode:n,count_include_pad:i,storage_order:r,dilations:[s,o],kernel_shape:[a,u],pads:[h,l,c,d],strides:[p,v]})},858076:(t,e,n,i,r)=>{f.jb("Gemm",t,{alpha:e,beta:n,transA:i,transB:r})},858180:t=>{f.jb("MatMul",t,void 0)},858234:(t,e,n,i)=>{f.jb("ArgMax",t,{keepDims:!!e,selectLastIndex:!!n,axis:i})},858342:(t,e,n,i)=>{f.jb("ArgMin",t,{keepDims:!!e,selectLastIndex:!!n,axis:i})},858450:(t,e)=>{f.jb("Softmax",t,{axis:e})},858513:(t,e)=>{f.jb("Concat",t,{axis:e})},858573:(t,e,n,i,r)=>{f.jb("Split",t,{axis:e,numOutputs:n,splitSizes:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},858713:t=>{f.jb("Expand",t,void 0)},858767:(t,e)=>{f.jb("Gather",t,{axis:Number(e)})},858838:(t,e)=>{f.jb("GatherElements",t,{axis:Number(e)})},858917:(t,e,n,i,r,s,a,u,h,l,c)=>{f.jb("Resize",t,{antialias:e,axes:n?Array.from(o().subarray(n>>>0,i>>>0)):[],coordinateTransformMode:Rt(r),cubicCoeffA:s,excludeOutside:a,extrapolationValue:u,keepAspectRatioPolicy:Rt(h),mode:Rt(l),nearestMode:Rt(c)})},859263:(t,e,n,i,r,s,a)=>{f.jb("Slice",t,{starts:e?Array.from(o().subarray(e>>>0,n>>>0)):[],ends:i?Array.from(o().subarray(i>>>0,r>>>0)):[],axes:s?Array.from(o().subarray(s>>>0,a>>>0)):[]})},859479:t=>{f.jb("Tile",t,void 0)},859531:(t,e,n)=>{f.jb("InstanceNormalization",t,{epsilon:e,format:n?"NHWC":"NCHW"})},859645:(t,e,n)=>{f.jb("InstanceNormalization",t,{epsilon:e,format:n?"NHWC":"NCHW"})},859759:t=>{f.jb("Range",t,void 0)},859812:(t,e)=>{f.jb("Einsum",t,{equation:Rt(e)})},859893:(t,e,n,i,r)=>{f.jb("Pad",t,{mode:e,value:n,pads:i?Array.from(o().subarray(i>>>0,r>>>0)):[]})},860020:(t,e,n,i,r,s)=>{f.jb("BatchNormalization",t,{epsilon:e,momentum:n,spatial:!!r,trainingMode:!!i,format:s?"NHWC":"NCHW"})},860189:(t,e,n,i,r,s)=>{f.jb("BatchNormalization",t,{epsilon:e,momentum:n,spatial:!!r,trainingMode:!!i,format:s?"NHWC":"NCHW"})},860358:(t,e,n)=>{f.jb("CumSum",t,{exclusive:Number(e),reverse:Number(n)})},860455:(t,e,n,i,r,s,a,u,h)=>{f.jb("Attention",t,{numHeads:e,isUnidirectional:n,maskFilterValue:i,scale:r,doRotary:s,qkvHiddenSizes:a?Array.from(o().subarray(Number(u)>>>0,Number(u)+a>>>0)):[],pastPresentShareBuffer:!!h})},860727:t=>{f.jb("BiasAdd",t,void 0)},860782:t=>{f.jb("BiasSplitGelu",t,void 0)},860843:t=>{f.jb("FastGelu",t,void 0)},860899:(t,n,i,r,s,a,h,l,c,d,p,v,m,y,w,g)=>{f.jb("Conv",t,{format:v?"NHWC":"NCHW",auto_pad:n,dilations:i?Array.from(o().subarray(i>>>0,r>>>0)):[],group:s,kernel_shape:a?Array.from(o().subarray(a>>>0,h>>>0)):[],pads:l?Array.from(o().subarray(l>>>0,c>>>0)):[],strides:d?Array.from(o().subarray(d>>>0,p>>>0)):[],w_is_const:()=>!!e()[m>>>0],activation:Rt(y),activation_params:w?Array.from(u().subarray(w>>>0,g>>>0)):[]})},861395:t=>{f.jb("Gelu",t,void 0)},861447:(t,e,n,i)=>{f.jb("GroupQueryAttention",t,{numHeads:e,kvNumHeads:n,scale:i})},861560:(t,e,n,i)=>{f.jb("LayerNormalization",t,{axis:e,epsilon:n,simplified:!!i})},861671:(t,e,n,i)=>{f.jb("LayerNormalization",t,{axis:e,epsilon:n,simplified:!!i})},861782:(t,e,n,i,r,s)=>{f.jb("MatMulNBits",t,{k:e,n:n,accuracyLevel:i,bits:r,blockSize:s})},861909:(t,e,n,i,r,s)=>{f.jb("MultiHeadAttention",t,{numHeads:e,isUnidirectional:n,maskFilterValue:i,scale:r,doRotary:s})},862068:(t,e)=>{f.jb("QuickGelu",t,{alpha:e})},862132:(t,e,n,i,r)=>{f.jb("RotaryEmbedding",t,{interleaved:!!e,numHeads:n,rotaryEmbeddingDim:i,scale:r})},862271:(t,e,n)=>{f.jb("SkipLayerNormalization",t,{epsilon:e,simplified:!!n})},862373:t=>{f.Yb(t)},862407:(t,e)=>f.$b(t,e,f.Eb.bc,f.Eb.errors),862519:(t,e,n)=>{f.jb("SkipLayerNormalization",t,{epsilon:e,simplified:!!n})}};function ot(t,e,n){return Je((async()=>{await f.Wb(t,e,n)}))}function at(){return typeof wasmOffsetConverter<"u"}function ut(t){this.name="ExitStatus",this.message=`Program terminated with exit(${t})`,this.status=t}var ht=t=>{t.terminate(),t.onmessage=()=>{}},lt=t=>{0==mt.length&&(kt(),xt(mt[0]));var e=mt.pop();if(!e)return 6;yt.push(e),gt[t.Ab]=e,e.Ab=t.Ab;var n={cmd:"run",start_routine:t.cc,arg:t.Pb,pthread_ptr:t.Ab};return e.postMessage(n,t.ic),0},ct=0,ft=(t,e,...n)=>{for(var i=2*n.length,r=Oi(),s=Ai(8*i),o=s>>>3,a=0;a<n.length;a++){var u=n[a];"bigint"==typeof u?(j[o+2*a]=1n,j[o+2*a+1]=u):(j[o+2*a]=0n,h()[o+2*a+1>>>0]=u)}return t=ki(t,0,i,s,e),Ci(r),t};function dt(t){if(m)return ft(0,1,t);if(z=t,!(0<ct)){for(var e of yt)ht(e);for(e of mt)ht(e);mt=[],yt=[],gt=[],H=!0}x(0,new ut(t))}function pt(t){if(m)return ft(1,0,t);vt(t)}var vt=t=>{if(z=t,m)throw pt(t),"unwind";dt(t)},mt=[],yt=[],wt=[],gt={},bt=t=>{var e=t.Ab;delete gt[e],mt.push(t),yt.splice(yt.indexOf(t),1),t.Ab=0,$i(e)};function _t(){wt.forEach((t=>t()))}var xt=t=>new Promise((e=>{t.onmessage=n=>{var i=(n=n.data).cmd;if(n.targetThread&&n.targetThread!=wi()){var r=gt[n.targetThread];r?r.postMessage(n,n.transferList):C(`Internal error! Worker sent a message "${i}" to target pthread ${n.targetThread}, but that thread no longer exists!`)}else"checkMailbox"===i?Re():"spawnThread"===i?lt(n):"cleanupThread"===i?bt(gt[n.thread]):"killThread"===i?(n=n.thread,i=gt[n],delete gt[n],ht(i),$i(n),yt.splice(yt.indexOf(i),1),i.Ab=0):"cancelThread"===i?gt[n.thread].postMessage({cmd:"cancel"}):"loaded"===i?(t.loaded=!0,e(t)):"alert"===i?alert(`Thread ${n.threadId}: ${n.text}`):"setimmediate"===n.target?t.postMessage(n):"callHandler"===i?f[n.handler](...n.args):i&&C(`worker sent an unknown command ${i}`)},t.onerror=t=>{throw C(`worker sent an error! ${t.filename}:${t.lineno}: ${t.message}`),t};var n,i=[];for(n of[])f.hasOwnProperty(n)&&i.push(n);t.postMessage({cmd:"load",handlers:i,wasmMemory:I,wasmModule:T})}));function kt(){var t=new Worker(new URL(n&&"SCRIPT"===n.tagName.toUpperCase()&&n.src||new URL("yunjing-for-cesium.js",document.baseURI).href),{type:"module",workerData:"em-pthread",name:"em-pthread"});mt.push(t)}var St=t=>{for(;0<t.length;)t.shift()(f)},Mt=()=>{var t=wi(),e=a()[t+52>>>2>>>0];t=a()[t+56>>>2>>>0],Ei(e,e-t),Ci(e)},Et=(t,e)=>{ct=0,t=Ii(t,e),0<ct?z=t:Si(t)};class Ct{constructor(t){this.Ib=t-24}}function At(t,e,n){var i=new Ct(t>>>=0);throw e>>>=0,n>>>=0,a()[i.Ib+16>>>2>>>0]=0,a()[i.Ib+4>>>2>>>0]=e,a()[i.Ib+8>>>2>>>0]=n,t}function Ot(t,e,n,i){return m?ft(2,1,t,e,n,i):It(t,e,n,i)}function It(t,e,n,i){if(t>>>=0,e>>>=0,n>>>=0,i>>>=0,void 0===y)return C("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var r=[];return m&&0===r.length?Ot(t,e,n,i):(t={cc:n,Ab:t,Pb:i,ic:r},m?(t.Lb="spawnThread",postMessage(t,r),0):lt(t))}var Tt=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,zt=(t,e,n)=>{var i=(e>>>=0)+n;for(n=e;t[n]&&!(n>=i);)++n;if(16<n-e&&t.buffer&&Tt)return Tt.decode(t.buffer instanceof y?t.slice(e,n):t.subarray(e,n));for(i="";e<n;){var r=t[e++];if(128&r){var s=63&t[e++];if(192==(224&r))i+=String.fromCharCode((31&r)<<6|s);else{var o=63&t[e++];65536>(r=224==(240&r)?(15&r)<<12|s<<6|o:(7&r)<<18|s<<12|o<<6|63&t[e++])?i+=String.fromCharCode(r):(r-=65536,i+=String.fromCharCode(55296|r>>10,56320|1023&r))}}else i+=String.fromCharCode(r)}return i},Rt=(t,e)=>(t>>>=0)?zt(i(),t,e):"";function Ft(t,e,n){return m?ft(3,1,t,e,n):0}function Pt(t,e){if(m)return ft(4,1,t,e)}var Dt=t=>{for(var e=0,n=0;n<t.length;++n){var i=t.charCodeAt(n);127>=i?e++:2047>=i?e+=2:55296<=i&&57343>=i?(e+=4,++n):e+=3}return e},Nt=(t,e,n,i)=>{if(!(0<i))return 0;var r=n>>>=0;i=n+i-1;for(var s=0;s<t.length;++s){var o=t.charCodeAt(s);if(55296<=o&&57343>=o&&(o=65536+((1023&o)<<10)|1023&t.charCodeAt(++s)),127>=o){if(n>=i)break;e[n++>>>0]=o}else{if(2047>=o){if(n+1>=i)break;e[n++>>>0]=192|o>>6}else{if(65535>=o){if(n+2>=i)break;e[n++>>>0]=224|o>>12}else{if(n+3>=i)break;e[n++>>>0]=240|o>>18,e[n++>>>0]=128|o>>12&63}e[n++>>>0]=128|o>>6&63}e[n++>>>0]=128|63&o}}return e[n>>>0]=0,n-r},Ut=(t,e,n)=>Nt(t,i(),e,n);function qt(t,e){if(m)return ft(5,1,t,e)}function jt(t,e,n){if(m)return ft(6,1,t,e,n)}function Bt(t,e,n){return m?ft(7,1,t,e,n):0}function Lt(t,e){if(m)return ft(8,1,t,e)}function Ht(t,e,n){if(m)return ft(9,1,t,e,n)}function Wt(t,e,n,i){if(m)return ft(10,1,t,e,n,i)}function Vt(t,e,n,i){if(m)return ft(11,1,t,e,n,i)}function Gt(t,e,n,i){if(m)return ft(12,1,t,e,n,i)}function Yt(t){if(m)return ft(13,1,t)}function Kt(t,e){if(m)return ft(14,1,t,e)}function Xt(t,e,n){if(m)return ft(15,1,t,e,n)}var Qt,Zt,Jt=()=>{Z("")},te=t=>{for(var e="";i()[t>>>0];)e+=Qt[i()[t++>>>0]];return e},ee={},ne={};function ie(t,e,n={}){if(!("argPackAdvance"in e))throw new TypeError("registerType registeredInstance requires argPackAdvance");return function(t,e,n={}){var i=e.name;if(!t)throw new Zt(`type "${i}" must have a positive integer typeid pointer`);if(ne.hasOwnProperty(t)){if(n.Rb)return;throw new Zt(`Cannot register type '${i}' twice`)}ne[t]=e,ee.hasOwnProperty(t)&&(e=ee[t],delete ee[t],e.forEach((t=>t())))}(t,e,n)}var re=(t,n,u)=>{switch(n){case 1:return u?t=>e()[t>>>0]:t=>i()[t>>>0];case 2:return u?t=>r()[t>>>1>>>0]:t=>s()[t>>>1>>>0];case 4:return u?t=>o()[t>>>2>>>0]:t=>a()[t>>>2>>>0];case 8:return u?t=>j[t>>>3]:t=>B[t>>>3];default:throw new TypeError(`invalid integer width (${n}): ${t}`)}};function se(t,e,n){n>>>=0,ie(t>>>=0,{name:e=te(e>>>0),fromWireType:t=>t,toWireType:function(t,e){if("bigint"!=typeof e&&"number"!=typeof e)throw e=null===e?"null":"object"==(t=typeof e)||"array"===t||"function"===t?e.toString():""+e,new TypeError(`Cannot convert "${e}" to ${this.name}`);return"number"==typeof e&&(e=BigInt(e)),e},argPackAdvance:oe,readValueFromPointer:re(e,n,-1==e.indexOf("u")),Db:null})}var oe=8;function ae(t,e,n,r){ie(t>>>=0,{name:e=te(e>>>0),fromWireType:function(t){return!!t},toWireType:function(t,e){return e?n:r},argPackAdvance:oe,readValueFromPointer:function(t){return this.fromWireType(i()[t>>>0])},Db:null})}var ue=[],he=[];function le(t){9<(t>>>=0)&&0==--he[t+1]&&(he[t]=void 0,ue.push(t))}var ce=t=>{if(!t)throw new Zt("Cannot use deleted val. handle = "+t);return he[t]},fe=t=>{switch(t){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let e=ue.pop()||he.length;return he[e]=t,he[e+1]=1,e}};function de(t){return this.fromWireType(a()[t>>>2>>>0])}var pe={name:"emscripten::val",fromWireType:t=>{var e=ce(t);return le(t),e},toWireType:(t,e)=>fe(e),argPackAdvance:oe,readValueFromPointer:de,Db:null};function ve(t){return ie(t>>>0,pe)}var me=(t,e)=>{switch(e){case 4:return function(t){return this.fromWireType(u()[t>>>2>>>0])};case 8:return function(t){return this.fromWireType(h()[t>>>3>>>0])};default:throw new TypeError(`invalid float width (${e}): ${t}`)}};function ye(t,e,n){n>>>=0,ie(t>>>=0,{name:e=te(e>>>0),fromWireType:t=>t,toWireType:(t,e)=>e,argPackAdvance:oe,readValueFromPointer:me(e,n),Db:null})}function we(t,e,n,i,r){if(t>>>=0,n>>>=0,e=te(e>>>0),-1===r&&(r=4294967295),r=t=>t,0===i){var s=32-8*n;r=t=>t<<s>>>s}var o=e.includes("unsigned")?function(t,e){return e>>>0}:function(t,e){return e};ie(t,{name:e,fromWireType:r,toWireType:o,argPackAdvance:oe,readValueFromPointer:re(e,n,0!==i),Db:null})}function ge(t,n,i){function r(t){var n=a()[t>>>2>>>0];return t=a()[t+4>>>2>>>0],new s(e().buffer,t,n)}var s=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][n];ie(t>>>=0,{name:i=te(i>>>0),fromWireType:r,argPackAdvance:oe,readValueFromPointer:r},{Rb:!0})}function be(t,e){t>>>=0;var n="std::string"===(e=te(e>>>0));ie(t,{name:e,fromWireType:function(t){var e=a()[t>>>2>>>0],r=t+4;if(n)for(var s=r,o=0;o<=e;++o){var u=r+o;if(o==e||0==i()[u>>>0]){if(s=Rt(s,u-s),void 0===h)var h=s;else h+=String.fromCharCode(0),h+=s;s=u+1}}else{for(h=Array(e),o=0;o<e;++o)h[o]=String.fromCharCode(i()[r+o>>>0]);h=h.join("")}return bi(t),h},toWireType:function(t,e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));var r="string"==typeof e;if(!(r||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array))throw new Zt("Cannot pass non-string to std::string");var s=n&&r?Dt(e):e.length,o=gi(4+s+1),u=o+4;if(a()[o>>>2>>>0]=s,n&&r)Ut(e,u,s+1);else if(r)for(r=0;r<s;++r){var h=e.charCodeAt(r);if(255<h)throw bi(u),new Zt("String has UTF-16 code units that do not fit in 8 bits");i()[u+r>>>0]=h}else for(r=0;r<s;++r)i()[u+r>>>0]=e[r];return null!==t&&t.push(bi,o),o},argPackAdvance:oe,readValueFromPointer:de,Db(t){bi(t)}})}var _e=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0,xe=(t,e)=>{for(var n=t>>1,o=n+e/2;!(n>=o)&&s()[n>>>0];)++n;if(32<(n<<=1)-t&&_e)return _e.decode(i().slice(t,n));for(n="",o=0;!(o>=e/2);++o){var a=r()[t+2*o>>>1>>>0];if(0==a)break;n+=String.fromCharCode(a)}return n},ke=(t,e,n)=>{if(n??=2147483647,2>n)return 0;var i=e;n=(n-=2)<2*t.length?n/2:t.length;for(var s=0;s<n;++s){var o=t.charCodeAt(s);r()[e>>>1>>>0]=o,e+=2}return r()[e>>>1>>>0]=0,e-i},$e=t=>2*t.length,Se=(t,e)=>{for(var n=0,i="";!(n>=e/4);){var r=o()[t+4*n>>>2>>>0];if(0==r)break;++n,65536<=r?(r-=65536,i+=String.fromCharCode(55296|r>>10,56320|1023&r)):i+=String.fromCharCode(r)}return i},Me=(t,e,n)=>{if(e>>>=0,n??=2147483647,4>n)return 0;var i=e;n=i+n-4;for(var r=0;r<t.length;++r){var s=t.charCodeAt(r);if(55296<=s&&57343>=s&&(s=65536+((1023&s)<<10)|1023&t.charCodeAt(++r)),o()[e>>>2>>>0]=s,(e+=4)+4>n)break}return o()[e>>>2>>>0]=0,e-i},Ee=t=>{for(var e=0,n=0;n<t.length;++n){var i=t.charCodeAt(n);55296<=i&&57343>=i&&++n,e+=4}return e};function Ce(t,e,n){if(t>>>=0,e>>>=0,n=te(n>>>=0),2===e)var i=xe,r=ke,o=$e,u=t=>s()[t>>>1>>>0];else 4===e&&(i=Se,r=Me,o=Ee,u=t=>a()[t>>>2>>>0]);ie(t,{name:n,fromWireType:t=>{for(var n,r=a()[t>>>2>>>0],s=t+4,o=0;o<=r;++o){var h=t+4+o*e;o!=r&&0!=u(h)||(s=i(s,h-s),void 0===n?n=s:(n+=String.fromCharCode(0),n+=s),s=h+e)}return bi(t),n},toWireType:(t,i)=>{if("string"!=typeof i)throw new Zt(`Cannot pass non-string to C++ string type ${n}`);var s=o(i),u=gi(4+s+e);return a()[u>>>2>>>0]=s/e,r(i,u+4,s+e),null!==t&&t.push(bi,u),u},argPackAdvance:oe,readValueFromPointer:de,Db(t){bi(t)}})}function Ae(t,e){ie(t>>>=0,{Sb:!0,name:e=te(e>>>0),argPackAdvance:0,fromWireType:()=>{},toWireType:()=>{}})}var Oe=()=>1;function Ie(t){_i(t>>>0,!v,1,!p,131072,!1),_t()}var Te=t=>{if(!H)try{if(t(),!(0<ct))try{m?Si(z):vt(z)}catch(t){t instanceof ut||"unwind"==t||x(0,t)}}catch(t){t instanceof ut||"unwind"==t||x(0,t)}};function ze(t){t>>>=0,"function"==typeof Atomics.jc&&(Atomics.jc(o(),t>>>2,t).value.then(Re),t+=128,Atomics.store(o(),t>>>2,1))}var Re=()=>{var t=wi();t&&(ze(t),Te(Mi))};function Fe(t,e){(t>>>=0)==e>>>0?setTimeout(Re):m?postMessage({targetThread:t,cmd:"checkMailbox"}):(t=gt[t])&&t.postMessage({cmd:"checkMailbox"})}var Pe=[];function De(t,e,n,i,r){for(e>>>=0,i/=2,Pe.length=i,n=r>>>0>>>3,r=0;r<i;r++)Pe[r]=j[n+2*r]?j[n+2*r+1]:h()[n+2*r+1>>>0];return(e?st[e]:di[t])(...Pe)}function Ne(t){t>>>=0,m?postMessage({cmd:"cleanupThread",thread:t}):bt(gt[t])}function Ue(t){}var qe=(t,e)=>{var n=ne[t];if(void 0===n)throw t=vi(t),n=te(t),bi(t),new Zt(`${e} has unknown type ${n}`);return n},je=(t,e,n)=>{var i=[];return t=t.toWireType(i,n),i.length&&(a()[e>>>2>>>0]=fe(i)),t};function Be(t,e,n){return e>>>=0,n>>>=0,t=ce(t>>>0),e=qe(e,"emval::as"),je(e,n,t)}var Le=t=>{try{t()}catch(t){Z(t)}},He=0,We=null,Ve=0,Ge=[],Ye={},Ke={},Xe=0,Qe=null,Ze=[];function Je(t){return function(){if(!H){if(0===He){var e=!1,n=!1;t().then(((t=0)=>{if(!H&&(Ve=t,e=!0,n)){He=2,Le((()=>Ri(We))),typeof Browser<"u"&&Browser.Jb.Qb&&Browser.Jb.resume(),t=!1;try{var i=(a=o()[We+8>>>2>>>0],a=pi[Ke[a]],--ct,a())}catch(a){i=a,t=!0}var r=!1;if(!We){var s=Qe;s&&(Qe=null,(t?s.reject:s.resolve)(i),r=!0)}if(t&&!r)throw i}var a})),n=!0,e||(He=1,We=function(){var t=gi(65548),e=t+12;a()[t>>>2>>>0]=e,a()[t+4>>>2>>>0]=e+65536,e=Ge[0];var n=Ye[e];return void 0===n&&(n=Xe++,Ye[e]=n,Ke[n]=e),e=n,o()[t+8>>>2>>>0]=e,t}(),typeof Browser<"u"&&Browser.Jb.Qb&&Browser.Jb.pause(),Le((()=>Ti(We))))}else 2===He?(He=0,Le(Fi),bi(We),We=null,Ze.forEach(Te)):Z(`invalid state: ${He}`);return Ve}}()}function tn(t){return t>>>=0,Je((()=>(t=ce(t)).then(fe)))}var en=[];function nn(t,e,n,i){return n>>>=0,i>>>=0,(t=en[t>>>0])(null,e=ce(e>>>0),n,i)}var rn={},sn=t=>{var e=rn[t];return void 0===e?te(t):e};function on(t,e,n,i,r){return n>>>=0,i>>>=0,r>>>=0,(t=en[t>>>0])(e=ce(e>>>0),e[n=sn(n)],i,r)}var an=()=>"object"==typeof globalThis?globalThis:Function("","return this")();function un(t){return 0==(t>>>=0)?fe(an()):(t=sn(t),fe(an()[t]))}var hn=t=>{var e=en.length;return en.push(t),e},ln=(t,e)=>{for(var n=Array(t),i=0;i<t;++i)n[i]=qe(a()[e+4*i>>>2>>>0],"parameter "+i);return n},cn=(t,e)=>Object.defineProperty(e,"name",{value:t});function fn(t,e,n){var i=(e=ln(t,e>>>0)).shift();t--;var r="return function (obj, func, destructorsRef, args) {\n",s=0,o=[];0===n&&o.push("obj");for(var a=["retType"],u=[i],h=0;h<t;++h)o.push("arg"+h),a.push("argType"+h),u.push(e[h]),r+=` var arg${h} = argType${h}.readValueFromPointer(args${s?"+"+s:""});\n`,s+=e[h].argPackAdvance;return r+=` var rv = ${1===n?"new func":"func.call"}(${o.join(", ")});\n`,i.Sb||(a.push("emval_returnValue"),u.push(je),r+=" return emval_returnValue(retType, destructorsRef, rv);\n"),a.push(r+"};\n"),t=function(t){var e=Function;if(!(e instanceof Function))throw new TypeError(`new_ called with constructor type ${typeof e} which is not a function`);var n=cn(e.name||"unknownFunctionName",(function(){}));return n.prototype=e.prototype,n=new n,(t=e.apply(n,t))instanceof Object?t:n}(a)(...u),n=`methodCaller<(${e.map((t=>t.name)).join(", ")}) => ${i.name}>`,hn(cn(n,t))}function dn(t){return t=sn(t>>>0),fe(f[t])}function pn(t,e){return e>>>=0,t=ce(t>>>0),e=ce(e),fe(t[e])}function vn(t){9<(t>>>=0)&&(he[t+1]+=1)}function mn(){return fe([])}function yn(t){t=ce(t>>>0);for(var e=Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return fe(e)}function wn(t){return fe(sn(t>>>0))}function gn(){return fe({})}function bn(t){for(var e=ce(t>>>=0);e.length;){var n=e.pop();e.pop()(n)}le(t)}function _n(t,e,n){e>>>=0,n>>>=0,t=ce(t>>>0),e=ce(e),n=ce(n),t[e]=n}function xn(t,e){return e>>>=0,t=(t=qe(t>>>0,"_emval_take_value")).readValueFromPointer(e),fe(t)}function kn(t,e){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t),e>>>=0,t=new Date(1e3*t),o()[e>>>2>>>0]=t.getUTCSeconds(),o()[e+4>>>2>>>0]=t.getUTCMinutes(),o()[e+8>>>2>>>0]=t.getUTCHours(),o()[e+12>>>2>>>0]=t.getUTCDate(),o()[e+16>>>2>>>0]=t.getUTCMonth(),o()[e+20>>>2>>>0]=t.getUTCFullYear()-1900,o()[e+24>>>2>>>0]=t.getUTCDay(),t=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,o()[e+28>>>2>>>0]=t}var $n=t=>t%4==0&&(t%100!=0||t%400==0),Sn=[0,31,60,91,121,152,182,213,244,274,305,335],Mn=[0,31,59,90,120,151,181,212,243,273,304,334];function En(t,e){t=-9007199254740992>t||9007199254740992<t?NaN:Number(t),e>>>=0,t=new Date(1e3*t),o()[e>>>2>>>0]=t.getSeconds(),o()[e+4>>>2>>>0]=t.getMinutes(),o()[e+8>>>2>>>0]=t.getHours(),o()[e+12>>>2>>>0]=t.getDate(),o()[e+16>>>2>>>0]=t.getMonth(),o()[e+20>>>2>>>0]=t.getFullYear()-1900,o()[e+24>>>2>>>0]=t.getDay();var n=($n(t.getFullYear())?Sn:Mn)[t.getMonth()]+t.getDate()-1|0;o()[e+28>>>2>>>0]=n,o()[e+36>>>2>>>0]=-60*t.getTimezoneOffset(),n=new Date(t.getFullYear(),6,1).getTimezoneOffset();var i=new Date(t.getFullYear(),0,1).getTimezoneOffset();t=0|(n!=i&&t.getTimezoneOffset()==Math.min(i,n)),o()[e+32>>>2>>>0]=t}function Cn(t){t>>>=0;var e=new Date(o()[t+20>>>2>>>0]+1900,o()[t+16>>>2>>>0],o()[t+12>>>2>>>0],o()[t+8>>>2>>>0],o()[t+4>>>2>>>0],o()[t>>>2>>>0],0),n=o()[t+32>>>2>>>0],i=e.getTimezoneOffset(),r=new Date(e.getFullYear(),6,1).getTimezoneOffset(),s=new Date(e.getFullYear(),0,1).getTimezoneOffset(),a=Math.min(s,r);return 0>n?o()[t+32>>>2>>>0]=+(r!=s&&a==i):0<n!=(a==i)&&(r=Math.max(s,r),e.setTime(e.getTime()+6e4*((0<n?a:r)-i))),o()[t+24>>>2>>>0]=e.getDay(),n=($n(e.getFullYear())?Sn:Mn)[e.getMonth()]+e.getDate()-1|0,o()[t+28>>>2>>>0]=n,o()[t>>>2>>>0]=e.getSeconds(),o()[t+4>>>2>>>0]=e.getMinutes(),o()[t+8>>>2>>>0]=e.getHours(),o()[t+12>>>2>>>0]=e.getDate(),o()[t+16>>>2>>>0]=e.getMonth(),o()[t+20>>>2>>>0]=e.getYear(),t=e.getTime(),BigInt(isNaN(t)?-1:t/1e3)}function An(t,e,n,i,r,s,o){return m?ft(16,1,t,e,n,i,r,s,o):-52}function On(t,e,n,i,r,s){if(m)return ft(17,1,t,e,n,i,r,s)}function In(t,e,n,i){t>>>=0,e>>>=0,n>>>=0,i>>>=0;var r=(new Date).getFullYear(),s=new Date(r,0,1),u=new Date(r,6,1);r=s.getTimezoneOffset();var h=u.getTimezoneOffset(),l=Math.max(r,h);a()[t>>>2>>>0]=60*l,o()[e>>>2>>>0]=+(r!=h),s=(t=t=>t.toLocaleTimeString(void 0,{hour12:!1,timeZoneName:"short"}).split(" ")[1])(s),u=t(u),h<r?(Ut(s,n,17),Ut(u,i,17)):(Ut(s,i,17),Ut(u,n,17))}var Tn=[],zn=(t,e)=>{Tn.length=0;for(var n;n=i()[t++>>>0];){var r=105!=n;e+=(r&=112!=n)&&e%8?4:0,Tn.push(112==n?a()[e>>>2>>>0]:106==n?j[e>>>3]:105==n?o()[e>>>2>>>0]:h()[e>>>3>>>0]),e+=r?8:4}return Tn};function Rn(t,e,n){return t>>>=0,e=zn(e>>>0,n>>>0),st[t](...e)}function Fn(t,e,n){return t>>>=0,e=zn(e>>>0,n>>>0),st[t](...e)}var Pn=()=>{},Dn=()=>Date.now();function Nn(t,e){return C(Rt(t>>>0,e>>>0))}var Un,qn=()=>{throw ct+=1,"unwind"};function jn(){return 4294901760}Un=()=>performance.timeOrigin+performance.now();var Bn=()=>navigator.hardwareConcurrency;function Ln(){return Z("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER"),0}function Hn(t){t>>>=0;var e=i().length;if(t<=e||4294901760<t)return!1;for(var n=1;4>=n;n*=2){var r=e*(1+.2/n);r=Math.min(r,t+100663296);var s=Math;r=Math.max(t,r);t:{s=(s.min.call(s,4294901760,r+(65536-r%65536)%65536)-I.buffer.byteLength+65535)/65536;try{I.grow(s),W();var o=1;break t}catch{}o=void 0}if(o)return!0}return!1}var Wn=()=>(Z("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER"),0),Vn={},Gn=t=>{t.forEach((t=>{Wn()}))};function Yn(){var t=Error().stack.toString().split("\n");return"Error"==t[0]&&t.shift(),Gn(t),Vn.Ob=Wn(),Vn.ac=t,Vn.Ob}function Kn(t,e,n){if(t>>>=0,e>>>=0,Vn.Ob==t)var i=Vn.ac;else"Error"==(i=Error().stack.toString().split("\n"))[0]&&i.shift(),Gn(i);for(var r=3;i[r]&&Wn()!=t;)++r;for(t=0;t<n&&i[t+r];++t)o()[e+4*t>>>2>>>0]=Wn();return t}var Xn,Qn={},Zn=()=>{if(!Xn){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",it:"./this.program"};for(t in Qn)void 0===Qn[t]?delete e[t]:e[t]=Qn[t];var n=[];for(t in e)n.push(`${t}=${e[t]}`);Xn=n}return Xn};function Jn(t,n){if(m)return ft(18,1,t,n);t>>>=0,n>>>=0;var i=0;return Zn().forEach(((r,s)=>{var o=n+i;for(s=a()[t+4*s>>>2>>>0]=o,o=0;o<r.length;++o)e()[s++>>>0]=r.charCodeAt(o);e()[s>>>0]=0,i+=r.length+1})),0}function ti(t,e){if(m)return ft(19,1,t,e);t>>>=0,e>>>=0;var n=Zn();a()[t>>>2>>>0]=n.length;var i=0;return n.forEach((t=>i+=t.length+1)),a()[e>>>2>>>0]=i,0}function ei(t){return m?ft(20,1,t):52}function ni(t,e,n,i){return m?ft(21,1,t,e,n,i):52}function ii(t,e,n,i){return m?ft(22,1,t,e,n,i):70}var ri=[null,[],[]];function si(t,e,n,r){if(m)return ft(23,1,t,e,n,r);e>>>=0,n>>>=0,r>>>=0;for(var s=0,o=0;o<n;o++){var u=a()[e>>>2>>>0],h=a()[e+4>>>2>>>0];e+=8;for(var l=0;l<h;l++){var c=i()[u+l>>>0],f=ri[t];0===c||10===c?((1===t?E:C)(zt(f,0)),f.length=0):f.push(c)}s+=h}return a()[r>>>2>>>0]=s,0}var oi=[31,29,31,30,31,30,31,31,30,31,30,31],ai=[31,28,31,30,31,30,31,31,30,31,30,31],ui=(t,n)=>{e().set(t,n>>>0)};function hi(t,e,n,i){function r(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.length<e;)t=n[0]+t;return t}function s(t,e){return r(t,e,"0")}function u(t,e){function n(t){return 0>t?-1:0<t?1:0}var i;return 0===(i=n(t.getFullYear()-e.getFullYear()))&&0===(i=n(t.getMonth()-e.getMonth()))&&(i=n(t.getDate()-e.getDate())),i}function h(t){switch(t.getDay()){case 0:return new Date(t.getFullYear()-1,11,29);case 1:return t;case 2:return new Date(t.getFullYear(),0,3);case 3:return new Date(t.getFullYear(),0,2);case 4:return new Date(t.getFullYear(),0,1);case 5:return new Date(t.getFullYear()-1,11,31);case 6:return new Date(t.getFullYear()-1,11,30)}}function l(t){var e=t.Bb;for(t=new Date(new Date(t.Cb+1900,0,1).getTime());0<e;){var n=t.getMonth(),i=($n(t.getFullYear())?oi:ai)[n];if(!(e>i-t.getDate())){t.setDate(t.getDate()+e);break}e-=i-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=h(new Date(t.getFullYear(),0,4)),n=h(n),0>=u(e,t)?0>=u(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}t>>>=0,e>>>=0,n>>>=0,i>>>=0;var c=a()[i+40>>>2>>>0];for(var f in i={fc:o()[i>>>2>>>0],ec:o()[i+4>>>2>>>0],Gb:o()[i+8>>>2>>>0],Kb:o()[i+12>>>2>>>0],Hb:o()[i+16>>>2>>>0],Cb:o()[i+20>>>2>>>0],ub:o()[i+24>>>2>>>0],Bb:o()[i+28>>>2>>>0],nc:o()[i+32>>>2>>>0],dc:o()[i+36>>>2>>>0],hc:c?Rt(c):""},n=Rt(n),c={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})n=n.replace(new RegExp(f,"g"),c[f]);var d,p,v="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),m="January February March April May June July August September October November December".split(" ");for(f in c={"%a":t=>v[t.ub].substring(0,3),"%A":t=>v[t.ub],"%b":t=>m[t.Hb].substring(0,3),"%B":t=>m[t.Hb],"%C":t=>s((t.Cb+1900)/100|0,2),"%d":t=>s(t.Kb,2),"%e":t=>r(t.Kb,2," "),"%g":t=>l(t).toString().substring(2),"%G":l,"%H":t=>s(t.Gb,2),"%I":t=>(0==(t=t.Gb)?t=12:12<t&&(t-=12),s(t,2)),"%j":t=>{for(var e=0,n=0;n<=t.Hb-1;e+=($n(t.Cb+1900)?oi:ai)[n++]);return s(t.Kb+e,3)},"%m":t=>s(t.Hb+1,2),"%M":t=>s(t.ec,2),"%n":()=>"\n","%p":t=>0<=t.Gb&&12>t.Gb?"AM":"PM","%S":t=>s(t.fc,2),"%t":()=>"\t","%u":t=>t.ub||7,"%U":t=>s(Math.floor((t.Bb+7-t.ub)/7),2),"%V":t=>{var e=Math.floor((t.Bb+7-(t.ub+6)%7)/7);if(2>=(t.ub+371-t.Bb-2)%7&&e++,e)53==e&&(4==(n=(t.ub+371-t.Bb)%7)||3==n&&$n(t.Cb)||(e=1));else{e=52;var n=(t.ub+7-t.Bb-1)%7;(4==n||5==n&&$n(t.Cb%400-1))&&e++}return s(e,2)},"%w":t=>t.ub,"%W":t=>s(Math.floor((t.Bb+7-(t.ub+6)%7)/7),2),"%y":t=>(t.Cb+1900).toString().substring(2),"%Y":t=>t.Cb+1900,"%z":t=>(0<=(t=t.dc)?"+":"-")+("0000"+((t=Math.abs(t)/60)/60*100+t%60)).slice(-4),"%Z":t=>t.hc,"%%":()=>"%"},n=n.replace(/%%/g,"\0\0"),c)n.includes(f)&&(n=n.replace(new RegExp(f,"g"),c[f](i)));return d=n=n.replace(/\0\0/g,"%"),p=Array(Dt(d)+1),Nt(d,p,0,p.length),(f=p).length>e?0:(ui(f,t),f.length-1)}function li(t,e,n,i){return hi(t>>>0,e>>>0,n>>>0,i>>>0)}m||function(){for(var t=f.numThreads-1;t--;)kt();V.unshift((()=>{K++,function(t){m?t():Promise.all(mt.map(xt)).then(t)}((()=>Q()))}))}();for(var ci=Array(256),fi=0;256>fi;++fi)ci[fi]=String.fromCharCode(fi);Qt=ci,Zt=f.BindingError=class extends Error{constructor(t){super(t),this.name="BindingError"}},f.InternalError=class extends Error{constructor(t){super(t),this.name="InternalError"}},he.push(0,1,void 0,1,null,1,!0,1,!1,1),f.count_emval_handles=()=>he.length/2-5-ue.length;var di=[dt,pt,Ot,Ft,Pt,qt,jt,Bt,Lt,Ht,Wt,Vt,Gt,Yt,Kt,Xt,An,On,Jn,ti,ei,ni,ii,si],pi=function(){function t(t,e){return pi=t.exports,pi=function(){var t=pi,e={};for(let[n,i]of Object.entries(t))e[n]="function"==typeof i?(...t)=>{Ge.push(n);try{return i(...t)}finally{H||(Ge.pop(),We&&1===He&&0===Ge.length&&(He=0,ct+=1,Le(zi),typeof Fibers<"u"&&Fibers.oc()))}}:i;return e}(),pi=function(){var t=pi,e=t=>e=>t(e)>>>0,n=t=>()=>t()>>>0;return(t=Object.assign({},t)).Ca=e(t.Ca),t.fb=n(t.fb),t.gb=e(t.gb),t.emscripten_main_runtime_thread_id=n(t.emscripten_main_runtime_thread_id),t.sb=e(t.sb),t.tb=n(t.tb),t}(),wt.push(pi.ib),G.unshift(pi.Ba),T=e,Q(),pi}var e=rt();if(K++,f.instantiateWasm)try{return f.instantiateWasm(e,t)}catch(t){C(`Module.instantiateWasm callback failed with error: ${t}`),c(t)}return J||=f.locateFile?tt("ort-wasm-simd-threaded.jsep.wasm")?"ort-wasm-simd-threaded.jsep.wasm":f.locateFile?f.locateFile("ort-wasm-simd-threaded.jsep.wasm",k):k+"ort-wasm-simd-threaded.jsep.wasm":new URL("ort-wasm-simd-threaded.jsep.wasm",n&&"SCRIPT"===n.tagName.toUpperCase()&&n.src||new URL("yunjing-for-cesium.js",document.baseURI).href).href,function(t,e){var n=J;return $||"function"!=typeof WebAssembly.instantiateStreaming||tt(n)||et(n)||"function"!=typeof fetch?it(n,t,e):fetch(n,{credentials:"same-origin"}).then((i=>WebAssembly.instantiateStreaming(i,t).then(e,(function(i){return C(`wasm streaming compile failed: ${i}`),C("falling back to ArrayBuffer instantiation"),it(n,t,e)}))))}(e,(function(e){t(e.instance,e.module)})).catch(c),{}}(),vi=t=>(vi=pi.Ca)(t),mi=()=>(mi=pi.Da)();f.rt=(t,e)=>(f.rt=pi.Ea)(t,e),f.st=(t,e)=>(f.st=pi.Fa)(t,e),f.ot=(t,e,n,i,r,s,o,a,u,h)=>(f.ot=pi.Ga)(t,e,n,i,r,s,o,a,u,h),f.ut=(t,e)=>(f.ut=pi.Ha)(t,e),f.ht=(t,e,n)=>(f.ht=pi.Ia)(t,e,n),f.ct=(t,e,n)=>(f.ct=pi.Ja)(t,e,n),f.ft=t=>(f.ft=pi.Ka)(t),f._=(t,e,n)=>(f._=pi.La)(t,e,n),f.vt=t=>(f.vt=pi.Ma)(t),f.yt=(t,e,n)=>(f.yt=pi.Na)(t,e,n),f.wt=(t,e)=>(f.wt=pi.Oa)(t,e),f.bt=(t,e)=>(f.bt=pi.Pa)(t,e),f._t=t=>(f._t=pi.Qa)(t),f.xt=(t,e,n,i,r,s)=>(f.xt=pi.Ra)(t,e,n,i,r,s),f.kt=(t,e,n,i,r)=>(f.kt=pi.Sa)(t,e,n,i,r),f.$t=t=>(f.$t=pi.Ta)(t),f.St=(t,e,n,i)=>(f.St=pi.Ua)(t,e,n,i),f.Mt=(t,e,n)=>(f.Mt=pi.Va)(t,e,n),f.Et=t=>(f.Et=pi.Wa)(t),f.Ct=t=>(f.Ct=pi.Xa)(t),f.nt=(t,e,n)=>(f.nt=pi.Ya)(t,e,n),f.At=(t,e,n,i)=>(f.At=pi.Za)(t,e,n,i),f.Ot=t=>(f.Ot=pi.It)(t),f.Tt=t=>(f.Tt=pi.$a)(t),f.et=(t,e,n,i,r)=>(f.et=pi.ab)(t,e,n,i,r),f.tt=(t,e,n,i,r,s,o,a)=>(f.tt=pi.bb)(t,e,n,i,r,s,o,a),f.zt=t=>(f.zt=pi.cb)(t),f.Rt=(t,e,n)=>(f.Rt=pi.db)(t,e,n),f.Ft=t=>(f.Ft=pi.eb)(t);var yi,wi=()=>(wi=pi.fb)(),gi=f.Pt=t=>(gi=f.Pt=pi.gb)(t),bi=f.Dt=t=>(bi=f.Dt=pi.hb)(t),_i=(t,e,n,i,r,s)=>(_i=pi.kb)(t,e,n,i,r,s),xi=()=>(xi=pi.lb)(),ki=(t,e,n,i,r)=>(ki=pi.mb)(t,e,n,i,r),$i=t=>($i=pi.nb)(t),Si=t=>(Si=pi.ob)(t),Mi=()=>(Mi=pi.pb)(),Ei=(t,e)=>(Ei=pi.qb)(t,e),Ci=t=>(Ci=pi.rb)(t),Ai=t=>(Ai=pi.sb)(t),Oi=()=>(Oi=pi.tb)(),Ii=f.dynCall_ii=(t,e)=>(Ii=f.dynCall_ii=pi.vb)(t,e),Ti=t=>(Ti=pi.wb)(t),zi=()=>(zi=pi.xb)(),Ri=t=>(Ri=pi.yb)(t),Fi=()=>(Fi=pi.zb)();function Pi(){0<K||(m?(l(f),m||St(G),startWorker(f)):(St(V),0<K||yi||(yi=!0,f.calledRun=!0,H||(m||St(G),l(f),m||St(Y)))))}return f.Nt=862621,f.Ut=862843,f.stackSave=()=>Oi(),f.stackRestore=t=>Ci(t),f.stackAlloc=t=>Ai(t),f.UTF8ToString=Rt,f.stringToUTF8=Ut,f.lengthBytesUTF8=Dt,X=function t(){yi||Pi(),yi||(X=t)},Pi(),d},Mt=St,"em-pthread"===globalThis.self?.name&&St()})),pu=V((()=>{yt(),Et=(n&&"SCRIPT"===n.tagName.toUpperCase()&&n.src||new URL("yunjing-for-cesium.js",document.baseURI).href)??(typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0),Ct=typeof location>"u"?void 0:location.origin,At=(t,e)=>{try{let n=e??Et;return(n?new URL(t,n):new URL(t)).origin===Ct}catch{return!1}},Ot=async t=>{let e=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(e)},It=(xt(),Y(wt)).default,Tt=async()=>{if(!Et)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(At(Et))return[void 0,It()];let t=await Ot(Et);return[t,It(t)]},zt=(du(),Y(kt)).default,Rt=async(t,e,n)=>[void 0,zt]})),vu=V((()=>{pu(),Pt=!1,Dt=!1,Nt=!1,Ut=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},qt=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},jt=async t=>{if(Pt)return Promise.resolve();if(Dt)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Nt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Dt=!0;let e=t.initTimeout,n=t.numThreads;if(!qt())throw new Error("WebAssembly SIMD is not supported in the current environment.");let i=Ut();n>1&&!i&&(typeof self<"u"&&self.crossOriginIsolated,t.numThreads=n=1);let r=t.wasmPaths,s="string"==typeof r?r:void 0,o=r?.mjs,a=o?.href??o,u=r?.wasm,h=u?.href??u,l=t.wasmBinary,[c,f]=await Rt(a,s,n>1),d=!1,p=[];if(e>0&&p.push(new Promise((t=>{setTimeout((()=>{d=!0,t()}),e)}))),p.push(new Promise(((t,e)=>{let i={numThreads:n};l?i.wasmBinary=l:(h||s)&&(i.locateFile=(t,e)=>h??(s??e)+t),f(i).then((e=>{Dt=!1,Pt=!0,Ft=e,t(),c&&URL.revokeObjectURL(c)}),(t=>{Dt=!1,Nt=!0,e(t)}))}))),await Promise.race(p),d)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},Bt=()=>{if(Pt&&Ft)return Ft;throw new Error("WebAssembly is not initialized yet.")}})),mu=V((()=>{vu(),Lt=(t,e)=>{let n=Bt(),i=n.lengthBytesUTF8(t)+1,r=n.Pt(i);return n.stringToUTF8(t,r,i),e.push(r),r},Ht=(t,e,n,i)=>{if("object"==typeof t&&null!==t){if(n.has(t))throw new Error("Circular reference in options");n.add(t)}Object.entries(t).forEach((([t,r])=>{let s=e?e+t:t;if("object"==typeof r)Ht(r,s+".",n,i);else if("string"==typeof r||"number"==typeof r)i(s,r.toString());else{if("boolean"!=typeof r)throw new Error("Can't handle extra config type: "+typeof r);i(s,r?"1":"0")}}))},Wt=t=>{let e=Bt(),n=e.stackSave();try{let n=e.stackAlloc(8);e.st(n,n+4);let i=e.HEAP32[n/4],r=e.HEAPU32[n/4+1],s=r?e.UTF8ToString(r):"";throw new Error(`${t} ERROR_CODE: ${i}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(n)}}})),yu=V((()=>{vu(),mu(),Vt=t=>{let e=Bt(),n=0,i=[],r=t||{};try{if(void 0===t?.logSeverityLevel)r.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===t?.logVerbosityLevel)r.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);void 0===t?.terminate&&(r.terminate=!1);let s=0;return void 0!==t?.tag&&(s=Lt(t.tag,i)),n=e.St(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,s),0===n&&Wt("Can't create run options."),void 0!==t?.extra&&Ht(t.extra,"",new WeakSet,((t,r)=>{let s=Lt(t,i),o=Lt(r,i);0!==e.Mt(n,s,o)&&Wt(`Can't set a run config entry: ${t} - ${r}.`)})),[n,i]}catch(t){throw 0!==n&&e.Et(n),i.forEach((t=>e.Dt(t))),t}}})),wu=V((()=>{vu(),mu(),Gt=t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}},Yt=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},Kt=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some((t=>"webgpu"===("string"==typeof t?t:t.name)))&&(t.enableMemPattern=!1)},Xt=(t,e,n)=>{for(let i of e){let e="string"==typeof i?i:i.name;switch(e){case"webnn":if(e="WEBNN","string"!=typeof i){let e=i?.deviceType;if(e){let i=Lt("deviceType",n),r=Lt(e,n);0!==Bt().ct(t,i,r)&&Wt(`Can't set a session config entry: 'deviceType' - ${e}.`)}}break;case"webgpu":if(e="JS","string"!=typeof i){let e=i;if(e?.preferredLayout){if("NCHW"!==e.preferredLayout&&"NHWC"!==e.preferredLayout)throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${e.preferredLayout}`);let i=Lt("preferredLayout",n),r=Lt(e.preferredLayout,n);0!==Bt().ct(t,i,r)&&Wt(`Can't set a session config entry: 'preferredLayout' - ${e.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${e}`)}let r=Lt(e,n);0!==Bt().ut(t,r)&&Wt(`Can't append execution provider: ${e}.`)}},Qt=t=>{let e=Bt(),n=0,i=[],r=t||{};Kt(r);try{let t=Gt(r.graphOptimizationLevel??"all"),s=Yt(r.executionMode??"sequential"),o="string"==typeof r.logId?Lt(r.logId,i):0,a=r.logSeverityLevel??2;if(!Number.isInteger(a)||a<0||a>4)throw new Error(`log serverity level is not valid: ${a}`);let u=r.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let h="string"==typeof r.optimizedModelFilePath?Lt(r.optimizedModelFilePath,i):0;if(n=e.ot(t,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,o,a,u,h),0===n&&Wt("Can't create session options."),r.executionProviders&&Xt(n,r.executionProviders,i),void 0!==r.enableGraphCapture){if("boolean"!=typeof r.enableGraphCapture)throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let t=Lt("enableGraphCapture",i),s=Lt(r.enableGraphCapture.toString(),i);0!==e.ct(n,t,s)&&Wt(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[t,s]of Object.entries(r.freeDimensionOverrides)){if("string"!=typeof t)throw new Error(`free dimension override name must be a string: ${t}`);if("number"!=typeof s||!Number.isInteger(s)||s<0)throw new Error(`free dimension override value must be a non-negative integer: ${s}`);let r=Lt(t,i);0!==e.ht(n,r,s)&&Wt(`Can't set a free dimension override: ${t} - ${s}.`)}return void 0!==r.extra&&Ht(r.extra,"",new WeakSet,((t,r)=>{let s=Lt(t,i),o=Lt(r,i);0!==e.ct(n,s,o)&&Wt(`Can't set a session config entry: ${t} - ${r}.`)})),[n,i]}catch(t){throw 0!==n&&e.ft(n),i.forEach((t=>e.Dt(t))),t}}})),gu=V((()=>{Zt=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${t}`)}},Jt=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${t}`)}},te=t=>[void 0,4,1,1,2,2,4,8,void 0,1,2,8,4,8,void 0,void 0,void 0][t],ee=t=>{switch(t){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${t}`)}},ne=t=>{switch(t){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${t}`)}},ie=t=>"float32"===t||"float16"===t||"int32"===t||"int64"===t||"uint32"===t||"uint8"===t||"bool"===t,re=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${t}`)}}})),bu=V((()=>{yt(),se=async t=>{if("string"==typeof t){let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let n=e.headers.get("Content-Length"),i=n?parseInt(n,10):0;if(i<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n,r=e.body.getReader();try{n=new ArrayBuffer(i)}catch(t){if(!(t instanceof RangeError))throw t;{let t=Math.ceil(i/65536);n=new WebAssembly.Memory({initial:t,maximum:t}).buffer}}let s=0;for(;;){let{done:t,value:e}=await r.read();if(t)break;let i=e.byteLength;new Uint8Array(n,s,i).set(e),s+=i}return new Uint8Array(n,0,i)}}return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}})),_u=V((()=>{gu(),ue=(t,e)=>{oe=t,ae=e},he=(t,e)=>{ne(t)>=ne(oe)&&"function"==typeof e&&e()},le=(...t)=>{ae&&he(...t)}})),xu=V((()=>{gu(),ce=(t,e)=>new(ee(e))(t)})),ku=V((()=>{})),$u=V((()=>{_u(),ku(),fe=new Map([[64,250],[128,200],[256,200],[512,200],[2048,230],[4096,200],[8192,50],[16384,50],[32768,50],[65536,50],[131072,50],[262144,50],[524288,50],[1048576,50],[2097152,30],[4194304,20],[8388608,10],[12582912,10],[16777216,10],[26214400,15],[33554432,22],[44236800,2],[58982400,6],[67108864,6],[134217728,6],[167772160,6]]),de=[],pe=t=>16*Math.ceil(t/16),ve=t=>{for(let e=0;e<de.length;e++){let n=de[e];if(t<=n)return n}return 16*Math.ceil(t/16)},me=1,ye=()=>me++,we=async(t,e,n,i)=>{let r=pe(n),s=t.device.createBuffer({size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});try{let o=t.getCommandEncoder();t.endComputePass(),o.copyBufferToBuffer(e,0,s,0,r),t.flush(),await s.mapAsync(GPUMapMode.READ);let a=s.getMappedRange();if(i){let t=i();return t.set(new Uint8Array(a,0,n)),t}return new Uint8Array(a.slice(0,n))}finally{s.destroy()}},ge=class{constructor(t){this.backend=t,this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.buffersForUploadingPending=[],this.buffersPending=[],this.externalBuffers=new Map,this.capturedPendingBuffers=new Map;for(let[t]of fe)de.push(t),this.freeBuffers.set(t,[]),this.freeUniformBuffers.set(t,[])}upload(t,e){let n=e.buffer,i=e.byteOffset,r=e.byteLength,s=pe(r),o=this.storageCache.get(t);if(!o)throw new Error("gpu data for uploading does not exist");if(o.originalSize!==r)throw new Error(`inconsistent data size. gpu data size=${o.originalSize}, data size=${r}`);let a=this.backend.device.createBuffer({mappedAtCreation:!0,size:s,usage:GPUBufferUsage.MAP_WRITE|GPUBufferUsage.COPY_SRC}),u=a.getMappedRange();new Uint8Array(u).set(new Uint8Array(n,i,r)),a.unmap();let h=this.backend.getCommandEncoder();this.backend.endComputePass(),h.copyBufferToBuffer(a,0,o.gpuData.buffer,0,s),le("verbose",(()=>`[WebGPU] GpuDataManager.upload(id=${t})`)),this.buffersForUploadingPending.push(a)}memcpy(t,e){let n=this.storageCache.get(t);if(!n)throw new Error("source gpu data for memcpy does not exist");let i=this.storageCache.get(e);if(!i)throw new Error("destination gpu data for memcpy does not exist");if(n.originalSize!==i.originalSize)throw new Error("inconsistent source and destination gpu data size");let r=pe(n.originalSize),s=this.backend.getCommandEncoder();this.backend.endComputePass(),s.copyBufferToBuffer(n.gpuData.buffer,0,i.gpuData.buffer,0,r)}registerExternalBuffer(t,e,n){let i;if(n){if(i=this.externalBuffers.get(n),void 0===i)throw new Error("previous buffer is not registered");if(t===n)return le("verbose",(()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${e}) => id=${i}, buffer is the same, skip.`)),i;if(this.backend.capturedCommandList.has(this.backend.currentSessionId))throw new Error("Registering a different external buffer under graph capture mode is not supported yet.\n Please use the previous external buffer!");this.externalBuffers.delete(n)}else i=ye();return this.storageCache.set(i,{gpuData:{id:i,type:0,buffer:t},originalSize:e}),this.externalBuffers.set(t,i),le("verbose",(()=>`[WebGPU] GpuDataManager.registerExternalBuffer(size=${e}) => id=${i}, registered.`)),i}unregisterExternalBuffer(t){let e=this.externalBuffers.get(t);void 0!==e&&(this.storageCache.delete(e),this.externalBuffers.delete(t),le("verbose",(()=>`[WebGPU] GpuDataManager.unregisterExternalBuffer() => id=${e}`)))}create(t,e=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST){let n,i=ve(t),r=(e&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE,s=(e&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM;if(r||s){let t=(r?this.freeBuffers:this.freeUniformBuffers).get(i);n=t&&t.length>0?t.pop():this.backend.device.createBuffer({size:i,usage:e})}else n=this.backend.device.createBuffer({size:i,usage:e});let o={id:ye(),type:0,buffer:n};return this.storageCache.set(o.id,{gpuData:o,originalSize:t}),le("verbose",(()=>`[WebGPU] GpuDataManager.create(size=${t}) => id=${o.id}`)),o}get(t){return this.storageCache.get(t)?.gpuData}release(t){let e=this.storageCache.get(t);if(!e)throw new Error("releasing data does not exist");return le("verbose",(()=>`[WebGPU] GpuDataManager.release(id=${t}), gpuDataId=${e.gpuData.id}`)),this.storageCache.delete(t),this.buffersPending.push(e.gpuData.buffer),e.originalSize}async download(t,e){let n=this.storageCache.get(t);if(!n)throw new Error("data does not exist");await we(this.backend,n.gpuData.buffer,n.originalSize,e)}refreshPendingBuffers(){for(let t of this.buffersForUploadingPending)t.destroy();if(this.buffersForUploadingPending=[],0!==this.buffersPending.length)if("default"===this.backend.sessionStatus){for(let t of this.buffersPending){let e=fe.get(t.size);if((t.usage&GPUBufferUsage.STORAGE)===GPUBufferUsage.STORAGE){let n=this.freeBuffers.get(t.size)||[];void 0===e||n.length>=e?t.destroy():n.push(t)}else if((t.usage&GPUBufferUsage.UNIFORM)===GPUBufferUsage.UNIFORM){let n=this.freeUniformBuffers.get(t.size)||[];void 0===e||n.length>=e?t.destroy():n.push(t)}else t.destroy()}this.buffersPending=[]}else{let t=this.capturedPendingBuffers.get(this.backend.currentSessionId);t||(t=[],this.capturedPendingBuffers.set(this.backend.currentSessionId,t));for(let e of this.buffersPending)t.push(e);this.buffersPending=[]}}dispose(){this.freeBuffers.forEach((t=>{t.forEach((t=>{t.destroy()}))})),this.freeUniformBuffers.forEach((t=>{t.forEach((t=>{t.destroy()}))})),this.storageCache.forEach((t=>{t.gpuData.buffer.destroy()})),this.capturedPendingBuffers.forEach((t=>{t.forEach((t=>{t.destroy()}))})),this.storageCache=new Map,this.freeBuffers=new Map,this.freeUniformBuffers=new Map,this.capturedPendingBuffers=new Map}onReleaseSession(t){let e=this.capturedPendingBuffers.get(t);e&&(e.forEach((t=>{t.destroy()})),this.capturedPendingBuffers.delete(t))}},be=(...t)=>new ge(...t)})),Su=V((()=>{_e=class{constructor(t){Object.assign(this,t)}get cacheKey(){return this.key||(this.key=Object.getOwnPropertyNames(this).sort().map((t=>`${this[t]}`)).join(";")),this.key}},xe=t=>new _e(t)})),Mu=V((()=>{ke=class{static calcMatMulShape(t,e){return t[1]!==e[0]?void 0:[t[0],e[1]]}},$e=class{static calcShape(t,e,n=!1){let i=t.length,r=e.length;if(0===i)return e;if(0===r)return t;let s=Math.max(t.length,e.length),o=new Array(s);if(n){if(i<2||r<2)return;let n=ke.calcMatMulShape([t[i-2],t[i-1]],[e[r-2],e[r-1]]);if(void 0===n)return;[o[s-2],o[s-1]]=n}for(let a=n?3:1;a<=s;a++){let n=i-a<0?1:t[i-a],u=r-a<0?1:e[r-a];if(n!==u&&n>1&&u>1)return;let h=Math.max(n,u);if(n&&u)o[s-a]=Math.max(n,u);else{if(h>1)return;o[s-a]=0}}return o}static isValidBroadcast(t,e){let n=t.length,i=e.length;if(n>i)return!1;for(let r=1;r<=n;r++)if(1!==t[n-r]&&t[n-r]!==e[i-r])return!1;return!0}},Se=class t{static size(e){return t.getSizeFromDimensionRange(e,0,e.length)}static convertShape(t,e=4){let n=t.length;if(0===n)return[];let i=new Array(n),r=n-1;for(;r>=0;){if(t[r]%e==0){i[r]=t[r]/e;break}if(e%t[r]!=0)throw new Error("cannot convert shape");i[r]=1,e/=t[r],r--}for(r--;r>=0;r--)i[r]=t[r];return i}static sizeFromDimension(e,n){if(n<0||n>e.length)throw new Error(`invalid dimension of ${n} for sizeFromDimension as Tensor has ${e.length} dimensions.`);return t.getSizeFromDimensionRange(e,n,e.length)}static sizeToDimension(e,n){if(n<0||n>e.length)throw new Error(`invalid dimension of ${n} for sizeToDimension as Tensor has ${e.length} dimensions.`);return t.getSizeFromDimensionRange(e,0,n)}static getSizeFromDimensionRange(t,e,n){let i=1;for(let r=e;r<n;r++){if(t[r]<0)throw new Error("cannot get valid size from specified dimension range. Most likely the range contains negative values in them.");i*=t[r]}return i}static computeStrides(t){let e=t.length;if(0===e)return[];if(1===e)return[1];let n=new Array(e);n[e-1]=1,n[e-2]=t[e-1];for(let i=e-3;i>=0;--i)n[i]=n[i+1]*t[i+1];return n}static normalizeAxis(t,e){if(t<-e&&t>=e)throw new Error("unsupported axis for this operation.");return t<0?t+e:t}static normalizeAxes(t,e){return t.map((n=>this.normalizeAxis(n,e??t.length)))}static sortBasedOnPerm(t,e){return e?e.map((e=>t[e])):t.slice().reverse()}static padShape(t,e){let n=t.length;return t.map(((t,i)=>t+e[i]+e[i+n]))}static areEqual(t,e){return t.length===e.length&&t.every(((t,n)=>t===e[n]))}},Me=class t{static adjustPoolAttributes(t,e,n,i,r,s){if(!t&&n.length!==e.length-2)throw new Error("length of specified kernel shapes should be 2 less than length of input dimensions");if(t)for(let t=0;t<e.length-2;t++)t>=n.length?n.push(e[t+2]):n[t]=e[t+2];for(let t=0;t<n.length;t++)if(t<i.length){if(i[t]<0)throw new Error("strides should be greater than or equal to 1")}else i.push(1);for(let t=0;t<n.length;t++)if(t<r.length){if(r[t]<0)throw new Error("dilations should be greater than or equal to 1")}else r.push(1);for(let t=0;t<2*n.length;t++)if(t<s.length){if(s[t]<0)throw new Error("pad should be greater than or equal to 1")}else s.push(0);for(let t=0;t<n.length;t++){if(n[t]<=0)throw new Error("kernel shapes need to be greater than 0");if(s[t]>=n[t]||s[t+n.length]>=n[t])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(e,n,i,r,s,o,a){if(a){if(s.length!==2*(e.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(n.length!==e.length-2)throw new Error("length of strides should be the length of data dimensions");if(r.length!==e.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let u=0;u<e.length-2;u++)t.adjustPadAndReturnShape(e[u+(o?1:2)],n[u],i[u],r[u],s,u,u+e.length-2,a)}}static computePoolOutputShape(e,n,i,r,s,o,a){if(n.length<=0)throw new Error("input shape must be of size greater than 0");let u=[n[0],n[1]];return t.computeShapeHelper(e,n,u,i,r,s,o,a),u}static computeConvOutputShape(e,n,i,r,s,o,a){if(e.length<=0||n.length<=0)throw new Error("invalid input tensor dims or invalid filter tensor dims");let u=[e[0],n[0]];return t.computeShapeHelper(!1,e,u,i,r,s,o,a),u}static computeShapeHelper(e,n,i,r,s,o,a,u){if(e)for(let t=0;t<n.length-2;t++)i.push(1);else for(let e=0;e<n.length-2;e++)i.push(t.adjustPadAndReturnShape(n[e+2],r[e],s[e],o[e],a,e,e+n.length-2,u))}static adjustPadAndReturnShape(t,e,n,i,r,s,o,a){let u=n*(i-1)+1;if(!a||"NOTSET"===a)return Math.floor((t+r[s]+r[o]-u)/e+1);switch(a){case"VALID":return r[s]=0,r[o]=0,Math.floor((t-u)/e+1);case"SAME_LOWER":case"SAME_UPPER":if(1!==n)throw new Error("Dilation not supported for SAME_UPPER or SAME_LOWER");{let n=((t+e-1)/e-1)*e+i-t;return r[s]=Math.floor("SAME_LOWER"===a?(n+1)/2:n/2),r[o]=n-r[s],Math.floor((t+n-i)/e+1)}default:throw new Error("Unsupported AutoPad type")}}},Ee=class{static getShapeOfGemmResult(t,e,n,i,r){if(2!==t.length||2!==n.length)throw new Error("shape need to be of size 2");let s,o,a;e?(s=t[1],o=t[0]):(s=t[0],o=t[1]);let u=-1;if(i?(a=n[0],u=1):(a=n[1],u=0),n[u]!==o)throw new Error("dimension mismatch");if(s<=0||a<=0||o<=0)throw new Error("invalid shape specified");if(r&&!$e.isValidBroadcast(r,[s,a]))throw new Error("gemm: invalid bias shape for broadcast");return[s,a,o]}},Ce=-34028234663852886e22,Ae=34028234663852886e22})),Eu=V((()=>{gu(),Mu(),Oe=64,Ie=(t,e)=>{if(3===e)throw new Error("vec3 has same alignment as vec4, use vec4 instead");switch(t){case 10:return e>1?`vec${e}<f16>`:"f16";case 1:return e>1?`vec${e}<f32>`:"f32";case 6:return e>1?`vec${e}<i32>`:"i32";case 12:return e>1?`vec${e}<u32>`:"u32";case 7:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2<u32>","i32"];case 13:if(e>1)throw new Error("currently not supported vecX of uint64 yet");return["vec2<u32>","u32"];case 9:if(4!==e)throw new Error("bool must be vec4");return["u32","vec4<bool>"];default:throw new Error(`Unknown data type: ${t}`)}},Te=(t,e=1)=>{let n=Ie(t,e);return"string"==typeof n?n:n[0]},ze=(t,e=1)=>{let n=Ie(t,e);return"string"==typeof n?n:n[1]},Re=(...t)=>{let e=[];return t.forEach((t=>{0!==t.length&&e.push({type:12,data:t},{type:12,data:Se.computeStrides(t)})})),e},Fe=t=>t%4==0?4:t%2==0?2:1,Pe=(t="f32",e,n="0")=>e&&1!==e?`vec${e}<${t}>(${n})`:`${t}(${n})`,De=(t,e,n)=>"f32"===t?n:1===e?`f32(${n})`:`vec${e}<f32>(${n})`,Ne=(t,e)=>4===e?`(${t}.x + ${t}.y + ${t}.z + ${t}.w)`:2===e?`(${t}.x + ${t}.y)`:3===e?`(${t}.x + ${t}.y + ${t}.z)`:t,Ue=(t,e,n,i)=>t.startsWith("uniforms.")&&n>4?"string"==typeof e?"f16"===i?`${t}[(${e}) / 8][(${e}) % 8 / 4][(${e}) % 8 % 4]`:`${t}[(${e}) / 4][(${e}) % 4]`:"f16"===i?`${t}[${Math.floor(e/8)}][${Math.floor(e%8/4)}][${e%8%4}]`:`${t}[${Math.floor(e/4)}][${e%4}]`:n>1?`${t}[${e}]`:t,qe=(t,e,n,i,r)=>{let s="number"==typeof n,o=s?n:n.length,a=[...new Array(o).keys()],u=o<2?"u32":o<=4?`vec${o}<u32>`:`array<u32, ${o}>`,h=Ie(e,r),l="string"==typeof h?h:h[1],c="string"==typeof h?h:h[0],f={indices:u,value:l,storage:c,tensor:e},d=t=>"string"==typeof t?t:`${t}u`,p={offsetToIndices:!1,indicesToOffset:!1,broadcastedIndicesToOffset:!1,set:!1,setByIndices:!1,get:!1,getByIndices:!1},v=s?"uniforms.":"",m=`${v}${t}_shape`,y=`${v}${t}_strides`,w="";for(let t=0;t<o-1;t++)w+=`\n let dim${t} = current / ${Ue(y,t,o)};\n let rest${t} = current % ${Ue(y,t,o)};\n indices[${t}] = dim${t};\n current = rest${t};\n `;w+=`indices[${o-1}] = current;`;let g=o<2?"":`\n fn o2i_${t}(offset: u32) -> ${f.indices} {\n var indices: ${f.indices};\n var current = offset;\n ${w}\n return indices;\n }`,b=[];if(o>=2)for(let t=o-1;t>=0;t--)b.push(`${Ue(y,t,o)} * (indices[${t}])`);let _=o<2?"":`\n fn i2o_${t}(indices: ${f.indices}) -> u32 {\n return ${b.join("+")};\n }`,x=(...t)=>0===o?"0u":`${f.indices}(${t.map(d).join(",")})`,k=(t,e)=>o<2?`${t}`:`${Ue(t,e,o)}`,$={},S=(e,n)=>(()=>{if(f.storage===f.value)return`${t}[${e}]=${n};`;if("vec2<u32>"===f.storage&&"i32"===f.value)return`${t}[${e}]=vec2<u32>(u32(${n}), select(0u, 0xFFFFFFFFu, ${n} < 0));`;if("vec2<u32>"===f.storage&&"u32"===f.value)return`${t}[${e}]=vec2<u32>(u32(${n}), 0u);`;if("u32"===f.storage&&"vec4<bool>"===f.value)return`${t}[${e}]=dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(${n}));`;throw new Error(`not supported combination of storage type ${f.storage} and value type ${f.value} yet`)})(),M=e=>(()=>{if(f.storage===f.value)return`${t}[${e}]`;if("vec2<u32>"===f.storage&&"i32"===f.value)return`i32(${t}[${e}].x)`;if("vec2<u32>"===f.storage&&"u32"===f.value)return`u32(${t}[${e}].x)`;if("u32"===f.storage&&"vec4<bool>"===f.value)return`vec4<bool>(bool(${t}[${e}] & 0xFFu), bool(${t}[${e}] & 0xFF00u), bool(${t}[${e}] & 0xFF0000u), bool(${t}[${e}] & 0xFF000000u))`;throw new Error(`not supported combination of storage type ${f.storage} and value type ${f.value} yet`)})(),E=o<2?"":`\n fn get_${t}ByIndices(indices: ${f.indices}) -> ${l} {\n return ${M(`i2o_${t}(indices)`)};\n }`,C=o<2?"":(()=>{let e=a.map((t=>`d${t}: u32`)).join(", "),n=a.map((t=>`d${t}`)).join(", ");return`\n fn get_${t}(${e}) -> ${l} {\n return get_${t}ByIndices(${x(n)});\n }`})(),A=o<2?"":`\n fn set_${t}ByIndices(indices: ${f.indices}, value: ${l}) {\n ${S(`i2o_${t}(indices)`,"value")}\n }`,O=o<2?"":(()=>{let e=a.map((t=>`d${t}: u32`)).join(", "),n=a.map((t=>`d${t}`)).join(", ");return`\n fn set_${t}(${e}, value: ${l}) {\n set_${t}ByIndices(${x(n)}, value);\n }`})();return{impl:()=>{let t=[],e=!1;return p.offsetToIndices&&(t.push(g),e=!0),p.indicesToOffset&&(t.push(_),e=!0),p.broadcastedIndicesToOffset&&(Object.values($).forEach((e=>t.push(e))),e=!0),p.set&&(t.push(O),e=!0),p.setByIndices&&(t.push(A),e=!0),p.get&&(t.push(C),e=!0),p.getByIndices&&(t.push(E),e=!0),!s&&e&&t.unshift(`const ${m} = ${f.indices}(${n.join(",")});`,`const ${y} = ${f.indices}(${Se.computeStrides(n).join(",")});`),t.join("\n")},type:f,offsetToIndices:e=>(p.offsetToIndices=!0,o<2?e:`o2i_${t}(${e})`),indicesToOffset:e=>(p.indicesToOffset=!0,o<2?e:`i2o_${t}(${e})`),broadcastedIndicesToOffset:(e,n)=>{p.broadcastedIndicesToOffset=!0;let i=`${n.name}broadcastedIndicesTo${t}Offset`;if(i in $)return`${i}(${e})`;let r=[];for(let t=o-1;t>=0;t--){let e=n.indicesGet("outputIndices",t+n.rank-o);r.push(`${k(y,t)} * (${e} % ${k(m,t)})`)}return $[i]=`fn ${i}(outputIndices: ${n.type.indices}) -> u32 {\n return ${r.length>0?r.join("+"):"0u"};\n }`,`${i}(${e})`},indices:x,indicesGet:k,indicesSet:(t,e,n)=>o<2?`${t}=${n};`:`${Ue(t,e,o)}=${n};`,set:(...e)=>{if(e.length!==o+1)throw new Error(`indices length must be ${o}`);let n=e[o];if("string"!=typeof n)throw new Error("value must be string");let i=e.slice(0,o).map(d).join(",");return 0===o?S("0u",n):1===o?S(i[0],n):(p.set=!0,p.setByIndices=!0,p.indicesToOffset=!0,`set_${t}(${i}, ${n})`)},setByOffset:S,setByIndices:(e,n)=>o<2?S(e,n):(p.setByIndices=!0,p.indicesToOffset=!0,`set_${t}ByIndices(${e}, ${n});`),get:(...e)=>{if(e.length!==o)throw new Error(`indices length must be ${o}`);let n=e.map(d).join(",");return 0===o?M("0u"):1===o?M(n[0]):(p.get=!0,p.getByIndices=!0,p.indicesToOffset=!0,`get_${t}(${n})`)},getByOffset:M,getByIndices:e=>o<2?M(e):(p.getByIndices=!0,p.indicesToOffset=!0,`get_${t}ByIndices(${e})`),usage:i,name:t,strides:y,shape:m,rank:o}},je=(t,e,n,i=1)=>qe(t,e,n,"input",i),Be=(t,e,n,i=1)=>qe(t,e,n,"output",i),Le=(t,e,n,i=1)=>qe(t,e,n,"internal",i),He=class{constructor(t,e){this.normalizedDispatchGroup=t,this.limits=e,this.internalVariables=[],this.variables=[],this.uniforms=[],this.variableIndex=0}guardAgainstOutOfBoundsWorkgroupSizes(t){return`if (global_idx >= ${"number"==typeof t?`${t}u`:t}) { return; }`}mainStart(t=Oe){let e="number"==typeof t?t:t[0],n="number"==typeof t?1:t[1],i="number"==typeof t?1:t[2];if(e>this.limits.maxComputeWorkgroupSizeX||n>this.limits.maxComputeWorkgroupSizeY||i>this.limits.maxComputeWorkgroupSizeZ)throw new Error(`workgroup size [${e}, ${n}, ${i}] exceeds the maximum workgroup size [${this.limits.maxComputeWorkgroupSizeX}, ${this.limits.maxComputeWorkgroupSizeY}, ${this.limits.maxComputeWorkgroupSizeZ}].`);if(e*n*i>this.limits.maxComputeInvocationsPerWorkgroup)throw new Error(`workgroup size [${e}, ${n}, ${i}] exceeds the maximum workgroup invocations ${this.limits.maxComputeInvocationsPerWorkgroup}.`);let r=1===this.normalizedDispatchGroup[1]&&1===this.normalizedDispatchGroup[2];return`@compute @workgroup_size(${e}, ${n}, ${i})\n fn main(${r?"@builtin(global_invocation_id) global_id : vec3<u32>,\n @builtin(workgroup_id) workgroup_id : vec3<u32>,\n @builtin(local_invocation_id) local_id : vec3<u32>":"@builtin(global_invocation_id) global_id : vec3<u32>,\n @builtin(local_invocation_id) local_id : vec3<u32>,\n @builtin(local_invocation_index) local_idx : u32,\n @builtin(workgroup_id) workgroup_id : vec3<u32>,\n @builtin(num_workgroups) num_workgroups : vec3<u32>"}) {\n ${r?"let global_idx = global_id.x; let local_idx = local_id.x;":`let global_idx = (workgroup_id.z * num_workgroups[0] * num_workgroups[1] +\n workgroup_id.y * num_workgroups[0] + workgroup_id.x) * ${e*n*i}u + local_idx;`}\n `}appendVariableUniforms(t){0!==t.rank&&(t.shape.startsWith("uniforms.")&&this.uniforms.push({name:t.shape.replace("uniforms.",""),type:"u32",length:t.rank}),t.strides.startsWith("uniforms.")&&this.uniforms.push({name:t.strides.replace("uniforms.",""),type:"u32",length:t.rank}))}declareVariable(t,e){if("internal"===t.usage)throw new Error("cannot use internal variable with declareVariable(). use registerInternalVariables() instead.");this.variables.push(t),this.appendVariableUniforms(t);let n="input"===t.usage?"read":"read_write",i=t.type.storage;return`@group(0) @binding(${e}) var<storage, ${n}> ${t.name}: array<${i}>;`}declareVariables(...t){return t.map((t=>this.declareVariable(t,this.variableIndex++))).join("\n")}registerInternalVariable(t){if("internal"!==t.usage)throw new Error("cannot use input or output variable with registerInternalVariable(). use declareVariables() instead.");this.internalVariables.push(t),this.appendVariableUniforms(t)}registerInternalVariables(...t){return t.forEach((t=>this.registerInternalVariable(t))),this}registerUniform(t,e,n=1){return this.uniforms.push({name:t,type:e,length:n}),this}registerUniforms(t){return this.uniforms=this.uniforms.concat(t),this}uniformDeclaration(){if(0===this.uniforms.length)return"";let t=[];for(let{name:e,type:n,length:i}of this.uniforms)if(i&&i>4)"f16"===n?t.push(`@align(16) ${e}:array<mat2x4<${n}>, ${Math.ceil(i/8)}>`):t.push(`${e}:array<vec4<${n}>, ${Math.ceil(i/4)}>`);else{let r=null==i||1===i?n:`vec${i}<${n}>`;t.push(`${e}:${r}`)}return`\n struct Uniforms { ${t.join(", ")} };\n @group(0) @binding(${this.variableIndex}) var<uniform> uniforms: Uniforms;`}get additionalImplementations(){return this.uniformDeclaration()+this.variables.map((t=>t.impl())).join("\n")+this.internalVariables.map((t=>t.impl())).join("\n")}get variablesInfo(){if(0===this.uniforms.length)return;let t=t=>[12,10,1,6][["u32","f16","f32","i32"].indexOf(t)];return this.uniforms.map((e=>[t(e.type),e.length??1]))}},We=(t,e)=>new He(t,e),Ve=(t,e)=>{let n=t.length,i=[];for(let r=0;r<n;r++){let s=n-1-r,o=t[s]||1;(e[e.length-1-r]||1)>1&&1===o&&i.unshift(s)}return i}})),Cu=V((()=>{gu(),Mu(),Su(),Eu(),Ge=t=>{if(!t||1!==t.length)throw new Error("Transpose requires 1 input.")},Ye=(t,e)=>e&&e.length!==t?[...new Array(t).keys()].reverse():e,Ke=(t,e)=>Se.sortBasedOnPerm(t,Ye(t.length,e)),Xe=(t,e,n,i)=>{let r=[];r.push(`fn perm(i: ${i.type.indices}) -> ${n.type.indices} {\n var a: ${n.type.indices};`);for(let i=0;i<e;++i)r.push(n.indicesSet("a",t[i],`i[${i}]`));return r.push("return a;}"),r.join("\n")},Qe=(t,e)=>{let n,i=t.dataType,r=t.dims.length,s=Ye(r,e),o=Ke(t.dims,s),a=Be("output",i,o.length),u=je("a",i,r);if(2===s.length&&1===s[0]&&0===s[1]){let t=a.type.value,e=[16,16,1];n=n=>`\n ${n.registerUniform("output_size","u32").declareVariables(u,a)}\n var<workgroup> tile : array<array<${t}, ${e[0]+1}>, ${e[0]}>;\n ${n.mainStart(e)}\n var x = workgroup_id.x * ${e[0]}u + local_id.x;\n var y = workgroup_id.y * ${e[0]}u + local_id.y;\n let width = uniforms.output_shape[0];\n let height = uniforms.output_shape[1];\n if (x < width && y < height) {\n tile[local_id.y][local_id.x] = ${u.getByOffset("y * width + x")};\n }\n workgroupBarrier();\n x = workgroup_id.y * ${e[0]}u + local_id.x;\n y = workgroup_id.x * ${e[0]}u + local_id.y;\n if (x < height && y < width) {\n ${a.setByOffset("y * height + x","tile[local_id.x][local_id.y]")}\n }\n }`}else n=t=>`\n ${t.registerUniform("output_size","u32").declareVariables(u,a)}\n\n ${Xe(s,r,u,a)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n\n let indices = ${a.offsetToIndices("global_idx")};\n let aIndices = perm(indices);\n\n ${a.setByOffset("global_idx",u.getByIndices("aIndices"))}\n }`;return{name:"Transpose",shaderCache:{hint:`${e}`,inputDependencies:["rank"]},getRunData:t=>{let e=Se.size(o);return{outputs:[{dims:o,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(e/64)},programUniforms:[{type:12,data:e},...Re(t[0].dims,o)]}},getShaderSource:n}},Ze=(t,e)=>{Ge(t.inputs),t.compute(Qe(t.inputs[0],e.perm))},Je=t=>xe({perm:t.perm})})),Au=V((()=>{gu(),Mu(),Eu(),Ou(),Cu(),tn={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate * candidate",logSumExp:"bestValue + exp(candidate)",l1:"bestValue + abs(candidate)",l2:"bestValue + candidate * candidate",logSum:"bestValue + candidate"},en={max:"select(bestValue, candidate, candidate > bestValue)",min:"select(bestValue, candidate, candidate < bestValue)",mean:"bestValue + candidate",sum:"bestValue + candidate",prod:"bestValue * candidate",sumSquare:"bestValue + candidate",logSumExp:"bestValue + candidate",l1:"bestValue + candidate",l2:"bestValue + candidate",logSum:"bestValue + candidate"},nn={max:"_A[offset]",min:"_A[offset]",mean:"0",sum:"0",prod:"1",sumSquare:"0",logSumExp:"0",l1:"0",l2:"0",logSum:"0"},rn={max:"bestValue",min:"bestValue",sum:"bestValue",prod:"bestValue",sumSquare:"bestValue",logSumExp:"log(bestValue)",l1:"bestValue",l2:"sqrt(bestValue)",logSum:"log(bestValue)"},sn=(t,e)=>{let n=[];for(let i=e-t;i<e;++i)n.push(i);return n},on=(t,e)=>{let n=[],i=t.length;for(let r=0;r<i;r++)-1===e.indexOf(r)&&n.push(t[r]);let r=e.map((e=>t[e]));return[n,r]},an=(t,e)=>{let n=t.length+e.length,i=[],r=0;for(let s=0;s<n;s++)-1===e.indexOf(s)?i.push(t[r++]):i.push(1);return i},un=(t,e)=>{for(let n=0;n<t.length;++n)if(t[t.length-n-1]!==e-1-n)return!1;return!0},hn=(t,e)=>{let n=[];if(!un(t,e)){for(let i=0;i<e;++i)-1===t.indexOf(i)&&n.push(i);t.forEach((t=>n.push(t)))}return n},ln=(t,e,n,i,r,s,o)=>{let a=n[0].dims,u=Se.size(s),h=Se.size(o),l=je("_A",n[0].dataType,a),c=Be("output",r,s);return{name:t,shaderCache:e,getShaderSource:t=>`\n ${t.registerUniform("reduceSize","u32").declareVariables(l,c)}\n \n var<workgroup> aBestValues : array<f32, 32>;\n \n fn DIV_CEIL(a : u32, b : u32) -> u32 {\n return ((a - 1u) / b + 1u);\n }\n ${t.mainStart(32)}\n\n let outputIndex = global_idx / 32;\n let offset = outputIndex * uniforms.reduceSize;\n\n var bestValue = f32(${nn[i]});\n let Length = uniforms.reduceSize;\n for (var k = local_idx; k < Length; k = k + 32) {\n let candidate = f32(${l.getByOffset("offset + k")});\n bestValue = ${tn[i]};\n }\n aBestValues[local_idx] = bestValue;\n workgroupBarrier();\n\n var reduceSize = min(Length, 32u);\n for (var currentSize = reduceSize / 2u; reduceSize > 1u;\n currentSize = reduceSize / 2u) {\n let interval = DIV_CEIL(reduceSize, 2u);\n if (local_idx < currentSize) {\n let candidate = aBestValues[local_idx + interval];\n bestValue = ${en[i]};\n aBestValues[local_idx] = bestValue;\n }\n reduceSize = interval;\n workgroupBarrier();\n }\n\n if (local_idx == 0u) {\n ${c.setByOffset("outputIndex","mean"===i?`${c.type.storage}(bestValue / f32(uniforms.reduceSize))`:`${c.type.storage}(${rn[i]})`)};\n }\n }`,getRunData:()=>({outputs:[{dims:s,dataType:r}],dispatchGroup:{x:u},programUniforms:[{type:12,data:h}]})}},cn=(t,e,n,i)=>{let r=1===t.inputs.length?n:Sn(t.inputs,n),s=r.axes;0===s.length&&!r.noopWithEmptyAxes&&(s=t.inputs[0].dims.map(((t,e)=>e)));let o=Se.normalizeAxes(s,t.inputs[0].dims.length),a=o,u=t.inputs[0],h=hn(a,t.inputs[0].dims.length);h.length>0&&(u=t.compute(Qe(t.inputs[0],h),{inputs:[0],outputs:[-1]})[0],a=sn(a.length,u.dims.length));let[l,c]=on(u.dims,a),f=l;r.keepDims&&(f=an(l,o)),t.compute(ln(e,{hint:r.cacheKey,inputDependencies:["type"]},[u],i,t.inputs[0].dataType,f,c),{inputs:[u]})},fn=(t,e)=>{cn(t,"ReduceMeanShared",e,"mean")},dn=(t,e)=>{cn(t,"ReduceL1Shared",e,"l1")},pn=(t,e)=>{cn(t,"ReduceL2Shared",e,"l2")},vn=(t,e)=>{cn(t,"ReduceLogSumExpShared",e,"logSumExp")},mn=(t,e)=>{cn(t,"ReduceMaxShared",e,"max")},yn=(t,e)=>{cn(t,"ReduceMinShared",e,"min")},wn=(t,e)=>{cn(t,"ReduceProdShared",e,"prod")},gn=(t,e)=>{cn(t,"ReduceSumShared",e,"sum")},bn=(t,e)=>{cn(t,"ReduceSumSquareShared",e,"sumSquare")},_n=(t,e)=>{cn(t,"ReduceLogSumShared",e,"logSum")}})),Ou=V((()=>{gu(),Mu(),Su(),Eu(),Au(),xn=t=>{if(!t||0===t.length||t.length>2)throw new Error("Reduce op requires 1 or 2 inputs.");if(2===t.length&&1!==t[1].dims.length)throw new Error("Invalid axes input dims.")},kn=t=>["","",`var value = ${t.getByIndices("input_indices")};`,""],$n=(t,e,n,i,r,s,o=!1,a=!1)=>{let u=[],h=n[0].dims,l=h.length,c=Se.normalizeAxes(r,l),f=!a&&0===c.length;h.forEach(((t,e)=>{f||c.indexOf(e)>=0?o&&u.push(1):u.push(t)}));let d=u.length,p=Se.size(u);return{name:t,shaderCache:e,getShaderSource:t=>{let e=[],r=je("_A",n[0].dataType,l),a=Be("output",s,d),u=i(r,a,c),p=u[2];for(let t=0,n=0;t<l;t++)f||c.indexOf(t)>=0?(o&&n++,p=`for(var j${t}: u32 = 0; j${t} < ${h[t]}; j${t}++) {\n ${u[2].includes("last_index")?`let last_index = j${t};`:""}\n ${r.indicesSet("input_indices",t,`j${t}`)}\n ${p}\n }`):(e.push(`${r.indicesSet("input_indices",t,a.indicesGet("output_indices",n))};`),n++);return`\n\n ${t.registerUniform("output_size","u32").declareVariables(r,a)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n var input_indices: ${r.type.indices};\n let output_indices = ${a.offsetToIndices("global_idx")};\n\n ${e.join("\n")}\n ${u[0]} // init ops for reduce max/min\n ${u[1]}\n ${p}\n ${u[3]}\n ${4===u.length?a.setByOffset("global_idx","value"):u.slice(4).join("\n")}\n }`},getRunData:()=>({outputs:[{dims:u,dataType:s}],dispatchGroup:{x:Math.ceil(p/64)},programUniforms:[{type:12,data:p},...Re(h,u)]})}},Sn=(t,e)=>{let n=[];return t[1].dims[0]>0&&t[1].getBigInt64Array().forEach((t=>n.push(Number(t)))),xe({axes:n,keepDims:e.keepDims,noopWithEmptyAxes:e.noopWithEmptyAxes})},Mn=(t,e,n,i)=>{let r=t.inputs,s=1===r.length?n:Sn(r,n);t.compute($n(e,{hint:s.cacheKey,inputDependencies:["rank"]},[r[0]],s.noopWithEmptyAxes&&0===s.axes.length?kn:i,s.axes,r[0].dataType,s.keepDims,s.noopWithEmptyAxes),{inputs:[0]})},En=(t,e)=>{xn(t.inputs),Mn(t,"ReduceLogSum",e,((t,e)=>[`var value = ${e.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,"value = log(value);"]))},Cn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceL1",e,((t,e)=>[`var value = ${e.type.storage}(0);`,"",`value += abs(${t.getByIndices("input_indices")});`,""]))},An=(t,e)=>{xn(t.inputs),Mn(t,"ReduceL2",e,((t,e)=>[`var t = ${e.type.value}(0); var value = ${e.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += (t * t);`,"value = sqrt(value);"]))},On=(t,e)=>{xn(t.inputs),Mn(t,"ReduceLogSumExp",e,((t,e)=>[`var value = ${e.type.storage}(0);`,"",`value += exp(${t.getByIndices("input_indices")});`,"value = log(value);"]))},In=(t,e)=>{xn(t.inputs),Mn(t,"ReduceMax",e,((t,e,n)=>{let i=[];for(let e=0;e<t.rank;e++)(n.indexOf(e)>=0||0===n.length)&&i.push(t.indicesSet("input_indices",e,0));return[`${i.join("\n")}`,`var value = ${t.getByIndices("input_indices")};`,`value = max(value, ${t.getByIndices("input_indices")});`,""]}))},Tn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceMean",e,((e,n,i)=>{let r=1;for(let n=0;n<e.rank;n++)(i.indexOf(n)>=0||0===i.length)&&(r*=t.inputs[0].dims[n]);return["var sum = f32(0);","",`sum += f32(${e.getByIndices("input_indices")});`,`let value = ${n.type.value}(sum / ${r});`]}))},zn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceMin",e,((t,e,n)=>{let i=[];for(let e=0;e<t.rank;e++)(n.indexOf(e)>=0||0===n.length)&&i.push(`input_indices[${e}] = 0;`);return[`${i.join("\n")}`,`var value = ${t.getByIndices("input_indices")};`,`value = min(value, ${t.getByIndices("input_indices")});`,""]}))},Rn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceProd",e,((t,e)=>[`var value = ${e.type.storage}(1);`,"",`value *= ${t.getByIndices("input_indices")};`,""]))},Fn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceSum",e,((t,e)=>[`var value = ${e.type.storage}(0);`,"",`value += ${t.getByIndices("input_indices")};`,""]))},Pn=(t,e)=>{xn(t.inputs),Mn(t,"ReduceSumSquare",e,((t,e)=>[`var t = ${e.type.value}(0); var value = ${e.type.value}(0);`,"",`t = ${t.getByIndices("input_indices")}; value += t * t;`,""]))},Dn=(t,e,n)=>{if(0===e.length)return n;let i=1,r=1;for(let n=0;n<e.length;n++)-1===e.indexOf(n)?i*=t[n]:r*=t[n];return r<32&&i>1024},Nn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?Tn(t,e):fn(t,e)},Un=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?Cn(t,e):dn(t,e)},qn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?An(t,e):pn(t,e)},jn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?On(t,e):vn(t,e)},Bn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?In(t,e):mn(t,e)},Ln=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?zn(t,e):yn(t,e)},Hn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?Rn(t,e):wn(t,e)},Wn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?Fn(t,e):gn(t,e)},Vn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?Pn(t,e):bn(t,e)},Gn=(t,e)=>{Dn(t.inputs[0].dims,e.axes,e.noopWithEmptyAxes)?En(t,e):_n(t,e)}})),Iu=V((()=>{gu(),Su(),Ou(),Yn=t=>{if(!t||0===t.length||t.length>2)throw new Error("ArgMinMaxOp op requires 1 or 2 inputs.");if(1!==t[0].dataType)throw new Error("Invalid input type.")},Kn=(t,e)=>{Yn(t.inputs),t.compute($n("ArgMin",{hint:e.cacheKey,inputDependencies:["rank"]},[t.inputs[0]],((t,n,i)=>{let r=[];for(let e=0;e<t.rank;e++)(i.indexOf(e)>=0||0===i.length)&&r.push(`input_indices[${e}] = 0;`);return[`${r.join("\n")}`,`var value = ${t.getByIndices("input_indices")};\nvar best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?"<=":"<"} value) {\n value = ${t.getByIndices("input_indices")};\n best_index = i32(last_index);\n }`,"",n.setByOffset("global_idx","best_index")]}),[e.axis],7,e.keepDims),{inputs:[0]})},Xn=(t,e)=>{Yn(t.inputs),t.compute($n("argMax",{hint:e.cacheKey,inputDependencies:["rank"]},[t.inputs[0]],((t,n,i)=>{let r=[];for(let e=0;e<t.rank;e++)(i.indexOf(e)>=0||0===i.length)&&r.push(`input_indices[${e}] = 0;`);return[`${r.join("\n")}`,`var value = ${t.getByIndices("input_indices")};\nvar best_index : i32 = 0;`,`if (${t.getByIndices("input_indices")} ${e.selectLastIndex>0?">=":">"} value) {\n value = ${t.getByIndices("input_indices")};\n best_index = i32(last_index);\n }`,"",n.setByOffset("global_idx","best_index")]}),[e.axis],7,e.keepDims),{inputs:[0]})},Qn=t=>xe(t)})),Tu=V((()=>{gu(),ku(),Eu(),Zn=(t,e)=>{let n=t[0],i=t[1],r=t[2],s=t[3],o=t[4],a=t[5];if(o&&a)throw new Error("Attention cannot have both past and relative_position_bias");if(3!==n.dims.length)throw new Error('Input "input" must have 3 dimensions');let u=n.dims[0],h=n.dims[1],l=n.dims[2];if(1!==r.dims.length)throw new Error('Input "bias" is expected to have 1 dimensions');if(2!==i.dims.length)throw new Error('Input "weights" is expected to have 2 dimensions');if(i.dims[0]!==l)throw new Error("Input 1 dimension 0 should have same length as dimension 2 of input 0");if(r.dims[0]!==i.dims[1])throw new Error('Input "bias" dimension 0 should have same length as dimension 1 of input "weights"');let c=r.dims[0]/3,f=c,d=f;if(e.qkvHiddenSizes.length>0){if(3!==e.qkvHiddenSizes.length)throw new Error("qkv_hidden_sizes attribute should have 3 elements");for(let t of e.qkvHiddenSizes)if(t%e.numHeads!=0)throw new Error("qkv_hidden_sizes should be divisible by num_heads");c=e.qkvHiddenSizes[0],f=e.qkvHiddenSizes[1],d=e.qkvHiddenSizes[2]}let p=h;if(c!==f)throw new Error("qkv_hidden_sizes first element should be same as the second");if(r.dims[0]!==c+f+d)throw new Error('Input "bias" dimension 0 should have same length as sum of Q/K/V hidden sizes');let v=0;if(o){if(f!==d)throw new Error('Input "past" expect k_hidden_size == v_hidden_size');if(5!==o.dims.length)throw new Error('Input "past" must have 5 dimensions');if(2!==o.dims[0])throw new Error('Input "past" first dimension must be 2');if(o.dims[1]!==u)throw new Error('Input "past" second dimension must be batch_size');if(o.dims[2]!==e.numHeads)throw new Error('Input "past" third dimension must be num_heads');if(o.dims[4]!==f/e.numHeads)throw new Error('Input "past" fifth dimension must be k_hidden_size / num_heads');e.pastPresentShareBuffer||(v=o.dims[3])}let m=p+v;if(s)throw new Error("Mask not supported");if(o)throw new Error("past is not supported");return{batchSize:u,sequenceLength:h,pastSequenceLength:v,kvSequenceLength:p,totalSequenceLength:m,maxSequenceLength:-1,inputHiddenSize:l,hiddenSize:c,vHiddenSize:d,headSize:Math.floor(c/e.numHeads),vHeadSize:Math.floor(d/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:0,scale:e.scale,broadcastResPosBias:!1,passPastInKv:!1,qkvFormat:1}},Jn=(t,e,n,i)=>{let r=Fe(i),s=64,o=i/r;o<s?s=1:o/8<64&&(s=Math.ceil(o/8));let a=Math.ceil(i/r/s),u=[{type:e.dataType,data:1/i},{type:12,data:o},{type:12,data:a}],h=Te(e.dataType,r),l=ze(1,r);return{name:"AttentionProbsSoftmax",shaderCache:{hint:`${s};${h};${r}`},getShaderSource:t=>{let n=Be("x",e.dataType,e.dims,r),i=[{name:"d_inv",type:ze(e.dataType)},{name:"d_comp",type:"u32"},{name:"elements_per_thread",type:"u32"}];return`\n var<workgroup> thread_max: array<f32, ${s}>;\n var<workgroup> thread_sum: array<f32, ${s}>;\n ${t.registerUniforms(i).declareVariables(n)}\n ${t.mainStart([s,1,1])}\n let local_offset = local_idx * uniforms.elements_per_thread;\n let offset = workgroup_id.x * uniforms.d_comp + local_offset;\n\n var thread_max_vector = ${l}(-3.402823e+38f);\n for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < uniforms.d_comp; i++) {\n thread_max_vector = max(${l}(x[offset + i]), thread_max_vector);\n }\n thread_max[local_idx] = ${(()=>{switch(r){case 1:return"thread_max_vector";case 2:return"max(thread_max_vector.x, thread_max_vector.y)";case 4:return"max(max(thread_max_vector.x, thread_max_vector.y), max(thread_max_vector.z, thread_max_vector.w))";default:throw new Error(`Unsupported components: ${r}`)}})()};\n workgroupBarrier();\n\n var max_value = f32(-3.402823e+38f);\n for (var i = 0u; i < ${s}; i++) {\n max_value = max(thread_max[i], max_value);\n }\n\n var sum_vector = ${l}(0);\n for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < uniforms.d_comp; i++) {\n sum_vector += exp(${l}(x[offset + i]) - max_value);\n }\n thread_sum[local_idx] = ${(()=>{switch(r){case 1:return"sum_vector";case 2:return"sum_vector.x + sum_vector.y";case 4:return"sum_vector.x + sum_vector.y + sum_vector.z + sum_vector.w";default:throw new Error(`Unsupported components: ${r}`)}})()};\n workgroupBarrier();\n\n var sum: f32 = 0;\n for (var i = 0u; i < ${s}; i++) {\n sum += thread_sum[i];\n }\n\n if (sum == 0) {\n for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < uniforms.d_comp; i++) {\n x[offset + i] = ${n.type.value}(uniforms.d_inv);\n }\n } else {\n for (var i: u32 = 0; i < uniforms.elements_per_thread && i + local_offset < uniforms.d_comp; i++) {\n var f32input = ${l}(x[offset + i]);\n x[offset + i] = ${n.type.value}(exp(f32input - max_value) / sum);\n }\n }\n }`},getRunData:()=>({outputs:[],dispatchGroup:{x:n},programUniforms:u})}},ti=(t,e,n,i,r,s,o,a)=>{let u=a+s.kvSequenceLength,h=[s.batchSize,s.numHeads,s.sequenceLength,u],l=void 0===s.kvNumHeads&&t.outputCount>1,c=l?[s.batchSize,s.numHeads,u,s.headSize]:void 0,f=0===o.scale?1/Math.sqrt(s.headSize):o.scale,d=Fe(s.headSize),p=s.headSize/d,v={x:Math.ceil(u/12),y:Math.ceil(s.sequenceLength/12),z:s.batchSize*s.numHeads},m=[{type:12,data:s.sequenceLength},{type:12,data:p},{type:12,data:u},{type:12,data:s.numHeads},{type:1,data:f},{type:12,data:a},{type:12,data:s.kvSequenceLength}],y=["type","type"];i&&y.push("type"),r&&y.push("type");let w=[{dims:h,dataType:e.dataType,gpuDataType:0}];return l&&w.push({dims:c,dataType:e.dataType,gpuDataType:0}),{name:"AttentionProbs",shaderCache:{hint:`${d};${void 0!==r};${void 0!==i};${t.outputCount}`,inputDependencies:y},getRunData:()=>({outputs:w,dispatchGroup:v,programUniforms:m}),getShaderSource:t=>{let s=je("q",e.dataType,e.dims,d),o=[s,je("key",n.dataType,n.dims,d)];if(i){let t=je("past_key",i.dataType,i.dims,d);o.push(t)}r&&o.push(je("relative_position_bias",r.dataType,r.dims));let a=Be("output",e.dataType,h),u=[a];l&&u.push(Be("present_key",e.dataType,c,d));let f=ze(1,d);return`\n const TILE_SIZE = 12u;\n\n var<workgroup> tileQ: array<${s.type.storage}, 144>;\n var<workgroup> tileK: array<${s.type.storage}, 144>;\n ${t.registerUniforms([{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"alpha",type:"f32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"}]).declareVariables(...o,...u)}\n ${t.mainStart([12,12,1])}\n // x holds the N and y holds the M\n let headIdx = workgroup_id.z;\n let m = workgroup_id.y * TILE_SIZE;\n let n = workgroup_id.x * TILE_SIZE;\n let qOffset = uniforms.M * uniforms.K * headIdx + m * uniforms.K;\n ${i&&l?"\n let kOffset = uniforms.kv_sequence_length * uniforms.K * headIdx;\n let pastKeyOffset = uniforms.past_sequence_length * uniforms.K * headIdx;":"\n let kOffset = uniforms.N * uniforms.K * headIdx + n * uniforms.K;"}\n ${l?"let presentKeyOffset = headIdx * uniforms.N * uniforms.K;":""}\n var value = ${f}(0);\n for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {\n if (global_id.y < uniforms.M && w + local_id.x < uniforms.K) {\n tileQ[TILE_SIZE * local_id.y + local_id.x] = q[qOffset + local_id.y * uniforms.K + w + local_id.x];\n }\n if (n + local_id.y < uniforms.N && w + local_id.x < uniforms.K) {\n var idx = TILE_SIZE * local_id.y + local_id.x;\n ${i&&l?"\n if (n + local_id.y < uniforms.past_sequence_length) {\n tileK[idx] = past_key[pastKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x];\n } else {\n tileK[idx] =\n key[kOffset + (n + local_id.y - uniforms.past_sequence_length) * uniforms.K + w + local_id.x];\n }":"tileK[idx] = key[kOffset + local_id.y * uniforms.K + w + local_id.x];"}\n ${l?"present_key[presentKeyOffset + (n + local_id.y) * uniforms.K + w + local_id.x] = tileK[idx];":""}\n }\n workgroupBarrier();\n\n for (var k: u32 = 0u; k < TILE_SIZE && w+k < uniforms.K; k++) {\n value += ${f}(tileQ[TILE_SIZE * local_id.y + k] * tileK[TILE_SIZE * local_id.x + k]);\n }\n\n workgroupBarrier();\n }\n\n let headOffset = headIdx * uniforms.M * uniforms.N;\n if (global_id.y < uniforms.M && global_id.x < uniforms.N) {\n let outputIdx = headOffset + global_id.y * uniforms.N + global_id.x;\n var sum: f32 = ${(()=>{switch(d){case 1:return"value";case 2:return"value.x + value.y";case 4:return"value.x + value.y + value.z + value.w";default:throw new Error(`Unsupported components: ${d}`)}})()};\n output[outputIdx] = ${a.type.value} (sum * uniforms.alpha) + ${r?"relative_position_bias[outputIdx]":"0.0"};\n }\n }`}}},ei=(t,e,n,i,r,s)=>{let o=s+r.kvSequenceLength,a=r.nReps?r.nReps:1,u=r.vHiddenSize*a,h=null==r.kvNumHeads&&t.outputCount>1,l=h?[r.batchSize,r.numHeads,o,r.headSize]:void 0,c=[r.batchSize,r.sequenceLength,u],f={x:Math.ceil(r.vHeadSize/12),y:Math.ceil(r.sequenceLength/12),z:r.batchSize*r.numHeads},d=[{type:12,data:r.sequenceLength},{type:12,data:o},{type:12,data:r.vHeadSize},{type:12,data:r.numHeads},{type:12,data:u},{type:12,data:s},{type:12,data:r.kvSequenceLength}],p=i?["type","type","type"]:["type","type"],v=[{dims:c,dataType:e.dataType,gpuDataType:0}];return h&&v.push({dims:l,dataType:e.dataType,gpuDataType:0}),{name:"AttentionScore",shaderCache:{hint:`${void 0!==i};${t.outputCount}`,inputDependencies:p},getRunData:()=>({outputs:v,dispatchGroup:f,programUniforms:d}),getShaderSource:t=>{let r=je("probs",e.dataType,e.dims),s=[r,je("v",n.dataType,n.dims)];i&&s.push(je("past_value",i.dataType,i.dims));let o=[Be("output",e.dataType,c)];return h&&o.push(Be("present_value",e.dataType,l)),`\n const TILE_SIZE = 12u;\n var<workgroup> tileQ: array<${r.type.value}, 144>;\n var<workgroup> tileK: array<${r.type.value}, 144>;\n ${t.registerUniforms([{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"v_hidden_size",type:"u32"},{name:"past_sequence_length",type:"u32"},{name:"kv_sequence_length",type:"u32"}]).declareVariables(...s,...o)}\n ${t.mainStart([12,12,1])}\n let headIdx = workgroup_id.z;\n let m = global_id.y;\n let n = global_id.x;\n\n let offsetA = headIdx * (uniforms.M * uniforms.K) + m * uniforms.K;\n ${i&&h?"\n let pastValueOffset = headIdx * uniforms.N * uniforms.past_sequence_length + n;\n let vOffset = headIdx * uniforms.N * uniforms.kv_sequence_length + n;\n ":"\n let offsetB = headIdx * uniforms.N * uniforms.K + n;\n "}\n ${h?"let presentValueOffset = headIdx * uniforms.N * uniforms.K + n;":""}\n var value = ${r.type.storage}(0);\n for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {\n if (m < uniforms.M && w + local_id.x < uniforms.K) {\n tileQ[TILE_SIZE * local_id.y + local_id.x] = probs[offsetA + w + local_id.x];\n }\n if (n < uniforms.N && w + local_id.y < uniforms.K) {\n var idx = TILE_SIZE * local_id.y + local_id.x;\n ${i&&h?"\n if (w + local_id.y < uniforms.past_sequence_length) {\n tileK[idx] = past_value[pastValueOffset + (w + local_id.y) * uniforms.N];\n } else {\n tileK[idx] = v[vOffset + (w + local_id.y - uniforms.past_sequence_length) * uniforms.N];\n }\n ":"\n tileK[idx] = v[offsetB + (w + local_id.y) * uniforms.N];\n "}\n ${h?"present_value[presentValueOffset + (w + local_id.y) * uniforms.N] = tileK[idx];":""}\n }\n workgroupBarrier();\n for (var k: u32 = 0u; k < TILE_SIZE && w+k < uniforms.K; k++) {\n value += tileQ[TILE_SIZE * local_id.y + k] * tileK[TILE_SIZE * k + local_id.x];\n }\n workgroupBarrier();\n }\n\n // we need to transpose output from BNSH_v to BSND_v\n let batchIdx = workgroup_id.z / uniforms.num_heads;\n let currentBatchHeadNumber = workgroup_id.z % uniforms.num_heads;\n if (m < uniforms.M && n < uniforms.N) {\n let outputIdx = batchIdx * uniforms.M * uniforms.v_hidden_size + m * uniforms.v_hidden_size\n + currentBatchHeadNumber * uniforms.N + n;\n output[outputIdx] = value;\n }\n }`}}},ni=(t,e,n,i,r,s,o,a,u,h,l)=>{let c=t.outputCount,f=void 0!==h.kvNumHeads||c>1?h.pastSequenceLength:0,d=f+h.kvSequenceLength,p=void 0===h.kvNumHeads&&c>1&&o?[e,n,o]:[e,n];u&&p.push(u);let v=t.compute(ti(t,e,n,c>1?o:void 0,u,h,l,f),{inputs:p,outputs:void 0===h.kvNumHeads&&c>1?[-1,1]:[-1]})[0];t.compute(Jn(0,v,h.batchSize*h.numHeads*h.sequenceLength,d),{inputs:[v],outputs:[]});let m=void 0===h.kvNumHeads&&c>1&&a?[v,i,a]:[v,i];t.compute(ei(t,v,i,c>1&&a?a:void 0,h,f),{inputs:m,outputs:void 0===h.kvNumHeads&&c>1?[0,2]:[0]})},ii=(t,e)=>{let n=[e.batchSize,e.numHeads,e.sequenceLength,e.headSize],i=e.sequenceLength,r=e.inputHiddenSize,s=e.headSize,o={x:Math.ceil(e.headSize/12),y:Math.ceil(e.sequenceLength/12),z:e.batchSize*e.numHeads},a=[t.inputs[0],t.inputs[1],t.inputs[2]],u=[{type:12,data:i},{type:12,data:r},{type:12,data:s},{type:12,data:e.numHeads},{type:12,data:e.headSize},{type:12,data:e.hiddenSize},{type:12,data:e.hiddenSize+e.hiddenSize+e.vHiddenSize}];return t.compute({name:"AttentionPrepare",shaderCache:{inputDependencies:["type","type","type"]},getRunData:()=>({outputs:[{dims:n,dataType:t.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:t.inputs[0].dataType,gpuDataType:0},{dims:n,dataType:t.inputs[0].dataType,gpuDataType:0}],dispatchGroup:o,programUniforms:u}),getShaderSource:t=>{let e=Be("output_q",a[0].dataType,n),i=Be("output_k",a[0].dataType,n),r=Be("output_v",a[0].dataType,n),s=je("input",a[0].dataType,a[0].dims),o=je("weight",a[1].dataType,a[1].dims),u=je("bias",a[2].dataType,a[2].dims),h=s.type.storage;return`\n const TILE_SIZE = 12u;\n var<workgroup> tileInput: array<${h}, 144>;\n var<workgroup> tileWeightQ: array<${h}, 144>;\n var<workgroup> tileWeightK: array<${h}, 144>;\n var<workgroup> tileWeightV: array<${h}, 144>;\n ${t.registerUniforms([{name:"M",type:"u32"},{name:"K",type:"u32"},{name:"N",type:"u32"},{name:"num_heads",type:"u32"},{name:"head_size",type:"u32"},{name:"hidden_size",type:"u32"},{name:"ldb",type:"u32"}]).declareVariables(s,o,u,e,i,r)}\n ${t.mainStart([12,12,1])}\n let batchIndex = workgroup_id.z / uniforms.num_heads;\n let headNumber = workgroup_id.z % uniforms.num_heads;\n let m = global_id.y;\n let n = global_id.x;\n\n let inputOffset = batchIndex * (uniforms.M * uniforms.K) + m * uniforms.K;\n let biasOffsetQ = headNumber * uniforms.head_size;\n let biasOffsetK = uniforms.hidden_size + biasOffsetQ;\n let biasOffsetV = uniforms.hidden_size + biasOffsetK;\n\n var valueQ = ${h}(0);\n var valueK = ${h}(0);\n var valueV = ${h}(0);\n for (var w: u32 = 0u; w < uniforms.K; w += TILE_SIZE) {\n if (m < uniforms.M && w + local_id.x < uniforms.K) {\n tileInput[TILE_SIZE * local_id.y + local_id.x] = input[inputOffset + w + local_id.x];\n }\n if (n < uniforms.N && w + local_id.y < uniforms.K) {\n let offset = n + (w + local_id.y) * uniforms.ldb;\n tileWeightQ[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetQ + offset];\n tileWeightK[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetK + offset];\n tileWeightV[TILE_SIZE * local_id.y + local_id.x] = weight[biasOffsetV + offset];\n }\n workgroupBarrier();\n for (var k: u32 = 0u; k<TILE_SIZE && w+k < uniforms.K; k++) {\n let inputTileOffset = TILE_SIZE * local_id.y + k;\n let weightTileOffset = TILE_SIZE * k + local_id.x;\n valueQ += tileInput[inputTileOffset] * tileWeightQ[weightTileOffset];\n valueK += tileInput[inputTileOffset] * tileWeightK[weightTileOffset];\n valueV += tileInput[inputTileOffset] * tileWeightV[weightTileOffset];\n }\n\n workgroupBarrier();\n }\n\n let headOffset = (m * uniforms.N + n) % uniforms.head_size;\n valueQ += bias[headOffset + biasOffsetQ];\n valueK += bias[headOffset + biasOffsetK];\n valueV += bias[headOffset + biasOffsetV];\n\n let offset = workgroup_id.z * uniforms.M * uniforms.N;\n if (m < uniforms.M && n < uniforms.N) {\n let outputIdx = offset + m * uniforms.N + n;\n output_q[outputIdx] = valueQ;\n output_k[outputIdx] = valueK;\n output_v[outputIdx] = valueV;\n }\n }`}},{inputs:a,outputs:[-1,-1,-1]})},ri=(t,e)=>{let n=Zn(t.inputs,e),[i,r,s]=ii(t,n);return ni(t,i,r,s,t.inputs[4],void 0,void 0,void 0,t.inputs[5],n,e)}})),zu=V((()=>{mt(),gu(),Mu(),Su(),Eu(),si=(t,e)=>{if(!t||5!==t.length)throw new Error("BatchNormalization requires 5 inputs");let n=(t,e,n)=>{let i=e.length;if(i!==t.length)throw new Error(`${n}: num dimensions != ${i}`);e.forEach(((e,i)=>{if(e!==t[i])throw new Error(`${n}: dim[${i}] do not match`)}))};if(t[0].dims.length>1){let i="NHWC"===e.format?e.spatial?t[0].dims.slice(-1):t[0].dims.slice(-1).concat(t[0].dims.slice(1,t[0].dims.length-1)):t[0].dims.slice(1,e.spatial?2:void 0);n(t[1].dims,i,"Invalid input scale"),n(t[2].dims,i,"Invalid input B"),n(t[3].dims,i,"Invalid input mean"),n(t[4].dims,i,"Invalid input var")}else n(t[1].dims,[1],"Invalid input scale"),n(t[2].dims,[1],"Invalid input B"),n(t[3].dims,[1],"Invalid input mean"),n(t[4].dims,[1],"Invalid input var")},oi=(t,e)=>{let{epsilon:n,spatial:i,format:r}=e,s=t[0].dims,o=i?Fe(s[s.length-1]):1,a="NHWC"===r&&s.length>1?o:1,u=Se.size(s)/o,h=i,l=h?s.length:s,c=je("x",t[0].dataType,t[0].dims,o),f=je("scale",t[1].dataType,t[1].dims,a),d=je("bias",t[2].dataType,t[2].dims,a),p=je("inputMean",t[3].dataType,t[3].dims,a),v=je("inputVar",t[4].dataType,t[4].dims,a),m=Be("y",t[0].dataType,l,o);return{name:"BatchNormalization",shaderCache:{hint:`${e.epsilon}_${e.format}_${i}_${o}`,inputDependencies:h?["rank","type","type","type","type"]:void 0},getShaderSource:t=>`\n const epsilon = ${n};\n ${t.registerUniform("outputSize","u32").declareVariables(c,f,d,p,v,m)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n var outputIndices = ${m.offsetToIndices(`global_idx * ${o}`)};\n ${(()=>{let t="";if(i)t=`let cOffset = ${1===s.length?"0u":"NHWC"===r?`outputIndices[${s.length-1}] / ${o}`:"outputIndices[1]"};`;else if("NCHW"===r)t=`\n ${m.indicesSet("outputIndices","0","0")}\n let cOffset = ${m.indicesToOffset("outputIndices")};`;else{t=`var cIndices = ${f.type.indices}(0);\n cIndices[0] = outputIndices[${s.length-1}];`;for(let e=1;e<f.rank;e++)t+=`cIndices[${e}] = outputIndices[${e}];`;t+=`let cOffset = ${f.indicesToOffset("cIndices")};`}return t})()}\n let scale = ${f.getByOffset("cOffset")};\n let bias = ${d.getByOffset("cOffset")};\n let inputMean = ${p.getByOffset("cOffset")};\n let inputVar = ${v.getByOffset("cOffset")};\n let x = ${c.getByOffset("global_idx")};\n let value = (x - inputMean) * inverseSqrt(inputVar + epsilon) * scale + bias;\n ${m.setByOffset("global_idx","value")}\n }`,getRunData:()=>({outputs:[{dims:t[0].dims,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:h?[{type:12,data:u},...Re(s)]:[{type:12,data:u}]})}},ai=t=>xe(t),ui=(t,e)=>{let{inputs:n,outputCount:i}=t,r=ai({...e,outputCount:i});if(y.webgpu.validateInputContent&&si(n,r),e.trainingMode)throw new Error("BatchNormalization trainingMode is not supported yet.");t.compute(oi(n,r))}})),Ru=V((()=>{Mu(),Eu(),hi=t=>{if(3!==t[0].dims.length)throw new Error("input should have 3 dimensions");if(![320,640,1280].includes(t[0].dims[2]))throw new Error("number of channels should be 320, 640 or 1280");if(1!==t[1].dims.length)throw new Error("bias is expected to have 1 dimensions");if(t[0].dims[2]!==t[1].dims[0])throw new Error("last dimension of input and bias are not the same")},li=t=>{let e=t[0].dims,n=t[0].dims[2],i=Se.size(e)/4,r=t[0].dataType,s=je("input",r,e,4),o=je("bias",r,[n],4),a=je("residual",r,e,4),u=Be("output",r,e,4);return{name:"BiasAdd",getRunData:()=>({outputs:[{dims:e,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(i/64)}}),getShaderSource:t=>`\n const channels = ${n}u / 4;\n ${t.declareVariables(s,o,a,u)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes(i)}\n let value = ${s.getByOffset("global_idx")}\n + ${o.getByOffset("global_idx % channels")} + ${a.getByOffset("global_idx")};\n ${u.setByOffset("global_idx","value")}\n }`}},ci=t=>{hi(t.inputs),t.compute(li(t.inputs))}})),Fu=V((()=>{gu(),Mu(),Su(),Eu(),fi=(t,e,n,i,r,s)=>{let o=Math.ceil(e/4),a="";a="string"==typeof r?`${r}(a)`:r("a");let u=je("inputData",n,[o],4),h=Be("outputData",i,[o],4);return`\n ${t.registerUniform("vec_size","u32").declareVariables(u,h)}\n\n ${s??""}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")}\n\n let a = ${u.getByOffset("global_idx")};\n ${h.setByOffset("global_idx",a)}\n }`},di=(t,e,n,i,r,s=t.dataType)=>({name:e,shaderCache:{hint:r,inputDependencies:["type"]},getShaderSource:e=>fi(e,Se.size(t.dims),t.dataType,s,n,i),getRunData:e=>({outputs:[{dims:t.dims,dataType:s}],dispatchGroup:{x:Math.ceil(Se.size(e[0].dims)/64/4)},programUniforms:[{type:12,data:Math.ceil(Se.size(t.dims)/4)}]})}),pi=t=>{t.compute(di(t.inputs[0],"Abs","abs"))},vi=t=>{t.compute(di(t.inputs[0],"Acos","acos"))},mi=t=>{t.compute(di(t.inputs[0],"Acosh","acosh"))},yi=t=>{t.compute(di(t.inputs[0],"Asin","asin"))},wi=t=>{t.compute(di(t.inputs[0],"Asinh","asinh"))},gi=t=>{t.compute(di(t.inputs[0],"Atan","atan"))},bi=t=>{t.compute(di(t.inputs[0],"Atanh","atanh"))},_i=t=>xe(t),xi=(t,e)=>{let n;switch(e.to){case 10:n="vec4<f16>";break;case 1:n="vec4<f32>";break;case 12:n="vec4<u32>";break;case 6:n="vec4<i32>";break;case 9:n="vec4<bool>";break;default:throw new RangeError(`not supported type (specified in attribute 'to' from 'Cast' operator): ${e.to}`)}t.compute(di(t.inputs[0],"Cast",n,void 0,e.cacheKey,e.to))},ki=t=>{let e=t.length>=2&&0!==t[1].data?t[1].getFloat32Array()[0]:Ce,n=t.length>=3&&0!==t[2].data?t[2].getFloat32Array()[0]:Ae;return xe({min:e,max:n})},$i=(t,e)=>{let n=1===t.inputs.length?e:ki(t.inputs),i=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"Clip",(t=>`clamp(${t}, clip_min_, clip_max_)`),`\n const clip_min_: vec4<${i}> = vec4(${i}(${n.min}));\n const clip_max_: vec4<${i}> = vec4(${i}(${n.max}));\n`,n.cacheKey),{inputs:[0]})},Si=t=>{t.compute(di(t.inputs[0],"Ceil","ceil"))},Mi=t=>{t.compute(di(t.inputs[0],"Cos","cos"))},Ei=t=>{t.compute(di(t.inputs[0],"Cosh","cosh"))},Ci=t=>xe(t),Ai=(t,e)=>{let n=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"Elu",(t=>`elu_vf32(${t})`),`\n const elu_alpha_ = ${n}(${e.alpha});\n\n fn elu_f32(a: ${n}) -> ${n} {\n return select((exp(a) - 1.0) * elu_alpha_, a, a >= 0.0);\n }\n\n fn elu_vf32(v: vec4<${n}>) -> vec4<${n}> {\n return vec4(elu_f32(v.x), elu_f32(v.y), elu_f32(v.z), elu_f32(v.w));\n }`,e.cacheKey))},Oi=(t="f32")=>`\nconst r0: ${t} = 0.3275911;\nconst r1: ${t} = 0.254829592;\nconst r2: ${t} = -0.284496736;\nconst r3: ${t} = 1.421413741;\nconst r4: ${t} = -1.453152027;\nconst r5: ${t} = 1.061405429;\n\nfn erf_vf32(v: vec4<${t}>) -> vec4<${t}> {\n let absv = abs(v);\n let x = 1.0 / (1.0 + r0 * absv);\n return sign(v) * (1.0 - ((((r5 * x + r4) * x + r3) * x + r2) * x + r1) * x * exp(-absv * absv));\n}`,Ii=t=>{let e=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"Erf",(t=>`erf_vf32(${t})`),Oi(e)))},Ti=t=>{t.compute(di(t.inputs[0],"Exp","exp"))},zi=t=>{t.compute(di(t.inputs[0],"Floor","floor"))},Ri=t=>{let e=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"Gelu",(t=>`0.5 * ${t} * (1.0 + erf_vf32(${t} * 0.7071067811865475))`),Oi(e)))},Fi=(t,e)=>{let n=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"LeakyRelu",(t=>`select(leaky_relu_alpha_ * ${t}, ${t}, ${t} >= vec4<${n}>(0.0))`),`const leaky_relu_alpha_ = ${n}(${e.alpha});`,e.cacheKey))},Pi=t=>{t.compute(di(t.inputs[0],"Not",(t=>`!${t}`)))},Di=t=>{t.compute(di(t.inputs[0],"Neg",(t=>`-${t}`)))},Ni=t=>{t.compute(di(t.inputs[0],"Reciprocal",(t=>`1.0/${t}`)))},Ui=t=>{let e=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"Relu",(t=>`select(vec4<${e}>(0.0), ${t}, ${t} > vec4<${e}>(0.0))`)))},qi=t=>{t.compute(di(t.inputs[0],"Sigmoid",(t=>`(1.0 / (1.0 + exp(-${t})))`)))},ji=t=>xe(t),Bi=(t,e)=>{let n=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"HardSigmoid",(t=>`max(vec4<${n}>(0.0), min(vec4<${n}>(1.0), ${e.alpha} * ${t} + vec4<${n}>(${e.beta})))`),void 0,e.cacheKey))},Li=t=>{t.compute(di(t.inputs[0],"Sin","sin"))},Hi=t=>{t.compute(di(t.inputs[0],"Sinh","sinh"))},Wi=t=>{t.compute(di(t.inputs[0],"Sqrt","sqrt"))},Vi=t=>{t.compute(di(t.inputs[0],"Tan","tan"))},Gi=t=>`sign(${t}) * (1 - exp(-2 * abs(${t}))) / (1 + exp(-2 * abs(${t})))`,Yi=t=>{t.compute(di(t.inputs[0],"Tanh",Gi))},Ki=(t="f32")=>`\nconst fast_gelu_a: ${t} = 0.5;\nconst fast_gelu_b: ${t} = 0.7978845608028654;\nconst fast_gelu_c: ${t} = 0.035677408136300125;\n\nfn tanh_v(v: vec4<${t}>) -> vec4<${t}> {\n return ${Gi("v")};\n}\n`,Xi=t=>`(fast_gelu_a + fast_gelu_a * tanh_v(${t} * (fast_gelu_c * ${t} * ${t} + fast_gelu_b))) * ${t}`,Qi=t=>{let e=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"FastGelu",Xi,Ki(e),void 0,t.inputs[0].dataType))},Zi=(t,e)=>{let n=ze(t.inputs[0].dataType);return t.compute(di(t.inputs[0],"ThresholdedRelu",(t=>`select(vec4<${n}>(0.0), ${t}, ${t} > thresholded_relu_alpha_)`),`const thresholded_relu_alpha_ = vec4<${n}>(${e.alpha});`,e.cacheKey)),0},Ji=t=>{t.compute(di(t.inputs[0],"Log","log"))},tr=(t,e)=>`\nconst alpha = vec4<${t}>(${e});\nconst one = ${t}(1.0);\nconst zero = ${t}(0.0);\n\nfn quick_gelu_impl(x: vec4<${t}>) -> vec4<${t}> {\n let v = x *alpha;\n var x1 : vec4<${t}>;\n for (var i = 0; i < 4; i = i + 1) {\n if (v[i] >= zero) {\n x1[i] = one / (one + exp(-v[i]));\n } else {\n x1[i] = one - one / (one + exp(v[i]));\n }\n }\n return x * x1;\n}\n`,er=t=>`quick_gelu_impl(${t})`,nr=(t,e)=>{let n=ze(t.inputs[0].dataType);t.compute(di(t.inputs[0],"QuickGelu",er,tr(n,e.alpha),e.cacheKey,t.inputs[0].dataType))}})),Pu=V((()=>{Mu(),Eu(),Fu(),ir=t=>{if(3!==t[0].dims.length)throw new Error("input should have 3 dimensions");if(![2560,5120,10240].includes(t[0].dims[2]))throw new Error("hidden state should be 2560, 5120 or 10240");if(1!==t[1].dims.length)throw new Error("bias is expected to have 1 dimensions");if(t[0].dims[2]!==t[1].dims[0])throw new Error("last dimension of input and bias are not the same")},rr=t=>{let e=t[0].dims.slice();e[2]=e[2]/2;let n=je("input",t[0].dataType,t[0].dims,4),i=je("bias",t[0].dataType,[t[0].dims[2]],4),r=Be("output",t[0].dataType,e,4),s=Se.size(e)/4,o=Te(t[0].dataType);return{name:"BiasSplitGelu",getRunData:()=>({outputs:[{dims:e,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(s/64)}}),getShaderSource:e=>`\n const M_SQRT2 = sqrt(2.0);\n const halfChannels = ${t[0].dims[2]/4/2}u;\n\n ${e.declareVariables(n,i,r)}\n\n ${Oi(o)}\n\n ${e.mainStart()}\n ${e.guardAgainstOutOfBoundsWorkgroupSizes(s)}\n let biasIdx = global_idx % halfChannels;\n let batchIndex = global_idx / halfChannels;\n let inputOffset = biasIdx + batchIndex * halfChannels * 2;\n let valueLeft = input[inputOffset] + bias[biasIdx];\n let valueRight = input[inputOffset + halfChannels] + bias[biasIdx + halfChannels];\n let geluRight = valueRight * 0.5 * (erf_vf32(valueRight / M_SQRT2) + 1);\n\n ${r.setByOffset("global_idx","valueLeft * geluRight")}\n }`}},sr=t=>{ir(t.inputs),t.compute(rr(t.inputs))}})),Du=V((()=>{gu(),Mu(),Eu(),or=(t,e,n,i,r,s,o,a,u,h,l,c)=>{let f,d;"string"==typeof a?f=d=(t,e)=>`${a}((${t}),(${e}))`:"function"==typeof a?f=d=a:(f=a.scalar,d=a.vector);let p,v=Be("outputData",l,i.length,4),m=je("aData",u,e.length,4),y=je("bData",h,n.length,4);if(r)if(s){let t=1===Se.size(e),i=1===Se.size(n),r=e.length>0&&e[e.length-1]%4==0,s=n.length>0&&n[n.length-1]%4==0;p=t||i?v.setByOffset("global_idx",d(t?`${m.type.value}(${m.getByOffset("0")}.x)`:m.getByOffset("global_idx"),i?`${y.type.value}(${y.getByOffset("0")}.x)`:y.getByOffset("global_idx"))):`\n let outputIndices = ${v.offsetToIndices("global_idx * 4u")};\n let offsetA = ${m.broadcastedIndicesToOffset("outputIndices",v)};\n let offsetB = ${y.broadcastedIndicesToOffset("outputIndices",v)};\n ${v.setByOffset("global_idx",d(o||r?m.getByOffset("offsetA / 4u"):`${m.type.value}(${m.getByOffset("offsetA / 4u")}[offsetA % 4u])`,o||s?y.getByOffset("offsetB / 4u"):`${y.type.value}(${y.getByOffset("offsetB / 4u")}[offsetB % 4u])`))}\n `}else p=v.setByOffset("global_idx",d(m.getByOffset("global_idx"),y.getByOffset("global_idx")));else{if(!s)throw new Error("no necessary to use scalar implementation for element-wise binary op implementation.");let t=(t,e,n="")=>{let i=`aData[indexA${e}][componentA${e}]`,r=`bData[indexB${e}][componentB${e}]`;return`\n let outputIndices${e} = ${v.offsetToIndices(`global_idx * 4u + ${e}u`)};\n let offsetA${e} = ${m.broadcastedIndicesToOffset(`outputIndices${e}`,v)};\n let offsetB${e} = ${y.broadcastedIndicesToOffset(`outputIndices${e}`,v)};\n let indexA${e} = offsetA${e} / 4u;\n let indexB${e} = offsetB${e} / 4u;\n let componentA${e} = offsetA${e} % 4u;\n let componentB${e} = offsetB${e} % 4u;\n ${t}[${e}] = ${n}(${f(i,r)});\n `};p=9===l?`\n var data = vec4<u32>(0);\n ${t("data",0,"u32")}\n ${t("data",1,"u32")}\n ${t("data",2,"u32")}\n ${t("data",3,"u32")}\n outputData[global_idx] = dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(data));`:`\n ${t("outputData[global_idx]",0)}\n ${t("outputData[global_idx]",1)}\n ${t("outputData[global_idx]",2)}\n ${t("outputData[global_idx]",3)}\n `}return`\n ${t.registerUniform("vec_size","u32").declareVariables(m,y,v)}\n\n ${c??""}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")}\n ${p}\n }`},ar=(t,e,n,i,r,s,o=n.dataType)=>{let a=!Se.areEqual(n.dims,i.dims),u=n.dims,h=Se.size(n.dims),l=!1,c=!1,f=[a];if(a){let t=$e.calcShape(n.dims,i.dims,!1);if(!t)throw new Error("Can't perform binary op on the given tensors");u=t,h=Se.size(u);let e=1===Se.size(n.dims),r=1===Se.size(i.dims),s=n.dims.length>0&&n.dims[n.dims.length-1]%4==0,o=i.dims.length>0&&i.dims[i.dims.length-1]%4==0;f.push(e),f.push(r),f.push(s),f.push(o);let a=1;for(let t=1;t<u.length;t++){let e=n.dims[n.dims.length-t]??1;if(e!==(i.dims[i.dims.length-t]??1))break;a*=e}a%4==0?(c=!0,l=!0):(e||r||s||o)&&(l=!0)}else l=!0;return f.push(l),{name:t,shaderCache:{hint:e+f.map((t=>t.toString())).join("_"),inputDependencies:["rank","rank"]},getShaderSource:t=>or(t,n.dims,i.dims,u,l,a,c,r,n.dataType,i.dataType,o,s),getRunData:()=>({outputs:[{dims:u,dataType:o}],dispatchGroup:{x:Math.ceil(h/64/4)},programUniforms:[{type:12,data:Math.ceil(Se.size(u)/4)},...Re(n.dims,i.dims,u)]})}},ur=(t,e,n,i,r,s)=>{t.compute(ar(e,r??"",t.inputs[0],t.inputs[1],n,i,s))},hr=t=>{ur(t,"Add",((t,e)=>`${t}+${e}`))},lr=t=>{ur(t,"Div",((t,e)=>`${t}/${e}`))},cr=t=>{ur(t,"Equal",{scalar:(t,e)=>`u32(${t}==${e})`,vector:(t,e)=>`vec4<u32>(${t}==${e})`},void 0,void 0,9)},fr=t=>{ur(t,"Mul",((t,e)=>`${t}*${e}`))},dr=t=>{let e=je("input",t.inputs[0].dataType,t.inputs[0].dims).type.value;ur(t,"Pow",{scalar:(t,e)=>`pow_custom(${t},${e})`,vector:(t,e)=>`pow_vector_custom(${t},${e})`},`\n fn pow_custom(a : ${e}, b : ${e}) -> ${e} {\n if (b == ${e}(0.0)) {\n return ${e}(1.0);\n } else if (a < ${e}(0.0) && f32(b) != floor(f32(b))) {\n return ${e}(pow(f32(a), f32(b))); // NaN\n }\n return select(sign(a), ${e}(1.0), round(f32(abs(b) % ${e}(2.0))) != 1.0) * ${e}(${"i32"===e?"round":""}(pow(f32(abs(a)), f32(b))));\n }\n fn pow_vector_custom(a : vec4<${e}>, b : vec4<${e}>) -> vec4<${e}> {\n // TODO: implement vectorized pow\n return vec4<${e}>(pow_custom(a.x, b.x), pow_custom(a.y, b.y), pow_custom(a.z, b.z), pow_custom(a.w, b.w));\n }\n `)},pr=t=>{ur(t,"Sub",((t,e)=>`${t}-${e}`))},vr=t=>{ur(t,"Greater",{scalar:(t,e)=>`u32(${t}>${e})`,vector:(t,e)=>`vec4<u32>(${t}>${e})`},void 0,void 0,9)},mr=t=>{ur(t,"Less",{scalar:(t,e)=>`u32(${t}<${e})`,vector:(t,e)=>`vec4<u32>(${t}<${e})`},void 0,void 0,9)},yr=t=>{ur(t,"GreaterOrEqual",{scalar:(t,e)=>`u32(${t}>=${e})`,vector:(t,e)=>`vec4<u32>(${t}>=${e})`},void 0,void 0,9)},wr=t=>{ur(t,"LessOrEqual",{scalar:(t,e)=>`u32(${t}<=${e})`,vector:(t,e)=>`vec4<u32>(${t}<=${e})`},void 0,void 0,9)}})),Nu=V((()=>{gu(),Mu(),Su(),Eu(),gr=(t,e)=>{if(!t||t.length<1)throw new Error("too few inputs");let n=t[0],i=n.dataType,r=n.dims.length;t.forEach(((t,s)=>{if(0!==s){if(t.dataType!==i)throw new Error("input tensors should be one type");if(t.dims.length!==r)throw new Error("input tensors should have the same shape");t.dims.forEach(((t,i)=>{if(i!==e&&t!==n.dims[i])throw new Error("non concat dimensions must match")}))}}))},br=(t,e)=>`\n fn calculateInputIndex(index: u32) -> u32 {\n let sizeInConcatAxis = array<u32, ${t}u>(${e});\n for (var i: u32 = 0u; i < ${t}; i += 1u ) {\n if (index < sizeInConcatAxis[i]) {\n return i;\n }\n }\n return ${t}u;\n }`,_r=(t,e)=>{let n=t.length,i=[];for(let r=0;r<n;++r){let s=e.setByOffset("global_idx",t[r].getByIndices("indices"));1===n?i.push(s):0===r?i.push(`if (inputIndex == ${r}u) { ${s} }`):r===n-1?i.push(`else { ${s} }`):i.push(`else if (inputIndex == ${r}) { ${s} }`)}return i.join("\n")},xr=(t,e,n,i)=>{let r=Se.size(n),s=new Array(t.length),o=new Array(t.length),a=0,u=[],h=[],l=[{type:12,data:r}];for(let n=0;n<t.length;++n)a+=t[n].dims[e],s[n]=a,h.push(t[n].dims.length),o[n]=je(`input${n}`,i,h[n]),u.push("rank"),l.push({type:12,data:s[n]});for(let e=0;e<t.length;++e)l.push(...Re(t[e].dims));l.push(...Re(n));let c=Be("output",i,n.length),f=c.indicesGet("indices",e),d=Array.from(Array(s.length).keys()).map((t=>`uniforms.sizeInConcatAxis${t}`)).join(",");return{name:"Concat",shaderCache:{hint:`${e}`,inputDependencies:u},getRunData:()=>({outputs:[{dims:n,dataType:i}],dispatchGroup:{x:Math.ceil(r/64)},programUniforms:l}),getShaderSource:e=>`\n\n ${(()=>{e.registerUniform("outputSize","u32");for(let n=0;n<t.length;n++)e.registerUniform(`sizeInConcatAxis${n}`,"u32");return e.declareVariables(...o,c)})()}\n\n ${br(s.length,d)}\n\n ${e.mainStart()}\n ${e.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n\n var indices = ${c.offsetToIndices("global_idx")};\n\n let inputIndex = calculateInputIndex(${f});\n if (inputIndex != 0u) {\n let sizeInConcatAxis = array<u32, ${s.length}u>(${d});\n ${f} -= sizeInConcatAxis[inputIndex - 1u];\n }\n\n ${_r(o,c)}\n }`}},kr=(t,e)=>{let n=t.inputs,i=n[0].dims,r=Se.normalizeAxis(e.axis,i.length);gr(n,r);let s=i.slice();s[r]=n.reduce(((t,e)=>t+(e.dims.length>r?e.dims[r]:0)),0);let o=n.filter((t=>Se.size(t.dims)>0));t.compute(xr(o,r,s,n[0].dataType),{inputs:o})},$r=t=>xe({axis:t.axis})})),Uu=V((()=>{gu(),Mu(),Sr=(t,e,n="f32")=>{switch(t.activation){case"Relu":return`value = max(value, ${e}(0.0));`;case"Sigmoid":return`value = (${e}(1.0) / (${e}(1.0) + exp(-value)));`;case"Clip":return`value = clamp(value, ${e}(${n}(uniforms.clip_min)), ${e}(${n}(uniforms.clip_max)));`;case"HardSigmoid":return`value = max(${e}(0.0), min(${e}(1.0), ${n}(uniforms.alpha) * value + ${n}(uniforms.beta)));`;case"LeakyRelu":return`value = select(${n}(uniforms.alpha) * value, value, value >= ${e}(0.0));`;case"Tanh":return"let e2x = exp(-2.0 * abs(value));\n value = sign(value) * (1.0 - e2x) / (1.0 + e2x);\n ";case"":return"";default:throw new Error(`Unsupported activation ${t.activation}`)}},Mr=(t,e)=>{"Clip"===t.activation?e.push({type:1,data:t.clipMax},{type:1,data:t.clipMin}):"HardSigmoid"===t.activation?e.push({type:1,data:t.alpha},{type:1,data:t.beta}):"LeakyRelu"===t.activation&&e.push({type:1,data:t.alpha})},Er=(t,e)=>{"Clip"===t.activation?e.push({name:"clip_max",type:"f32"},{name:"clip_min",type:"f32"}):"HardSigmoid"===t.activation?e.push({name:"alpha",type:"f32"},{name:"beta",type:"f32"}):"LeakyRelu"===t.activation&&e.push({name:"alpha",type:"f32"})},Cr=t=>{let e=t?.activation||"";if("HardSigmoid"===e){let[n,i]=t?.activation_params||[.2,.5];return{activation:e,alpha:n,beta:i}}if("Clip"===e){let[n,i]=t?.activation_params||[Ce,Ae];return{activation:e,clipMax:i,clipMin:n}}if("LeakyRelu"===e){let[n]=t?.activation_params||[.01];return{activation:e,alpha:n}}return{activation:e}}})),qu=V((()=>{Ar=(t,e)=>{switch(t){case 1:return e;case 2:return`vec2<${e}>`;case 3:return`vec3<${e}>`;case 4:return`vec4<${e}>`;default:throw new Error(`${t}-component is not supported.`)}},Or=t=>`\n ${t?"value = value + getBiasByOutputCoords(coords);":""}\n `})),ju=V((()=>{Ir=t=>`\nfn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));\n}\nfn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {\n return dot(coords, vec4<i32>(\n i32(${t}.x), i32(${t}.y), i32(${t}.z), 1));\n}\n`})),Bu=V((()=>{gu(),Mu(),Eu(),Uu(),qu(),Tr=(t,e)=>t?`\n mm_Asub[inputRow][inputCol] = mm_readA(batch,\n kStart + inputRow,\n globalRowStart / innerElementSize + inputCol${e?", batchIndices":""});\n `:`\n mm_Asub[inputRow][inputCol] = mm_readA(batch,\n globalRow + innerRow,\n kStart / innerElementSize + inputCol${e?", batchIndices":""});\n `,zr=(t,e)=>t?`\n let ACached0 = mm_Asub[k * innerElementSize][localRow];\n let ACached1 = mm_Asub[k * innerElementSize + 1][localRow];\n let ACached2 = mm_Asub[k * innerElementSize + 2][localRow];\n ${3===e?"":"let ACached3 = mm_Asub[k * innerElementSize + 3][localRow];"}\n for (var i = 0; i < rowPerThread; i = i + 1) {\n acc[i] = BCached0 * ACached0[i] + acc[i];\n acc[i] = BCached1 * ACached1[i] + acc[i];\n acc[i] = BCached2 * ACached2[i] + acc[i];\n ${3===e?"":"acc[i] = BCached3 * ACached3[i] + acc[i];"}\n }`:`\n for (var i = 0; i < rowPerThread; i = i + 1) {\n let ACached = mm_Asub[tileRow + i][k];\n acc[i] = BCached0 * ACached.x + acc[i];\n acc[i] = BCached1 * ACached.y + acc[i];\n acc[i] = BCached2 * ACached.z + acc[i];\n ${3===e?"":"acc[i] = BCached3 * ACached.w + acc[i];"}\n }`,Rr=(t,e,n="f32",i,r=!1,s=32,o=!1,a=32)=>{let u=e[1]*t[1],h=e[0]*t[0],l=r?u:s,c=r?s:u,f=l/e[0],d=s/e[1];if((!r||4!==f||4!==t[1])&&(r||3!==f&&4!==f)||l%e[0]!=0||s%e[1]!=0||4!==t[0])throw new Error(`If transposeA ${r} is true, innerElementSize ${f} and workPerThread[1] ${t[1]} must be 4.\n Otherwise, innerElementSize ${f} must be 3 or 4.\n tileAWidth ${l} must be divisible by workgroupSize[0]${e[0]}. tileInner ${s} must be divisible by workgroupSize[1] ${e[1]}. colPerThread ${t[0]} must be 4.`);return`\nvar<workgroup> mm_Asub: array<array<vec${f}<${n}>, ${l/f}>, ${c}>;\nvar<workgroup> mm_Bsub: array<array<vec4<${n}>, ${h/t[0]}>, ${s}>;\n\nconst rowPerThread = ${t[1]};\nconst colPerThread = ${t[0]};\nconst innerElementSize = ${f};\nconst tileInner = ${s};\n\n@compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]})\nfn main(@builtin(local_invocation_id) localId : vec3<u32>,\n @builtin(global_invocation_id) globalId : vec3<u32>,\n @builtin(workgroup_id) workgroupId : vec3<u32>) {\n let localRow = i32(localId.y);\n let tileRow = localRow * rowPerThread;\n let tileCol = i32(localId.x);\n\n let globalRow =i32(globalId.y) * rowPerThread;\n let globalCol = i32(globalId.x);\n let batch = ${o?"0":"i32(globalId.z)"};\n ${i?`let batchIndices = ${i.offsetToIndices("u32(batch)")};`:""}\n let globalRowStart = i32(workgroupId.y) * ${u};\n\n let num_tiles = ${o?`${Math.ceil(a/s)}`:"(uniforms.dim_inner - 1) / tileInner + 1"};\n var kStart = ${o?`i32(globalId.z) * ${a}`:"0"};\n\n var acc: array<vec4<${n}>, rowPerThread>;\n\n // Loop over shared dimension.\n let tileRowB = localRow * ${d};\n for (var t = 0; t < num_tiles; t = t + 1) {\n // Load one tile of A into local memory.\n for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n let inputRow = tileRow + innerRow;\n let inputCol = tileCol;\n ${Tr(r,i)}\n }\n\n // Load one tile of B into local memory.\n for (var innerRow = 0; innerRow < ${d}; innerRow = innerRow + 1) {\n let inputRow = tileRowB + innerRow;\n let inputCol = tileCol;\n mm_Bsub[inputRow][inputCol] = mm_readB(batch, kStart + inputRow, globalCol${i?", batchIndices":""});\n }\n kStart = kStart + tileInner;\n workgroupBarrier();\n\n // Compute acc values for a single thread.\n for (var k = 0; k < tileInner / innerElementSize; k = k + 1) {\n let BCached0 = mm_Bsub[k * innerElementSize][tileCol];\n let BCached1 = mm_Bsub[k * innerElementSize + 1][tileCol];\n let BCached2 = mm_Bsub[k * innerElementSize + 2][tileCol];\n ${3===f?"":"let BCached3 = mm_Bsub[k * innerElementSize + 3][tileCol];"}\n\n ${zr(r,f)}\n }\n\n workgroupBarrier();\n }\n\n for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n mm_write(batch, globalRow + innerRow, globalCol, acc[innerRow]);\n }\n}`},Fr=(t,e)=>t?`\n mm_Asub[inputRow][inputCol] = mm_readA(batch,\n kStart + inputRow,\n globalRowStart + inputCol${e?", batchIndices":""});\n `:`\n mm_Asub[inputRow][inputCol] = mm_readA(batch,\n globalRowStart + inputRow,\n kStart + inputCol${e?", batchIndices":""});\n `,Pr=t=>t?"let ACached = mm_Asub[k][tileRow + innerRow];":"let ACached = mm_Asub[tileRow + innerRow][k];",Dr=(t,e,n="f32",i,r=!1,s=32,o=!1,a=32,u=!1)=>{let h=t[1]*e[1],l=t[0]*e[0],c=r?h:s,f=r?s:h;if(f%e[1]!=0||c%e[0]!=0||s%e[1]!=0)throw new Error(`tileAHight ${f} must be divisible by workgroupSize[1]${e[1]}, tileAWidth ${c} must be divisible by workgroupSize[0]${e[0]}, tileInner ${s} must be divisible by workgroupSize[1]${e[1]}`);let d=f/e[1],p=c/e[0],v=s/e[1],m=u?`\n let localRow = i32(localId.y);\n let localCol = i32(localId.x);\n let globalRowStart = i32(workgroupId.y) * ${h};\n let globalColStart = i32(workgroupId.x) * ${l};\n\n // Loop over shared dimension.\n for (var t = 0; t < num_tiles; t = t + 1) {\n // Load one tile of A into local memory.\n for (var inputRow = localRow; inputRow < ${f}; inputRow = inputRow + ${e[1]}) {\n for (var inputCol = localCol; inputCol < ${c}; inputCol = inputCol + ${e[0]}) {\n ${Fr(r,i)}\n }\n }\n // Load one tile of B into local memory.\n for (var inputRow = localRow; inputRow < ${s}; inputRow = inputRow + ${e[1]}) {\n for (var inputCol = localCol; inputCol < ${l}; inputCol = inputCol + ${e[0]}) {\n mm_Bsub[inputRow][inputCol] = mm_readB(batch,\n kStart + inputRow,\n globalColStart + inputCol${i?", batchIndices":""});\n }\n }\n kStart = kStart + tileInner;\n workgroupBarrier();\n\n // Compute acc values for a single thread.\n var BCached : array<${n}, colPerThread>;\n for (var k = 0; k < tileInner; k = k + 1) {\n for (var inner = 0; inner < colPerThread; inner = inner + 1) {\n BCached[inner] = mm_Bsub[k][localCol + inner * ${e[0]}];\n }\n for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n let ACached = ${r?`mm_Asub[k][localRow + innerRow * ${e[1]}];`:`mm_Asub[localRow + innerRow * ${e[1]}][k];`}\n for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {\n acc[innerRow][innerCol] = acc[innerRow][innerCol] +\n ACached * BCached[innerCol];\n }\n }\n }\n workgroupBarrier();\n }\n for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n let gRow = globalRowStart + localRow + innerRow * ${e[1]};\n for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {\n let gCol = globalColStart + localCol + innerCol * ${e[0]};\n mm_write(batch, gRow, gCol, acc[innerRow][innerCol]);\n }\n }\n `:`\nlet tileRow = i32(localId.y) * rowPerThread;\nlet tileCol = i32(localId.x) * colPerThread;\n\nlet globalRow = i32(globalId.y) * rowPerThread;\nlet globalCol = i32(globalId.x) * colPerThread;\nlet globalRowStart = i32(workgroupId.y) * ${h};\n\nlet tileRowA = i32(localId.y) * ${d};\nlet tileColA = i32(localId.x) * ${p};\nlet tileRowB = i32(localId.y) * ${v};\n// Loop over shared dimension.\nfor (var t = 0; t < num_tiles; t = t + 1) {\n // Load one tile of A into local memory.\n for (var innerRow = 0; innerRow < ${d}; innerRow = innerRow + 1) {\n for (var innerCol = 0; innerCol < ${p}; innerCol = innerCol + 1) {\n let inputRow = tileRowA + innerRow;\n let inputCol = tileColA + innerCol;\n ${Fr(r,i)}\n }\n }\n\n // Load one tile of B into local memory.\n for (var innerRow = 0; innerRow < ${v}; innerRow = innerRow + 1) {\n for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {\n let inputRow = tileRowB + innerRow;\n let inputCol = tileCol + innerCol;\n mm_Bsub[inputRow][inputCol] = mm_readB(batch,\n kStart + inputRow,\n globalCol + innerCol${i?", batchIndices":""});\n }\n }\n kStart = kStart + tileInner;\n workgroupBarrier();\n\n // Compute acc values for a single thread.\n var BCached : array<${n}, colPerThread>;\n for (var k = 0; k < tileInner; k = k + 1) {\n for (var inner = 0; inner < colPerThread; inner = inner + 1) {\n BCached[inner] = mm_Bsub[k][tileCol + inner];\n }\n\n for (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n ${Pr(r)}\n for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {\n acc[innerRow][innerCol] = acc[innerRow][innerCol] + ACached * BCached[innerCol];\n }\n }\n }\n\n workgroupBarrier();\n}\n\nfor (var innerRow = 0; innerRow < rowPerThread; innerRow = innerRow + 1) {\n for (var innerCol = 0; innerCol < colPerThread; innerCol = innerCol + 1) {\n mm_write(batch, globalRow + innerRow, globalCol + innerCol,\n acc[innerRow][innerCol]);\n }\n}\n`;return`\n var<workgroup> mm_Asub : array<array<${n}, ${c}>, ${f}>;\n var<workgroup> mm_Bsub : array<array<${n}, ${l}>, ${s}>;\n const rowPerThread = ${t[1]};\n const colPerThread = ${t[0]};\n const tileInner = ${s};\n\n@compute @workgroup_size(${e[0]}, ${e[1]}, ${e[2]})\nfn main(@builtin(local_invocation_id) localId : vec3<u32>,\n @builtin(global_invocation_id) globalId : vec3<u32>,\n @builtin(workgroup_id) workgroupId : vec3<u32>) {\n let batch = ${o?"0":"i32(globalId.z)"};\n ${i?`let batchIndices = ${i.offsetToIndices("u32(batch)")};`:""}\n let num_tiles = ${o?`${Math.ceil(a/s)}`:"(uniforms.dim_inner - 1) / tileInner + 1"};\n var kStart = ${o?`i32(globalId.z) * ${a}`:"0"};\n\n var acc : array<array<${n}, colPerThread>, rowPerThread>;\n ${m}\n }\n`},Nr=(t,e,n,i,r,s=!1)=>{let[o,a,u]=r,[h,l,c,f]=i,d=Ve(o,u),p=Ve(a,u),v=Te(i[0].type.tensor);return`\n fn mm_readA(batch: i32, row: i32, colIn: i32, batchIndices: ${h.type.indices}) -> ${Ar(t,v)} {\n var value = ${Ar(t,v)}(0.0);\n let col = colIn * ${t};\n if(row < uniforms.dim_a_outer && col < uniforms.dim_inner)\n {\n ${(()=>{let t=l.rank,e=h.rank,n=`var aIndices: ${l.type.indices};`;for(let i=t-2-1,r=e-1;i>=0;i--,r--)n+=`\naIndices[${i}] = ${e>1?`batchIndices[${r}]`:"batchIndices"};`;return d.forEach((t=>{n+=`\naIndices[${t}] = 0;`})),n+=`\naIndices[${t-2}] = u32(row);\n aIndices[${t-1}] = u32(colIn);`,n})()}\n value = ${l.getByIndices("aIndices")};\n }\n return value;\n }\n\n fn mm_readB(batch: i32, row: i32, colIn: i32, batchIndices: ${h.type.indices}) -> ${Ar(t,v)} {\n var value = ${Ar(t,v)}(0.0);\n let col = colIn * ${t};\n if(row < uniforms.dim_inner && col < uniforms.dim_b_outer)\n {\n ${(()=>{let t=c.rank,e=h.rank,n=`var bIndices: ${c.type.indices};`;for(let i=t-2-1,r=e-1;i>=0;i--,r--)n+=`\nbIndices[${i}] = ${e>1?`batchIndices[${r}]`:"batchIndices"};`;return p.forEach((t=>{n+=`\nbIndices[${t}] = 0;`})),n+=`\nbIndices[${t-2}] = u32(row);\n bIndices[${t-1}] = u32(colIn);`,n})()}\n value = ${c.getByIndices("bIndices")};\n }\n return value;\n }\n\n fn mm_write(batch: i32, row: i32, colIn: i32, valueIn: ${Ar(t,v)}) {\n let col = colIn * ${t};\n if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) {\n var value = valueIn;\n let coords = vec3<i32>(batch, row, colIn);\n ${e?`value = value + ${s?"bias[colIn]":`${Ar(t,v)}(bias[row])`};`:""}\n ${n}\n ${f.setByIndices("vec3<u32>(coords)","value")}\n }\n }\n `},Ur=(t,e,n,i,r=!1)=>{let s=t[0].dims,o=t[1].dims,a=s.slice(0,-2),u=o.slice(0,-2),h=i?i.slice(0,-2):n.slice(0,-2),l=Se.size(h),c=s[s.length-2],f=s[s.length-1],d=o[o.length-1],p=f%4==0&&d%4==0,v=c<=8?[4,1,1]:[4,4,1],m=[8,8,1],y=[Math.ceil(d/m[0]/v[0]),Math.ceil(c/m[1]/v[1]),Math.ceil(l/m[2]/v[2])],w=p?4:1,g=[...a,c,f/w],b=g.length,_=[...u,f,d/w],x=_.length,k=[l,c,d/w],$=[{type:6,data:c},{type:6,data:d},{type:6,data:f}];Mr(e,$),$.push(...Re(h,g,_));let S=["rank","rank"],M=t.length>2;return M&&($.push(...Re(t[2].dims)),S.push("rank")),$.push(...Re(k)),{name:"MatMul",shaderCache:{hint:`${v};${e.activation};${p};${r}`,inputDependencies:S},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:y[0],y:y[1],z:y[2]},programUniforms:$}),getShaderSource:n=>{let i=h.length,s=Le("batchDims",t[0].dataType,i,1),o=Te(t[0].dataType),l=je("a",t[0].dataType,b,w),c=je("b",t[1].dataType,x,w),f=Be("result",t[0].dataType,k.length,w),d=[l,c];if(M){let e=r?w:1;d.push(je("bias",t[2].dataType,t[2].dims.length,e))}let y=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"}];Er(e,y);let g=Te(f.type.tensor),_=Sr(e,f.type.value,g),$=Nr(w,M,_,[s,l,c,f],[a,u,h],r);return`\n ${n.registerUniforms(y).registerInternalVariables(s).declareVariables(...d,f)}\n ${$}\n ${p?Rr(v,m,o,s):Dr(v,m,o,s)}\n `}}}})),Lu=V((()=>{gu(),_u(),Eu(),Uu(),qu(),ju(),Bu(),qr=(t,e,n,i,r=!1,s,o=4,a=4,u=4,h="f32")=>{let l=t?"\n let coord = vec4<i32>(batch, xRow, xCol, xCh);\n ":"\n let coord = vec4<i32>(batch, xCh, xRow, xCol);\n ",c=t?"\n let coords = vec4<i32>(\n batch,\n row / outWidth,\n row % outWidth,\n col);\n ":"\n let coords = vec4<i32>(\n batch,\n row,\n col / outWidth,\n col % outWidth);\n ",f=t?"i32(uniforms.x_shape[1])":"i32(uniforms.x_shape[2])",d=t?"i32(uniforms.x_shape[2])":"i32(uniforms.x_shape[3])",p=t?"row":"col",v=t?"col":"row",m=`\n let inChannels = i32(uniforms.w_shape[2]);\n let outWidth = ${t?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"};\n let outRow = ${p} / outWidth;\n let outCol = ${p} % outWidth;\n\n let WRow = ${v} / (i32(uniforms.w_shape[1]) * inChannels);\n let WCol = ${v} / inChannels % i32(uniforms.w_shape[1]);\n let xRow = outRow * uniforms.stride[0] + uniforms.dilation[0] * WRow - uniforms.pad[0];\n let xCol = outCol * uniforms.stride[1] + uniforms.dilation[1] * WCol - uniforms.pad[1];\n let xCh = ${v} % inChannels;\n var resData = ${Ar(o,h)}(0.0);\n // The bounds checking is always needed since we use it to pad zero for\n // the 'same' padding type.\n if (xRow >= 0 && xRow < ${f} && xCol >= 0 && xCol < ${d}) {\n ${l}\n let xIndex = getIndexFromCoords4D(coord, vec4<i32>(uniforms.x_shape));\n ${(t=>{switch(t){case 1:return"resData = x[xIndex];";case 3:return`resData = vec3<${h}>(x[xIndex], x[xIndex + 1], x[xIndex + 2]);`;case 4:return"resData = x[xIndex / 4];";default:throw new Error(`innerElementSize ${t} is not supported.`)}})(o)}\n }\n return resData;`,y=t?e&&i?`\n let col = colIn * ${o};\n ${m}`:`\n let col = colIn * ${o};\n if (row < uniforms.dim_a_outer && col < uniforms.dim_inner) {\n ${m}\n }\n return ${Ar(o,h)}(0.0);`:i&&n?`\n let col = colIn * ${o};\n ${m}`:`\n let col = colIn * ${o};\n if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) {\n ${m}\n }\n return ${Ar(o,h)}(0.0);`,w=`${(t=>{switch(t){case 1:return"return w[row * i32(uniforms.w_shape[3]) + colIn];";case 4:return"return w[row * i32(uniforms.w_shape[3]) / 4 + colIn];";default:throw new Error(`innerElementSize ${t} is not supported.`)}})(a)}`,g=Ar(u,h),b=Ar(t?o:a,h),_=Ar(t?a:o,h),x=Sr(s,g,h);return`\n fn mm_readA(batch: i32, row : i32, colIn : i32) -> ${b} {\n ${t?y:w}\n }\n\n fn mm_readB(batch: i32, row : i32, colIn : i32) -> ${_} {\n ${t?w:y}\n }\n\n fn mm_write(batch: i32, row : i32, colIn : i32, valueIn : ${g}) {\n let col = colIn * ${u};\n if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer)\n {\n var value = valueIn;\n let outWidth = ${t?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"};\n ${c}\n ${Or(r)}\n ${x}\n setOutputAtCoords(coords[0], coords[1], coords[2], coords[3], value);\n }\n }`},jr=(t,e,n,i,r,s,o,a)=>{let u="NHWC"===e.format,h=u?t[0].dims[3]:t[0].dims[1],l=n[0],c=u?n[2]:n[3],f=u?n[1]:n[2],d=u?n[3]:n[1],p=u&&(h%4==0||h%3==0)&&d%4==0,v=u?d:c*f,m=u?c*f:d,y=[8,8,1],w=i<=8?[4,1,1]:[4,4,1],g=[Math.ceil(v/y[0]/w[0]),Math.ceil(m/y[1]/w[1]),Math.ceil(l/y[2]/w[2])];le("verbose",(()=>`[conv2d_mm_webgpu] dispatch = ${g}`));let b=p?u&&h%4!=0?3:4:1,_=y[1]*w[1],x=y[0]*w[0],k=Math.max(y[0]*b,y[1]),$=i%_==0,S=r%x==0,M=s%k==0,E=p?[b,4,4]:[1,1,1],C=[{type:6,data:i},{type:6,data:r},{type:6,data:s},{type:6,data:[e.pads[0],e.pads[1]]},{type:6,data:e.strides},{type:6,data:e.dilations}];Mr(e,C),C.push(...Re(t[0].dims,t[1].dims));let A=["rank","rank"];return o&&(C.push(...Re(t[2].dims)),A.push("rank")),C.push(...Re(n)),{name:"Conv2DMatMul",shaderCache:{hint:`${e.cacheKey};${b};${p};${$};${S};${M};${_};${x};${k}`,inputDependencies:A},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:g[0],y:g[1],z:g[2]},programUniforms:C}),getShaderSource:i=>{let r=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"},{name:"pad",type:"i32",length:2},{name:"stride",type:"i32",length:2},{name:"dilation",type:"i32",length:2}];Er(e,r);let s=p?4:1,h=Te(t[0].dataType),l=`\n fn setOutputAtIndex(flatIndex : i32, value : ${p?`vec4<${h}>`:h}) {\n result[flatIndex] = ${p?`vec4<${h}>`:h}(value);\n }\n fn setOutputAtCoords(d0 : i32, d1 : i32, d2 : i32, d3 : i32, value : ${p?`vec4<${h}>`:h}) {\n let flatIndex = getOutputIndexFromCoords(vec4<i32>(d0, d1, d2, d3));\n setOutputAtIndex(flatIndex ${p?"/ 4":""}, value);\n }`,c=[je("x",t[0].dataType,t[0].dims.length,3===b?1:b),je("w",t[1].dataType,t[1].dims.length,s)],f=Be("result",t[0].dataType,n.length,s);if(o){let e=je("bias",t[2].dataType,t[2].dims.length,s);c.push(e),l+=`\n fn getBiasByOutputCoords(coords : vec4<i32>) -> ${p?`vec4<${h}>`:h} {\n return bias[coords.${u?"w":"y"}${p?"/ 4":""}];\n }`}return`\n ${Ir("uniforms.result_strides")}\n //struct Uniforms { xShape : vec4<i32>, wShape : vec4<i32>, outShape : vec4<i32>,\n // outShapeStrides: vec3<i32>, filterDims : vec2<i32>, pad : vec2<i32>, stride : vec2<i32>,\n // dilation : vec2<i32>, dimAOuter : i32, dimBOuter : i32, dimInner : i32 };\n ${i.registerUniforms(r).declareVariables(...c,f)}\n ${l}\n ${qr(u,$,S,M,o,e,E[0],E[1],E[2],h)}\n ${p?Rr(w,y,h,void 0,!u,k):Dr(w,y,h,void 0,!u,k,!1,void 0,a)}`}}}})),Hu=V((()=>{gu(),_u(),Mu(),Eu(),Uu(),qu(),Br=t=>{let e=1;for(let n=0;n<t.length;n++)e*=t[n];return e},Lr=t=>"number"==typeof t?[t,t,t]:t,Hr=(t,e)=>e<=1?t:t+(t-1)*(e-1),Wr=(t,e,n,i=1)=>{let r=Hr(e,i);return Math.floor((t[0]*(n-1)-n+r)/2)},Vr=(t,e,n,i,r)=>{null==r&&(r=Wr(t,e[0],i[0]));let s=[0,0,0,n];for(let n=0;n<3;n++)t[n]+2*r>=e[n]&&(s[n]=Math.trunc((t[n]-e[n]+2*r)/i[n]+1));return s},Gr=(t,e,n,i,r,s,o,a,u,h)=>{let l,c,f,d;if("VALID"===t&&(t=0),"number"==typeof t){l={top:t,bottom:t,left:t,right:t,front:t,back:t};let p=Vr([e,n,i,1],[a,u,h],1,[r,s,o],t);c=p[0],f=p[1],d=p[2]}else if(Array.isArray(t)){if(!t.every(((t,e,n)=>t===n[0])))throw Error(`Unsupported padding parameter: ${t}`);l={top:t[0],bottom:t[1],left:t[2],right:t[3],front:t[4],back:t[5]};let p=Vr([e,n,i,1],[a,u,h],1,[r,s,o],t[0]);c=p[0],f=p[1],d=p[2]}else{if("SAME_UPPER"!==t)throw Error(`Unknown padding parameter: ${t}`);{c=Math.ceil(e/r),f=Math.ceil(n/s),d=Math.ceil(i/o);let t=(c-1)*r+a-e,p=(f-1)*s+u-n,v=(d-1)*o+h-i,m=Math.floor(t/2),y=t-m,w=Math.floor(p/2),g=p-w,b=Math.floor(v/2);l={top:w,bottom:g,left:b,right:v-b,front:m,back:y}}}return{padInfo:l,outDepth:c,outHeight:f,outWidth:d}},Yr=(t,e,n,i,r,s=!1,o="channelsLast")=>{let a,u,h,l,c;if("channelsLast"===o)[a,u,h,l,c]=t;else{if("channelsFirst"!==o)throw new Error(`Unknown dataFormat ${o}`);[a,c,u,h,l]=t}let[f,,d,p,v]=e,[m,y,w]=Lr(n),[g,b,_]=Lr(i),x=Hr(d,g),k=Hr(p,b),$=Hr(v,_),{padInfo:S,outDepth:M,outHeight:E,outWidth:C}=Gr(r,u,h,l,m,y,w,x,k,$),A=s?f*c:f,O=[0,0,0,0,0];return"channelsFirst"===o?O=[a,A,M,E,C]:"channelsLast"===o&&(O=[a,M,E,C,A]),{batchSize:a,dataFormat:o,inDepth:u,inHeight:h,inWidth:l,inChannels:c,outDepth:M,outHeight:E,outWidth:C,outChannels:A,padInfo:S,strideDepth:m,strideHeight:y,strideWidth:w,filterDepth:d,filterHeight:p,filterWidth:v,effectiveFilterDepth:x,effectiveFilterHeight:k,effectiveFilterWidth:$,dilationDepth:g,dilationHeight:b,dilationWidth:_,inShape:t,outShape:O,filterShape:e}},Kr=(t,e,n,i,r,s)=>{let o="channelsLast"===s;o?t[0].dims[3]:t[0].dims[1];let a={x:n.map(((t,e)=>e))},u=[Math.ceil(Br(a.x.map((t=>n[t])))/64),1,1];le("verbose",(()=>`[conv3d_naive_webgpu] dispatch = ${u}`));let h=[{type:12,data:Se.size(n)},{type:12,data:i},{type:12,data:r},{type:12,data:e.strides},{type:12,data:e.dilations}];Mr(e,h),h.push(...Re(t[0].dims,t[1].dims));let l=["rank","rank"],c=3===t.length;return c&&(h.push(...Re(t[2].dims)),l.push("rank")),h.push(...Re(n)),{name:"Conv3DNaive",shaderCache:{hint:`${e.cacheKey};${o};1;${c}`,inputDependencies:l},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:u[0],y:u[1],z:u[2]},programUniforms:h}),getShaderSource:s=>{let a=[{name:"output_size",type:"u32"},{name:"filter_dims",type:"u32",length:i.length},{name:"pads",type:"u32",length:r.length},{name:"strides",type:"u32",length:e.strides.length},{name:"dilations",type:"u32",length:e.dilations.length}];Er(e,a);let u=Te(t[0].dataType),h=je("x",t[0].dataType,t[0].dims.length,1),l=je("W",t[1].dataType,t[1].dims.length,1),f=[h,l],d=Be("result",t[0].dataType,n.length,1),p="";if(c){let e=je("bias",t[2].dataType,t[2].dims.length,1);f.push(e),p+=`\n fn getBiasByOutputCoords(coords : array<u32, 5>) -> ${u} {\n return bias[${Ue("coords",o?4:1,5)}];\n }`}let v=Ar(1,u),m=Sr(e,v,u);return`\n ${p}\n fn getX(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 {\n let aIndices = array<u32, 5>(d0, d1, d2, d3, d4);\n return ${h.getByIndices("aIndices")};\n }\n fn getW(d0 : u32, d1 : u32, d2 : u32, d3 : u32, d4 : u32) -> f32 {\n let aIndices = array<u32, 5>(d0, d1, d2, d3, d4);\n return ${l.getByIndices("aIndices")};\n }\n ${s.registerUniforms(a).declareVariables(...f,d)}\n ${s.mainStart()}\n ${s.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n let coords = ${d.offsetToIndices("global_idx")};\n let batch = ${Ue("coords",0,h.rank)};\n let d2 = ${Ue("coords",o?h.rank-1:1,h.rank)};\n let xFRCCorner = vec3<u32>(${Ue("coords",o?1:2,h.rank)},\n ${Ue("coords",o?2:3,h.rank)},\n ${Ue("coords",o?3:4,h.rank)}) * uniforms.strides - uniforms.pads;\n let xFCorner = xFRCCorner.x;\n let xRCorner = xFRCCorner.y;\n let xCCorner = xFRCCorner.z;\n let xShapeY = ${Ue("uniforms.x_shape",o?1:2,h.rank)};\n let xShapeZ = ${Ue("uniforms.x_shape",o?2:3,h.rank)};\n let xShapeW = ${Ue("uniforms.x_shape",o?3:4,h.rank)};\n let xShapeU = ${Ue("uniforms.x_shape",o?4:1,h.rank)};\n let inputDepthNearestVec4 = (xShapeU / 4) * 4;\n let inputDepthVec4Remainder = xShapeU % 4;\n\n var value = 0.0;\n for (var wF = 0u; wF < uniforms.filter_dims[0]; wF++) {\n let xF = xFCorner + wF * uniforms.dilations[0];\n if (xF < 0 || xF >= xShapeY) {\n continue;\n }\n\n for (var wR = 0u; wR < uniforms.filter_dims[1]; wR++) {\n let xR = xRCorner + wR * uniforms.dilations[1];\n if (xR < 0 || xR >= xShapeZ) {\n continue;\n }\n\n for (var wC = 0u; wC < uniforms.filter_dims[2]; wC++) {\n let xC = xCCorner + wC * uniforms.dilations[2];\n if (xC < 0 || xC >= xShapeW) {\n continue;\n }\n\n for (var d1 = 0u; d1 < inputDepthNearestVec4; d1 += 4) {\n ${o?"let xValues = vec4<f32>(\n getX(batch, xF, xR, xC, d1),\n getX(batch, xF, xR, xC, d1 + 1),\n getX(batch, xF, xR, xC, d1 + 2),\n getX(batch, xF, xR, xC, d1 + 3));\n ":"let xValues = vec4<f32>(\n getX(batch, d1, xF, xR, xC),\n getX(batch, d1 + 1, xF, xR, xC),\n getX(batch, d1 + 2, xF, xR, xC),\n getX(batch, d1 + 3, xF, xR, xC));\n "}\n let wValues = vec4<f32>(\n getW(d2, d1, wF, wR, wC),\n getW(d2, d1 + 1, wF, wR, wC),\n getW(d2, d1 + 2, wF, wR, wC),\n getW(d2, d1 + 3, wF, wR, wC));\n value += dot(xValues, wValues);\n }\n if (inputDepthVec4Remainder == 1) {\n ${o?"value += getX(batch, xF, xR, xC, inputDepthNearestVec4)\n * getW(d2, inputDepthNearestVec4, wF, wR, wC);":"value += getX(batch, inputDepthNearestVec4, xF, xR, xC)\n * getW(d2, inputDepthNearestVec4, wF, wR, wC);"}\n } else if (inputDepthVec4Remainder == 2) {\n ${o?"let xValues = vec2<f32>(\n getX(batch, xF, xR, xC, inputDepthNearestVec4),\n getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1));\n ":"let xValues = vec2<f32>(\n getX(batch, inputDepthNearestVec4, xF, xR, xC),\n getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC));\n "}\n let wValues = vec2<f32>(\n getW(d2, inputDepthNearestVec4, wF, wR, wC),\n getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC));\n value += dot(xValues, wValues);\n } else if (inputDepthVec4Remainder == 3) {\n ${o?"let xValues = vec3<f32>(\n getX(batch, xF, xR, xC, inputDepthNearestVec4),\n getX(batch, xF, xR, xC, inputDepthNearestVec4 + 1),\n getX(batch, xF, xR, xC, inputDepthNearestVec4 + 2));\n ":"let xValues = vec3<f32>(\n getX(batch, inputDepthNearestVec4, xF, xR, xC),\n getX(batch, inputDepthNearestVec4 + 1, xF, xR, xC),\n getX(batch, inputDepthNearestVec4 + 2, xF, xR, xC));\n "}\n let wValues = vec3<f32>(\n getW(d2, inputDepthNearestVec4, wF, wR, wC),\n getW(d2, inputDepthNearestVec4 + 1, wF, wR, wC),\n getW(d2, inputDepthNearestVec4 + 2, wF, wR, wC));\n value += dot(xValues, wValues);\n }\n }\n }\n }\n ${c?"value = value + getBiasByOutputCoords(coords)":""};\n ${m}\n result[global_idx] = f32(value);\n }`}}}})),Wu=V((()=>{gu(),Mu(),Eu(),Gu(),Uu(),Xr=(t,e,n)=>{let i=t.length>2,r=i?"value += b[output_channel];":"",s=t[0].dims,o=t[1].dims,a=o[0]/e.group,u="NHWC"===e.format,h=es(s,o,e.dilations,e.pads,e.strides,u),l=Se.size(h),c=[{type:12,data:l},{type:12,data:e.dilations},{type:12,data:[e.strides[0],e.strides[1]]},{type:12,data:[e.pads[0],e.pads[1]]},{type:12,data:a}];Mr(e,c),c.push(...Re(s,o));let f=["rank","rank"];return i&&(c.push(...Re(t[2].dims)),f.push("rank")),c.push(...Re(h)),{name:"GroupedConv",shaderCache:{hint:e.cacheKey,inputDependencies:f},getRunData:()=>({outputs:[{dims:n?n(h):h,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:c}),getShaderSource:n=>{let a=Be("output",t[0].dataType,h.length),l=Te(a.type.tensor),c=Sr(e,a.type.value,l),f=je("x",t[0].dataType,s.length),d=je("w",t[1].dataType,o.length),p=[f,d];i&&p.push(je("b",t[2].dataType,t[2].dims.length));let v=[{name:"output_size",type:"u32"},{name:"dilations",type:"u32",length:e.dilations.length},{name:"strides",type:"u32",length:2},{name:"pads",type:"u32",length:2},{name:"output_channels_per_group",type:"u32"}];return Er(e,v),`\n ${n.registerUniforms(v).declareVariables(...p,a)}\n\n ${n.mainStart()}\n ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n\n let outputIndices = ${a.offsetToIndices("global_idx")};\n let batch: u32 = outputIndices[0];\n let output_channel: u32 = outputIndices[${u?3:1}];\n let xRCCorner: vec2<u32> = vec2<u32>(outputIndices[${u?1:2}], outputIndices[${u?2:3}]) * uniforms.strides - uniforms.pads;\n let group_id: u32 = output_channel / uniforms.output_channels_per_group;\n\n var value: ${a.type.value} = ${a.type.value}(0);\n for (var wInChannel: u32 = 0u; wInChannel < uniforms.w_shape[1]; wInChannel++) {\n let input_channel = group_id * uniforms.w_shape[1] + wInChannel;\n for (var wHeight: u32 = 0u; wHeight < uniforms.w_shape[2]; wHeight++) {\n let xHeight = xRCCorner.x + wHeight * uniforms.dilations[0];\n\n if (xHeight < 0u || xHeight >= uniforms.x_shape[${u?1:2}]) {\n continue;\n }\n\n for (var wWidth: u32 = 0u; wWidth < uniforms.w_shape[3]; wWidth++) {\n let xWidth = xRCCorner.y + wWidth * uniforms.dilations[1];\n if (xWidth < 0u || xWidth >= uniforms.x_shape[${u?2:3}]) {\n continue;\n }\n\n let xVal = ${u?f.get("batch","xHeight","xWidth","input_channel"):f.get("batch","input_channel","xHeight","xWidth")};\n let wVal = ${d.get("output_channel","wInChannel","wHeight","wWidth")};\n value += xVal*wVal;\n }\n }\n }\n ${r}\n ${c}\n ${a.setByOffset("global_idx","value")}\n }`}}},Qr=(t,e,n)=>{let i=t.length>2,r=Fe(n[3]),s=Fe(n[2]),o=Se.size(n)/r/s,a=[t[0].dims[0],t[0].dims[1],t[0].dims[2],t[0].dims[3]/r],u=[t[1].dims[0],t[1].dims[1],t[1].dims[2],t[1].dims[3]/r],h=[n[0],n[1],n[2],n[3]/r],l=[{type:12,data:o},{type:6,data:[e.strides[0],e.strides[1]]},{type:6,data:[e.pads[0],e.pads[1]]}];Mr(e,l),l.push(...Re(a,u,h));let c=(s-1)*e.strides[1]+u[1];return{name:"GroupedConv-Vectorize",shaderCache:{hint:`${e.cacheKey};${r};${s};${c};${u[0]};${u[1]}`,inputDependencies:i?["rank","rank","type"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:l}),getShaderSource:n=>{let o=Be("output",t[0].dataType,h.length,r),l=Te(o.type.tensor),f=Sr(e,o.type.value,l),d=je("x",t[0].dataType,a.length,r),p=je("w",t[1].dataType,u.length,r),v=[d,p];i&&v.push(je("b",t[2].dataType,t[2].dims,r));let m=i?"value += b[output_channel];":"",y=[{name:"output_size",type:"u32"},{name:"strides",type:"i32",length:2},{name:"pads",type:"i32",length:2}];return Er(e,y),`\n ${n.registerUniforms(y).declareVariables(...v,o)}\n ${n.mainStart()}\n ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n let width0 = uniforms.output_shape[3];\n let output_channel = global_idx % width0;\n var index1 = global_idx / width0;\n let width1 = uniforms.output_shape[2] / ${s}u;\n let col = (index1 % width1) * ${s}u;\n index1 = index1 / width1;\n let row = index1 % uniforms.output_shape[1];\n let batch = index1 / uniforms.output_shape[1];\n\n let x_corner = vec2<i32>(i32(row), i32(col)) * uniforms.strides - uniforms.pads;\n\n var x_vals: array<${d.type.value}, ${c}>;\n var values: array<${o.type.value}, ${s}>;\n let input_channel = output_channel;\n // Use constant instead of uniform can give better performance for w's height/width.\n for (var w_height: u32 = 0u; w_height < ${u[0]}; w_height++) {\n let x_height = x_corner.x + i32(w_height);\n if (x_height >= 0 && u32(x_height) < uniforms.x_shape[1]) {\n for (var i = 0; i < ${c}; i++) {\n let x_width = x_corner.y + i;\n if (x_width >= 0 && u32(x_width) < uniforms.x_shape[2]) {\n x_vals[i] = ${d.get("batch","u32(x_height)","u32(x_width)","input_channel")};\n } else {\n x_vals[i] = ${d.type.value}(0);\n }\n }\n for (var w_width: u32 = 0u; w_width < ${u[1]}; w_width++) {\n let w_val = ${p.get("w_height","w_width","0","output_channel")};\n for (var i = 0u; i < ${s}u; i++) {\n values[i] = fma(x_vals[i * u32(uniforms.strides[1]) + w_width], w_val, values[i]);\n }\n }\n }\n }\n\n for (var i = 0u; i < ${s}u; i++) {\n var value = values[i];\n ${m}\n ${f}\n ${o.set("batch","row","col + i","output_channel","value")};\n }\n }`}}}})),Vu=V((()=>{gu(),Mu(),Bu(),Eu(),Uu(),Zr=(t,e,n,i,r=!1)=>{let s=t[0].dims,o=t[1].dims,a=s[s.length-2],u=o[o.length-1],h=s[s.length-1],l=Fe(u),c=Fe(h),f=Fe(a),d=Se.size(n)/l/f,p=t.length>2,v=i?i.slice(0,-2):n.slice(0,-2),m=[Se.size(v),a,u],y=[{type:12,data:d},{type:12,data:a},{type:12,data:u},{type:12,data:h}];return Mr(e,y),y.push(...Re(v,s,o)),p&&y.push(...Re(t[2].dims)),y.push(...Re(m)),{name:"MatMulNaive",shaderCache:{hint:`${e.activation};${l};${c};${f};${r}`,inputDependencies:p?["rank","rank","rank"]:["rank","rank"]},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(d/64)},programUniforms:y}),getShaderSource:i=>{let a=Le("batch_dims",t[0].dataType,v.length),u=je("a",t[0].dataType,s.length,c),h=je("b",t[1].dataType,o.length,l),d=Be("output",t[0].dataType,m.length,l),y=Te(d.type.tensor),w=Sr(e,d.type.value,y),g=[u,h],b="";if(p){let e=r?l:1;g.push(je("bias",t[2].dataType,t[2].dims.length,e)),b=r?`value += bias[col / ${e}];`:`value += ${d.type.value}(bias[row + i]);`}let _=s.slice(0,-2),x=o.slice(0,-2),k=Ve(_,v),$=Ve(x,v),S=[{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"}];Er(e,S);let M=(t,e)=>{let n=t.rank,i=t.name;if(2===n)return`var ${i}_indices = ${t.type.indices}(0u, 0u);`;let r=a.rank,s=`var ${i}_indices: ${t.type.indices};`;for(let t=n-2-1,e=r-1;t>=0;t--,e--)s+=`\n${i}_indices[${t}] = ${r>1?`batch_indices[${e}]`:"batch_indices"};`;return e.forEach((t=>{s+=`\n${i}_indices[${t}] = 0;`})),s+=`${i}_indices[${n-2}] = 0u;\n ${i}_indices[${n-1}] = 0u;`,s};return`\n ${i.registerUniforms(S).registerInternalVariables(a).declareVariables(...g,d)}\n ${i.mainStart()}\n ${i.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n let col = (global_idx % (uniforms.N / ${l})) * ${l};\n var index1 = global_idx / (uniforms.N / ${l});\n let stride1 = uniforms.M / ${f};\n let row = (index1 % stride1) * ${f};\n let batch = index1 / stride1;\n\n ${2===n.length?"":`let batch_indices = ${a.offsetToIndices("batch")};`}\n ${M(u,k)}\n let a_offset = ${u.indicesToOffset("a_indices")};\n ${M(h,$)}\n let b_offset = ${h.indicesToOffset("b_indices")};\n var values: array<${d.type.value}, ${f}>;\n for (var k: u32 = 0u; k < uniforms.K; k = k + ${c}) {\n ${(()=>{let t=`var a_data: ${u.type.value};`;for(let e=0;e<c;e++)t+=`\n let b_data${e} = b[(b_offset + (k + ${e}) * uniforms.N + col) / ${l}];`;for(let e=0;e<f;e++){t+=`a_data = a[(a_offset + (row + ${e}) * uniforms.K + k) / ${c}];`;for(let n=0;n<c;n++)t+=`\n values[${e}] = fma(${h.type.value}(a_data${1===c?"":`[${n}]`}), b_data${n}, values[${e}]);\n`}return t})()}\n }\n for (var i = 0u; i < ${f}u; i++) {\n var value = values[i];\n ${b}\n ${w}\n let cur_indices = ${d.type.indices}(batch, row + i, col);\n let offset = ${d.indicesToOffset("cur_indices")};\n ${d.setByOffset(`offset / ${l}`,"value")};\n }\n }\n `}}},Jr=t=>{if(!t||2!==t.length)throw new Error("MatMul requires 2 inputs.");if(t[0].dims[t[0].dims.length-1]!==t[1].dims[t[1].dims.length-2])throw new Error("shared dimension does not match.")},ts=t=>{Jr(t.inputs);let e=$e.calcShape(t.inputs[0].dims,t.inputs[1].dims,!0);if(!e)throw new Error("Can't use matmul on the given tensors");let n=e[e.length-1],i=t.inputs[0].dims[t.inputs[0].dims.length-1];n<8&&i<8?t.compute(Zr(t.inputs,{activation:""},e)):t.compute(Ur(t.inputs,{activation:""},e))}})),Gu=V((()=>{Mu(),Lu(),Hu(),Bu(),Wu(),Uu(),Vu(),Cu(),es=(t,e,n,i,r,s)=>{let o=t[0],a=t.slice(s?1:2,s?3:4),u=a.length,h=e[0],l=e.slice(2).map(((t,e)=>t+(t-1)*(n[e]-1))),c=a.map(((t,e)=>t+i[e]+i[e+u])).map(((t,e)=>Math.floor((t-l[e]+r[e])/r[e])));return c.splice(0,0,o),c.splice(s?3:1,0,h),c},ns=[2,3,1,0],is=(t,e)=>{if(!t||2!==t.length&&3!==t.length)throw new Error("Conv requires 2 or 3 inputs");if(t[0].dims.length>5)throw new Error("greater than 5D is not supported");if(t[0].dims.length!==t[1].dims.length)throw new Error("filter does not have same dimension as input");if(t[0].dims["NHWC"===e.format?t[0].dims.length-1:1]!==t[1].dims[1]*e.group)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(3===t.length&&(1!==t[2].dims.length||t[1].dims[0]!==t[2].dims[0]))throw new Error("invalid bias");let n=t[0].dims.length-2;if(e.dilations.length!==n)throw new Error(`dilations should be ${n}D`);if(e.strides.length!==n)throw new Error(`strides should be ${n}D`);if(e.pads.length!==2*n)throw new Error(`pads should be ${2*n}D`);if(0!==e.kernelShape.length&&e.kernelShape.length!==t[1].dims.length-2)throw new Error("invalid kernel shape")},rs=(t,e)=>{let n=t.kernelShape.slice();for(let t=2;t<e[1].dims.length;++t)0===n[t-2]&&(n[t-2]=e[1].dims[t]);let i=t.pads.slice();Me.adjustPadsBasedOnAutoPad(e[0].dims,t.strides,t.dilations,n,i,"NHWC"===t.format,t.autoPad);let r=Object.assign({},t);return Object.assign(r,{kernelShape:n,pads:i}),r},ss=t=>{let e=Cr(t),n=t.format;return{autoPad:["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][t.auto_pad],format:n,dilations:t.dilations,group:t.group,kernelShape:t.kernel_shape,pads:t.pads,strides:t.strides,wIsConst:t.w_is_const(),...e,cacheKey:`${t.format};${e.activation};`}},os=(t,e,n)=>{let i=rs(n,e),r="NHWC"===n.format;if(1!==n.group){if(!t.adapterInfo.isArchitecture("ampere")&&r&&e[1].dims[0]===n.group&&1===e[1].dims[1]&&1===n.dilations[0]&&1===n.dilations[1]){let s=es(e[0].dims,e[1].dims,n.dilations,i.pads,n.strides,r),o=t.kernelCustomData.wT??t.compute(Qe(e[1],ns),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!t.kernelCustomData.wT&&(t.kernelCustomData.wT=o);let a=[e[0],o];3===e.length&&a.push(e[2]),t.compute(Qr(a,i,s),{inputs:a})}else t.compute(Xr(e,i));return}let s=3===e.length,o=e[0].dims[r?1:2],a=e[0].dims[r?2:3],u=e[0].dims[r?3:1],h=e[1].dims[2],l=e[1].dims[3],c=es(e[0].dims,e[1].dims,n.dilations,i.pads,n.strides,r),f=c[r?1:2],d=c[r?2:3],p=c[r?3:1],v=r&&h===o&&l===a&&0===n.pads[0]&&0===n.pads[1];if(v||1===h&&1===l&&1===n.dilations[0]&&1===n.dilations[1]&&1===n.strides[0]&&1===n.strides[1]&&0===n.pads[0]&&0===n.pads[1]){let h,l,m,y=c[0],w=[];if(r){let i=t.kernelCustomData.wT??t.compute(Qe(e[1],ns),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];if(n.wIsConst&&!t.kernelCustomData.wT&&(t.kernelCustomData.wT=i),v){let t=o*a*u;h=e[0].reshape([1,y,t]),l=i.reshape([1,t,p]),m=[1,y,p]}else h=e[0].reshape([y,o*a,u]),l=i.reshape([1,u,p]),m=[y,f*d,p];w.push(h),w.push(l)}else h=e[0].reshape([y,u,o*a]),l=e[1].reshape([1,p,u]),m=[y,p,f*d],w.push(l),w.push(h);s&&w.push(e[2]);let g=m[2],b=w[0].dims[w[0].dims.length-1];return void(g<8&&b<8?t.compute(Zr(w,i,c,m,r),{inputs:w}):t.compute(Ur(w,i,c,m,r),{inputs:w}))}let m=t.kernelCustomData.wT??t.compute(Qe(e[1],ns),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!t.kernelCustomData.wT&&(t.kernelCustomData.wT=m);let y=[e[0],m];s&&y.push(e[2]);let w=r?f*d:p,g=r?p:f*d,b=h*l*u;t.compute(jr(y,i,c,w,g,b,s,!0),{inputs:y})},as=(t,e)=>{let n="NHWC"===e.format,i=[t.inputs[0].reshape(n?[t.inputs[0].dims[0],1,t.inputs[0].dims[1],t.inputs[0].dims[2]]:[t.inputs[0].dims[0],t.inputs[0].dims[1],1,t.inputs[0].dims[2]]),t.inputs[1].reshape([t.inputs[1].dims[0],t.inputs[1].dims[1],1,t.inputs[1].dims[2]])];3===t.inputs.length&&i.push(t.inputs[2]);let r=[0,e.pads[0],0,e.pads[1]],s=[1].concat(e.strides),o=[1].concat(e.dilations),a=[1].concat(e.kernelShape),u=rs({...e,pads:r,strides:s,dilations:o,kernelShape:a},i);t.compute(Xr(i,u,(t=>n?[t[0],t[2],t[3]]:[])))},us=(t,e,n)=>{let i="NHWC"===n.format?"channelsLast":"channelsFirst",r=rs(n,e),s="NOTSET"===n.autoPad?n.pads:n.autoPad,o=Yr(e[0].dims,e[1].dims,n.strides,n.dilations,s,!1,i);t.compute(Kr(e,r,o.outShape,[o.filterDepth,o.filterHeight,o.filterWidth],[o.padInfo.front,o.padInfo.top,o.padInfo.left],i))},hs=(t,e)=>{is(t.inputs,e),3===t.inputs[0].dims.length?as(t,e):5===t.inputs[0].dims.length?us(t,t.inputs,e):os(t,t.inputs,e)}})),Yu=V((()=>{gu(),_u(),Eu(),Uu(),qu(),ju(),Bu(),ls=(t,e=!1,n,i,r=4)=>{let s=t?"\n let coords = vec4<i32>(\n batch,\n row / outWidth,\n row % outWidth,\n col);\n ":"\n let coords = vec4<i32>(\n batch,\n row,\n col / outWidth,\n col % outWidth);\n ",o=t?"row":"col",a=t?"col":"row",u=`\n let inChannels = ${t?"i32(uniforms.x_shape[3])":"i32(uniforms.x_shape[1])"};\n let outWidth = ${t?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"};\n let outRow = ${o} / outWidth;\n let outCol = ${o} % outWidth;\n\n let WRow = ${a} / (uniforms.filter_dims[1] * inChannels);\n let WCol = ${a} / inChannels % uniforms.filter_dims[1];\n let xR = f32(outRow - uniforms.pads[0] + uniforms.dilations[0] * WRow) / f32(uniforms.strides[0]);\n let xC = f32(outCol - uniforms.pads[1] + uniforms.dilations[1] * WCol) / f32(uniforms.strides[1]);\n if (xR < 0.0 || xR >= f32(${t?"i32(uniforms.x_shape[1])":"i32(uniforms.x_shape[2])"}) || fract(xR) > 0.0) {\n return ${i}(0.0);\n }\n if (xC < 0.0 || xC >= f32(${t?"i32(uniforms.x_shape[2])":"i32(uniforms.x_shape[3])"}) || fract(xC) > 0.0) {\n return ${i}(0.0);\n }\n let iXR = i32(xR);\n let iXC = i32(xC);\n let xCh = ${a} % inChannels;\n ${t?"\n let coord = vec4<i32>(batch, iXR, iXC, xCh);\n ":"\n let coord = vec4<i32>(batch, xCh, iXR, iXC);\n "}\n return x[getIndexFromCoords4D(coord, vec4<i32>(uniforms.x_shape))/${r}];`,h=t?`\n let col = colIn * ${r};\n if (row < uniforms.dim_a_outer && col < uniforms.dim_inner) {\n ${u}\n }\n return ${i}(0.0);`:`\n let col = colIn * ${r};\n if (row < uniforms.dim_inner && col < uniforms.dim_b_outer) {\n ${u}\n }\n return ${i}(0.0);`,l=`\n let col = colIn * ${r};\n let inChannels = ${t?"i32(uniforms.x_shape[3])":"i32(uniforms.x_shape[1])"};\n let coordX = uniforms.filter_dims[0] - 1 - row / (uniforms.filter_dims[1] * inChannels);\n let coordY = uniforms.filter_dims[1] - 1 - (row / inChannels) % uniforms.filter_dims[1];\n if (${t?"row < uniforms.dim_inner && col < uniforms.dim_b_outer":"row < uniforms.dim_inner && col < uniforms.dim_a_outer"} && coordX >= 0 && coordY >= 0) {\n let rowInner = row % inChannels;\n let coord = vec4<i32>(coordX, coordY, col, rowInner);\n ${(t=>{switch(t){case 1:return"return w[getIndexFromCoords4D(coord, vec4<i32>(uniforms.w_shape))];";case 4:return`\n let coord1 = vec4<i32>(coordX, coordY, col + 1, rowInner);\n let coord2 = vec4<i32>(coordX, coordY, col + 2, rowInner);\n let coord3 = vec4<i32>(coordX, coordY, col + 3, rowInner);\n let v0 = w[getIndexFromCoords4D(coord, vec4<i32>(uniforms.w_shape))];\n let v1 = w[getIndexFromCoords4D(coord1, vec4<i32>(uniforms.w_shape))];\n let v2 = w[getIndexFromCoords4D(coord2, vec4<i32>(uniforms.w_shape))];\n let v3 = w[getIndexFromCoords4D(coord3, vec4<i32>(uniforms.w_shape))];\n return ${i}(v0, v1, v2, v3);\n `;default:throw new Error(`innerElementSize ${t} is not supported.`)}})(r)}\n }\n return ${i}(0.0);\n `,c=Sr(n,i);return`\n fn mm_readA(batch: i32, row : i32, colIn : i32) -> ${i} {\n ${t?h:l}\n }\n\n fn mm_readB(batch: i32, row : i32, colIn : i32) -> ${i} {\n ${t?l:h}\n }\n\n fn mm_write(batch: i32, row : i32, colIn : i32, valueInput : ${i}) {\n let col = colIn * ${r};\n if (row < uniforms.dim_a_outer && col < uniforms.dim_b_outer) {\n var value = valueInput;\n let outWidth = ${t?"i32(uniforms.result_shape[2])":"i32(uniforms.result_shape[3])"};\n ${s}\n ${Or(e)}\n ${c}\n result[getIndexFromCoords4D(coords, vec4<i32>(uniforms.result_shape))/${r}] = value;\n }\n }`},cs=(t,e,n,i,r,s,o,a)=>{let u="NHWC"===e.format,h=u?t[0].dims[3]:t[0].dims[1],l=n[0],c=u?n[2]:n[3],f=u?n[1]:n[2],d=u?n[3]:n[1],p=u&&h%4==0&&h%3&&d%4==0,v=u?d:c*f,m=u?c*f:d,y=[8,8,1],w=i<=8?[4,1,1]:[4,4,1],g=[Math.ceil(v/y[0]/w[0]),Math.ceil(m/y[1]/w[1]),Math.ceil(l/y[2]/w[2])];le("verbose",(()=>`[conv_backprop_mm_webgpu] dispatch = ${g}`));let b=p?4:1,_=Math.max(y[0]*b,y[1]),x=p?4:1,k=[e.kernelShape[u?1:2],e.kernelShape[u?2:3]],$=[k[0]+(e.dilations[0]<=1?0:(k[0]-1)*(e.dilations[0]-1)),k[1]+(e.dilations[1]<=1?0:(k[1]-1)*(e.dilations[1]-1))],S=[$[0]-1-Math.floor((e.pads[0]+e.pads[2])/2),$[1]-1-Math.floor((e.pads[1]+e.pads[3])/2)],M=[{type:6,data:i},{type:6,data:r},{type:6,data:s},{type:6,data:e.strides},{type:6,data:e.dilations},{type:6,data:k},{type:6,data:S}];Mr(e,M),M.push(...Re(t[0].dims,t[1].dims));let E=["rank","rank"];return o&&(M.push(...Re(t[2].dims)),E.push("rank")),M.push(...Re(n)),{name:"Conv2DTransposeMatMul",shaderCache:{hint:`${e.cacheKey};${w};${y};${p}`,inputDependencies:E},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:g[0],y:g[1],z:g[2]},programUniforms:M}),getShaderSource:i=>{let r=je("x",t[0].dataType,t[0].dims.length,x),s=je("w",t[1].dataType,t[1].dims.length,1),h=Be("result",t[0].dataType,n.length,x),l=[r,s],c="";if(o){let e=je("bias",t[2].dataType,t[2].dims.length,x);l.push(e),c+=`\n fn getBiasByOutputCoords(coords : vec4<i32>) -> ${e.type.value} {\n return bias[coords.${u?"w":"y"}${p?"/ 4":""}];\n }`}let f=[{name:"dim_a_outer",type:"i32"},{name:"dim_b_outer",type:"i32"},{name:"dim_inner",type:"i32"},{name:"strides",type:"i32",length:2},{name:"dilations",type:"i32",length:2},{name:"filter_dims",type:"i32",length:k.length},{name:"pads",type:"i32",length:S.length}];Er(e,f);let d=Te(t[0].dataType,1);if("f16"!==d&&"f32"!==d)throw new Error(`elemType ${d} is not supported.`);return`\n ${Ir("uniforms.result_strides")}\n ${i.registerUniforms(f).declareVariables(...l,h)};\n ${c}\n ${ls(u,o,e,r.type.value,b)}\n ${p?Rr(w,y,d,void 0,!u,_):Dr(w,y,d,void 0,!u,_,!1,void 0,a)}`}}}})),Ku=V((()=>{gu(),_u(),Mu(),Eu(),fs=(t,e,n,i,r,s=!1,o,a,u=!1)=>{let h=u?1:2,l=u?2:3,c=u?3:1,f=s?2:1,d=`\n fn setOutputAtIndex(flatIndex : u32, value : ${s?`vec4<${o}>`:o}) {\n result[flatIndex] = ${s?`vec4<${o}>`:o}(value);\n }`;i&&(d+=`\n fn getBiasByOutputCoords(coords : vec4<u32>) -> ${s?`vec4<${o}>`:o} {\n return bias[coords.${u?"w":"y"}${s?"/ 4":""}];\n }`);let p=s?4:1,v=je("W",e[1].dataType,e[1].dims.length,p),m=je("Dy",e[0].dataType,e[0].dims.length,p),y=[m,v];i&&y.push(je("bias",e[2].dataType,[n[c]].length,p));let w=Be("result",e[0].dataType,n.length,p),g=`{\n let batch: u32 = ${r?"global_id.z":"workgroup_id.z"} / uniforms.result_shape[1];\n let r = ${r?"global_id.z":"workgroup_id.z"} % uniforms.result_shape[1];\n let c = ${r?"global_id.y":"workgroup_id.y"} * ${f};\n let d1: u32 = ${r?"global_id.x":"workgroup_id.x"} * 4;\n\n let dyCorner = vec2<i32>(i32(r), i32(c)) - vec2<i32>(uniforms.pads);\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n var dotProd: array<vec4<${o}>, ${f}>;\n for (var i = 0; i < ${f}; i++) {\n dotProd[i] = vec4<${o}>(0.0);\n }\n for (var wR: u32 = 0; wR < uniforms.filter_dims[0]; wR = wR + 1) {\n var dyR = (${o}(dyCorner.x) + ${o}(wR)) / ${o}(uniforms.strides.x);\n let wRPerm = uniforms.filter_dims[0] - 1 - wR;\n if (dyR < 0.0 || dyR >= ${o}(uniforms.Dy_shape[1]) ||\n fract(dyR) > 0.0 || wRPerm < 0) {\n continue;\n }\n let idyR: u32 = u32(dyR);\n\n for (var wC: u32 = 0; wC < uniforms.filter_dims[1]; wC = wC + 1) {\n let dyC = (${o}(dyCorner.y) + ${o}(wC)) / ${o}(uniforms.strides.y);\n let dyC2 = (${o}(dyCorner.y) + 1.0 + ${o}(wC)) / ${o}(uniforms.strides.y);\n let wCPerm = uniforms.filter_dims[1] - 1 - wC;\n if (wCPerm < 0) {\n continue;\n }\n var bDyCVal = true;\n var bDyCVal2 = true;\n if (dyC < 0.0 || dyC >= ${o}(uniforms.Dy_shape[2]) ||\n fract(dyC) > 0.0) {\n bDyCVal = false;\n }\n if (dyC2 < 0.0 || dyC2 >= ${o}(uniforms.Dy_shape[2]) ||\n fract(dyC2) > 0.0) {\n bDyCVal2 = false;\n }\n\n let idyC: u32 = u32(dyC);\n let idyC2: u32 = u32(dyC2);\n if (bDyCVal && bDyCVal2) {\n let d2Length = uniforms.Dy_shape[3];\n for (var d2 :u32 = 0; d2 < d2Length; d2 = d2 + 4) {\n let wValue0 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1","d2")};\n let wValue1 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 1","d2")};\n let wValue2 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 2","d2")};\n let wValue3 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 3","d2")};\n\n var xValue = ${m.get("batch","idyR","idyC","d2")};\n let tmpval = vec4<${o}>(dot(xValue, wValue0),\n dot(xValue, wValue1),\n dot(xValue, wValue2),\n dot(xValue, wValue3));\n dotProd[0] = dotProd[0] + tmpval;\n\n xValue = ${m.get("batch","idyR","idyC2","d2")};\n\n dotProd[1] = dotProd[1] + vec4<${o}>(dot(xValue, wValue0),\n dot(xValue, wValue1),\n dot(xValue, wValue2),\n dot(xValue, wValue3));\n }\n } else if (bDyCVal) {\n let d2Length = uniforms.Dy_shape[${c}];\n for (var d2: u32 = 0; d2 < d2Length; d2 = d2 + 4) {\n let wValue0 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1","d2")};\n let wValue1 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 1","d2")};\n let wValue2 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 2","d2")};\n let wValue3 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 3","d2")};\n\n var xValue = ${m.get("batch","idyR","idyC","d2")};\n let tmpval = vec4<${o}>(dot(xValue, wValue0),\n dot(xValue, wValue1),\n dot(xValue, wValue2),\n dot(xValue, wValue3));\n dotProd[0] = dotProd[0] + tmpval;\n }\n } else if (bDyCVal2) {\n let d2Length = uniforms.Dy_shape[3];\n for (var d2: u32 = 0; d2 < d2Length; d2 = d2 + 4) {\n let wValue0 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1","d2")};\n let wValue1 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 1","d2")};\n let wValue2 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 2","d2")};\n let wValue3 = ${v.get("u32(wRPerm)","u32(wCPerm)","d1 + 3","d2")};\n\n var xValue = ${m.get("batch","idyR","idyC2","d2")};\n let tmpval = vec4<${o}>(dot(xValue, wValue0),\n dot(xValue, wValue1),\n dot(xValue, wValue2),\n dot(xValue, wValue3));\n dotProd[1] = dotProd[1] + tmpval;\n }\n }\n }\n }\n\n for (var i: u32 = 0; i < ${f}; i = i + 1) {\n let value = dotProd[i] + ${i?"bias[c+i]":`vec4<${o}>(0.0)`};\n ${w.set("batch","r","c + i","d1","value")};\n }\n }`,b=`\n let outputIndices = ${w.offsetToIndices("global_idx")};\n let batch = ${w.indicesGet("outputIndices",0)};\n let d1 = ${w.indicesGet("outputIndices",c)};\n let r = ${w.indicesGet("outputIndices",h)};\n let c = ${w.indicesGet("outputIndices",l)};\n let dyCorner = vec2<i32>(i32(r), i32(c)) - uniforms.pads;\n let dyRCorner = dyCorner.x;\n let dyCCorner = dyCorner.y;\n let groupId = d1 / uniforms.output_channels_per_group;\n let wOutChannel = d1 - groupId * uniforms.output_channels_per_group;\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n var dotProd = ${o}(0.0);\n for (var wR: u32 = 0; wR < uniforms.effective_filter_dims.x; wR = wR + 1) {\n if (wR % uniforms.dilations.x != 0) {\n continue;\n }\n let dyR = (${o}(dyRCorner) + ${o}(wR)) / ${o}(uniforms.strides[0]);\n let wRPerm = uniforms.filter_dims.x - 1 - wR / uniforms.dilations.x;\n if (dyR < 0.0 || dyR >= ${o}(uniforms.Dy_shape[${h}]) || fract(dyR) > 0.0 ||\n wRPerm < 0) {\n continue;\n }\n let idyR: u32 = u32(dyR);\n\n for (var wC: u32 = 0; wC < uniforms.effective_filter_dims.y; wC = wC + 1) {\n if (wC % uniforms.dilations.y != 0) {\n continue;\n }\n let dyC = (${o}(dyCCorner) + ${o}(wC)) / ${o}(uniforms.strides.y);\n let wCPerm = uniforms.filter_dims.y - 1 - wC / uniforms.dilations.y;\n if (dyC < 0.0 || dyC >= ${o}(uniforms.Dy_shape[${l}]) ||\n fract(dyC) > 0.0 || wCPerm < 0) {\n continue;\n }\n let idyC: u32 = u32(dyC);\n var inputChannel = groupId * uniforms.input_channels_per_group;\n for (var d2: u32 = 0; d2 < uniforms.input_channels_per_group; d2 = d2 + 1) {\n let xValue = ${u?m.get("batch","idyR","idyC","inputChannel"):m.get("batch","inputChannel","idyR","idyC")};\n let wValue = ${v.get("inputChannel","wOutChannel","u32(wRPerm)","u32(wCPerm)")};\n dotProd = dotProd + xValue * wValue;\n inputChannel = inputChannel + 1;\n }\n }\n }\n let value = dotProd + ${i?"bias[d1]":`${o}(0.0)`};\n ${w.setByOffset("global_idx","value")};\n `;return`\n ${t.registerUniforms(a).declareVariables(...y,w)}\n ${d}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")};\n ${s?g:b}}`},ds=(t,e,n)=>{let i=t.length>2,r=e.outputShape,s=Se.size(r),o=[Math.ceil(s/64),1,1];le("verbose",(()=>`[conv2d_backprop_webgpu] dispatch = ${o}`));let a="NHWC"===e.format,u=["rank","rank"],h=[e.strides[0],e.strides[1]],l=[e.kernelShape[a?1:2],e.kernelShape[a?2:3]],c=[e.dilations[0],e.dilations[1]],f=[l[0]+(e.dilations[0]<=1?0:(e.kernelShape[a?1:2]-1)*(e.dilations[0]-1)),l[1]+(e.dilations[1]<=1?0:(e.kernelShape[a?2:3]-1)*(e.dilations[1]-1))],d=[f[0]-1-Math.floor((e.pads[0]+e.pads[2])/2),f[1]-1-Math.floor(e.pads[1]+e.pads[3])/2],p=e.group,v=t[1].dims,m=v[0]/p,y=v[1],w=[{type:12,data:s},{type:12,data:h},{type:12,data:l},{type:12,data:c},{type:12,data:f},{type:6,data:d},{type:12,data:m},{type:12,data:y},...Re(t[0].dims,t[1].dims)];i&&(w.push(...Re(t[2].dims)),u.push("rank")),w.push(...Re(r));let g=1===o[1]&&1===o[2];return{name:"ConvTranspose2D",shaderCache:{hint:`${e.cacheKey};`,inputDependencies:u},getRunData:()=>({dispatchGroup:{x:o[0],y:o[1],z:o[2]},outputs:[{dims:n?n(r):r,dataType:t[0].dataType}],programUniforms:w}),getShaderSource:e=>{let n=[{name:"output_size",type:"u32"},{name:"strides",type:"u32",length:h.length},{name:"filter_dims",type:"u32",length:l.length},{name:"dilations",type:"u32",length:l.length},{name:"effective_filter_dims",type:"u32",length:f.length},{name:"pads",type:"i32",length:d.length},{name:"input_channels_per_group",type:"u32"},{name:"output_channels_per_group",type:"u32"}],s=Te(t[0].dataType);return`${fs(e,t,r,i,g,!1,s,n,a)}`}}}})),Xu=V((()=>{Yu(),Ku(),Uu(),Cu(),ps=(t,e,n,i,r,s)=>(t-1)*e+n+(i-1)*r+1-s,vs=(t,e,n,i,r)=>{let s=Math.floor(t/2);"SAME_UPPER"===e?(n[i]=s,n[r]=t-s):"SAME_LOWER"===e&&(n[i]=t-s,n[r]=s)},ms=(t,e,n,i,r,s,o,a,u,h)=>{let l=t.length-2,c=0===h.length;if(0===u.length)for(let t=0;t<l;++t)u.push(0);let f=t[0],d=e[a?3:1]*r;for(let r=0,f=t.length-l-(a?1:0);r<l;++r,++f){let a=t[f],d=c?a*o[r]:h[r],p=ps(a,o[r],s[r],e[f],n[r],d);vs(p,i,s,r,r+l),c&&h.push(o[r]*(a-1)+u[r]+(e[f]-1)*n[r]+1-s[r]-s[r+l])}h.splice(0,0,f),h.splice(a?3:1,0,d)},ys=(t,e)=>{let n=t.kernelShape.slice();if(0===t.kernelShape.length||0===t.kernelShape.reduce(((t,e)=>t*e),1)){n.length=0;for(let t=2;t<e[1].dims.length;++t)n.push(e[1].dims[t])}let i="NHWC"===t.format;n.splice(0,0,e[1].dims[0]),n.splice(i?3:1,0,e[1].dims[1]);let r=t.pads.slice(),s=t.outputShape.slice(),o=t.outputPadding.slice(),a=e[0].dims,u=t.dilations.slice();if(0===u.reduce(((t,e)=>t+e),0)){let t=e[0].dims.length-2;u=new Array(t).fill(1)}let h=t.strides.slice();if(0===h.reduce(((t,e)=>t+e),0)){let t=e[0].dims.length-2;h=new Array(t).fill(1)}ms(a,n,u,t.autoPad,t.group,r,h,i,o,s);let l=Object.assign({},t);return Object.assign(l,{kernelShape:n,pads:r,outputPadding:o,outputShape:s,dilations:u,strides:h}),l},ws=t=>{let e=Cr(t),n=t.format,i=["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][typeof t.autoPad>"u"?0:t.autoPad],r=t.dilations,s=t.group,o=t.kernelShape,a=t.pads,u=t.strides,h=t.wIsConst();return{autoPad:i,format:n,dilations:r,group:s,kernelShape:o,outputPadding:t.outputPadding,outputShape:t.outputShape,pads:a,strides:u,wIsConst:h,...e,cacheKey:`${t.format};${e.activation};`}},gs=(t,e)=>{if(!t||2!==t.length&&3!==t.length)throw new Error("Conv requires 2 or 3 inputs");if(4!==t[0].dims.length&&3!==t[0].dims.length)throw new Error("currently only support 2-dimensional conv");if(t[0].dims.length!==t[1].dims.length)throw new Error("filter does not have same dimension as input");if(t[0].dims["NHWC"===e.format?t[0].dims.length-1:1]!==t[1].dims[0])throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");let n=t[1].dims[1]*e.group;if(3===t.length&&(1!==t[2].dims.length||t[2].dims[0]!==n))throw new Error("invalid bias");let i=t[0].dims.length-2;if(e.dilations.reduce(((t,e)=>t+e),0)>0&&e.dilations.length!==i)throw new Error(`dilations should be ${i}D`);if(e.strides.reduce(((t,e)=>t+e),0)>0&&e.strides.length!==i)throw new Error(`strides should be ${i}D`);if(e.pads.reduce(((t,e)=>t+e),0)>0&&e.pads.length!==2*i)throw new Error(`pads should be ${2*i}D`);if(e.outputPadding.length!==i&&0!==e.outputPadding.length)throw new Error(`output_padding should be ${i}D`);if(e.kernelShape.reduce(((t,e)=>t+e),0)>0&&0!==e.kernelShape.length&&e.kernelShape.length!==t[1].dims.length-2)throw new Error("invalid kernel shape");if(0!==e.outputShape.length&&e.outputShape.length!==t[0].dims.length-2)throw new Error("invalid output shape")},bs=[2,3,1,0],_s=(t,e,n)=>{let i=ys(n,e),r="NHWC"===n.format,s=i.outputShape,o=s[r?3:1],a=e[0].dims[r?3:1];if(1!==i.group||1===o&&1===a)return void t.compute(ds(e,i));let u=s[r?1:2],h=s[r?2:3],l=r?u*h:o,c=r?o:u*h,f=e[1].dims[2]*e[1].dims[3]*a,d=t.kernelCustomData.wT??t.compute(Qe(e[1],bs),{inputs:[1],outputs:[n.wIsConst?-2:-1]})[0];n.wIsConst&&!t.kernelCustomData.wT&&(t.kernelCustomData.wT=d);let p=[e[0],d],v=3===e.length;v&&(r||1!==e[2].dims.length?p.push(e[2]):p.push(e[2].reshape([e[2].dims[0],1,1]))),t.compute(cs(p,i,s,l,c,f,v,!0),{inputs:p})},xs=(t,e)=>{let n="NHWC"===e.format,i=[t.inputs[0].reshape(n?[t.inputs[0].dims[0],1,t.inputs[0].dims[1],t.inputs[0].dims[2]]:[t.inputs[0].dims[0],t.inputs[0].dims[1],1,t.inputs[0].dims[2]]),t.inputs[1].reshape([t.inputs[1].dims[0],t.inputs[1].dims[1],1,t.inputs[1].dims[2]])];3===t.inputs.length&&i.push(t.inputs[2]);let r=e.kernelShape;(0===r.length||0===r[0])&&(r=[t.inputs[1].dims[2]]);let s=e.dilations;(0===s.length||0===s[0])&&(s=[1]);let o=e.strides;(0===o.length||0===o[0])&&(o=[1]);let a=e.pads;0===a.length&&(a=[0,0]),a=[0,a[0],0,a[1]],o=[1].concat(o),s=[1].concat(s),r=[1].concat(r);let u=ys({...e,pads:a,strides:o,dilations:s,kernelShape:r},i);t.compute(ds(i,u,(t=>n?[t[0],t[2],t[3]]:[t[0],t[1],t[3]])))},ks=(t,e)=>{gs(t.inputs,e),3===t.inputs[0].dims.length?xs(t,e):_s(t,t.inputs,e)}})),Qu=V((()=>{gu(),Mu(),Su(),Eu(),$s=(t,e,n,i)=>{let r=Se.size(e),s=e.length,o=je("input",t,s),a=Be("output",t,s),u=6===n.dataType?n.getInt32Array()[0]:Number(n.getBigInt64Array()[0]),h=Se.normalizeAxis(u,s);return{name:"CumSum",shaderCache:{hint:i.cacheKey,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:e,dataType:t}],dispatchGroup:{x:Math.ceil(r/64)},programUniforms:[{type:12,data:r},{type:12,data:h},...Re(e,e)]}),getShaderSource:t=>{let e=` i32(${o.indicesGet("inputIndices","uniforms.axis")}) `,n=Ue("uniforms.input_shape","uniforms.axis",s),r=i.reverse?e+(i.exclusive?" + 1":""):"0",u=i.reverse?n:e+(i.exclusive?"":" + 1");return`\n ${t.registerUniform("outputSize","u32").registerUniform("axis","u32").declareVariables(o,a)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n var inputIndices = ${a.offsetToIndices("global_idx")};\n var sum = ${a.type.value}(0);\n let first : i32 = ${r};\n let last : i32 = ${u};\n for (var i : i32 = first; i < last; i++) {\n ${o.indicesSet("inputIndices","uniforms.axis","u32(i)")};\n sum = sum + ${o.getByIndices("inputIndices")};\n }\n ${a.setByOffset("global_idx","sum")};\n }`}}},Ss=(t,e)=>{let n=t.inputs[0].dims,i=t.inputs[0].dataType,r=t.inputs[1];t.compute($s(i,n,r,e),{inputs:[0]})},Ms=t=>{let e=1===t.exclusive,n=1===t.reverse;return xe({exclusive:e,reverse:n})}})),Zu=V((()=>{gu(),Mu(),Su(),Eu(),Es=t=>{if(!t||1!==t.length)throw new Error("DepthToSpace requires 1 input.");if(4!==t[0].dims.length)throw new Error("DepthToSpace requires 4D input.")},Cs=(t,e,n,i)=>{let r=[];r.push(`fn perm(i: ${i.type.indices}) -> ${n.type.indices} {\n var a: ${n.type.indices};`);for(let i=0;i<e;++i)r.push(n.indicesSet("a",t[i],`i[${i}]`));return r.push("return a;}"),r.join("\n")},As=(t,e)=>{let n,i,r,s,o,a,u="NHWC"===e.format,h=e.blocksize,l="DCR"===e.mode;u?([n,i,r,s]=t.dims,o=l?[n,i,r,h,h,s/h**2]:[n,i,r,s/h**2,h,h],a=l?[0,1,3,2,4,5]:[0,1,4,2,5,3]):([n,i,r,s]=[t.dims[0],t.dims[2],t.dims[3],t.dims[1]],o=l?[n,h,h,s/h**2,i,r]:[n,s/h**2,h,h,i,r],a=l?[0,3,4,1,5,2]:[0,1,4,2,5,3]);let c=t.reshape(o),f=c.dims.length,d=t.dataType,p=je("a",d,f),v=Be("output",d,f);return{name:"DepthToSpace",shaderCache:{hint:`${t.dims};${e.blocksize};${e.mode}`,inputDependencies:["rank"]},getRunData:t=>{let e=u?[n,i*h,r*h,s/h**2]:[n,s/h**2,i*h,r*h],o=Se.size(e),l=c.dims,f=Se.sortBasedOnPerm(l,a);return{outputs:[{dims:e,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:[{type:12,data:o},...Re(l,f)]}},getShaderSource:t=>`\n ${t.registerUniform("output_size","u32").declareVariables(p,v)}\n\n ${Cs(a,f,p,v)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n\n let indices = ${v.offsetToIndices("global_idx")};\n let aIndices = perm(indices);\n\n ${v.setByOffset("global_idx",p.getByIndices("aIndices"))}\n }`}},Os=(t,e)=>{Es(t.inputs),t.compute(As(t.inputs[0],e))},Is=t=>xe({blocksize:t.blocksize,mode:t.mode,format:t.format})})),Ju=V((()=>{gu(),Mu(),Su(),Eu(),Rs="^"+(zs="("+(Ts="[a-zA-Z]|\\.\\.\\.")+")+")+"$",Fs="^("+zs+",)*"+zs+"$",Ps=class{constructor(t=-1){this.symbolToIndices=new Map,this.inputIndex=t}addSymbol(t,e){let n=this.symbolToIndices.get(t);void 0===n?n=[e]:n.push(e),this.symbolToIndices.set(t,n)}},Ds=class{constructor(t,e){this.equation=e,this.hasEllipsis=!1,this.symbolToInfo=new Map,this.lhs=new Array,this.outputDims=[];let[n,i]=e.includes("->")?e.split("->",2):[e,""];if(!n.match(RegExp(Fs)))throw new Error("Invalid LHS term");if(n.split(",").forEach(((e,n)=>{let i=t[n].dims.slice();if(!e.match(RegExp(Rs)))throw new Error("Invalid LHS term");let r=this.processTerm(e,!0,i,n);this.lhs.push(r)})),""===i)i+=[...this.symbolToInfo.entries()].filter((([t,e])=>1===e.count||"..."===t)).map((([t])=>t)).join("");else if(!i.match(RegExp(zs)))throw new Error("Invalid RHS");i.match(RegExp(Ts,"g"))?.forEach((t=>{if("..."===t)this.outputDims=this.outputDims.concat(this.ellipsisDims);else{let e=this.symbolToInfo.get(t);if(void 0===e)throw new Error("Invalid RHS symbol");this.outputDims.push(e.dimValue)}})),this.rhs=this.processTerm(i,!1,this.outputDims)}addSymbol(t,e,n){let i=this.symbolToInfo.get(t);if(void 0!==i){if(i.dimValue!==e&&1!==i.count)throw new Error("Dimension mismatch");i.count++,i.inputIndices.push(n)}else i={count:1,dimValue:e,inputIndices:[n]};this.symbolToInfo.set(t,i)}processTerm(t,e,n,i=-1){let r=n.length,s=!1,o=[],a=0;if(!t.match(RegExp(Rs))&&!e&&""!==t)throw new Error("Invalid LHS term");let u=t.match(RegExp(Ts,"g")),h=new Ps(i);return u?.forEach(((t,l)=>{if("..."===t){if(s)throw new Error("Only one ellipsis is allowed per input term");s=!0;let t=r-u.length+1;if(t<0)throw new Error("Ellipsis out of bounds");if(o=n.slice(a,a+t),this.hasEllipsis){if(this.ellipsisDims.length!==o.length||this.ellipsisDims.toString()!==o.toString())throw new Error("Ellipsis dimensions mismatch")}else{if(!e)throw new Error("Ellipsis must be specified in the LHS");this.hasEllipsis=!0,this.ellipsisDims=o}for(let t=0;t<o.length;t++){let e=String.fromCharCode("0".charCodeAt(0)+t);h.addSymbol(e,l+t),this.addSymbol(e,n[a++],i)}}else h.addSymbol(t,l+(this.hasEllipsis?this.ellipsisDims.length-1:0)),this.addSymbol(t,n[a++],i)})),h}},Ns=t=>t+"_max",Us=(t,e,n,i)=>{let r=t.map((t=>t.length)).map(((t,n)=>je(`input${n}`,e,t))),s=Se.size(i),o=Be("output",e,i.length),a=[...n.symbolToInfo.keys()].filter((t=>!n.rhs.symbolToIndices.has(t)));return{name:"Einsum",shaderCache:{hint:n.equation,inputDependencies:t.map((()=>"rank"))},getRunData:()=>{let r=a.filter((t=>n.symbolToInfo.has(t))).map((t=>({type:12,data:n.symbolToInfo.get(t)?.dimValue||0})));r.push({type:12,data:s});let o=t.map(((t,e)=>[...Re(t)])).reduce(((t,e)=>t.concat(e)),r);return o.push(...Re(i)),{outputs:[{dims:i,dataType:e}],dispatchGroup:{x:Math.ceil(s/64)},programUniforms:o}},getShaderSource:t=>{let e=[],i=[],s=[],u=[],h=[],l=n.symbolToInfo.size===n.rhs.symbolToIndices.size;n.symbolToInfo.forEach(((t,a)=>{if(n.rhs.symbolToIndices.has(a)){let i=n.rhs.symbolToIndices.get(a)?.[0];void 0!==i&&n.lhs.forEach(((n,s)=>{if(t.inputIndices.includes(s)){let t=n.symbolToIndices.get(a);if(void 0===t)throw new Error("Invalid symbol error");t.forEach((t=>{e.push(`${r[s].indicesSet(`input${s}Indices`,t,o.indicesGet("outputIndices",i))}`)}))}}))}else n.lhs.forEach(((e,n)=>{if(t.inputIndices.includes(n)){let t=e.symbolToIndices.get(a);if(void 0===t)throw new Error("Invalid symbol error");t.forEach((t=>{i.push(`${r[n].indicesSet(`input${n}Indices`,t,`${a}`)}`)})),h.push(`prod *= ${r[n].getByIndices(`input${n}Indices`)};`)}})),s.push(`for(var ${a}: u32 = 0; ${a} < uniforms.${Ns(a)}; ${a}++) {`),u.push("}")}));let c=l?[...e,`let sum = ${r.map(((t,e)=>t.getByIndices(`input${e}Indices`))).join(" * ")};`]:[...e,"var sum = 0.0;",...s,...i,"var prod = 1.0;",...h,"sum += prod;",...u];return`\n ${t.registerUniforms(a.map((t=>({name:`${Ns(t)}`,type:"u32"})))).registerUniform("outputSize","u32").declareVariables(...r,o)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n var outputIndices = ${o.offsetToIndices("global_idx")};\n ${r.map(((t,e)=>`var input${e}Indices: ${r[e].type.indices};`)).join("\n")}\n ${c.join("\n")};\n ${o.setByOffset("global_idx","sum")};\n }`}}},qs=(t,e)=>{let n=new Ds(t.inputs,e.equation),i=n.outputDims,r=t.inputs.map(((t,e)=>t.dims));t.compute(Us(r,t.inputs[0].dataType,n,i))},js=t=>{let e=t.equation.replace(/\s+/g,"");return xe({equation:e})}})),th=V((()=>{gu(),Mu(),Eu(),Bs=t=>{if(!t||2!==t.length)throw new Error("Expand requires 2 input.");let e=t[0].dims,n=Array.from(t[1].getBigInt64Array(),Number),i=n.length<e.length?0:n.length-e.length,r=e.length<n.length?0:e.length-n.length;for(;i<n.length&&r<e.length;++i,++r)if(n[i]!==e[r]&&1!==n[i]&&1!==e[r])throw new Error("Expand requires shape to be broadcastable to input")},Ls=(t,e)=>{let n=t.length-e.length,i=[];for(let e=0;e<n;++e)i.push(t[e]);for(let r=0;r<e.length;++r)i.push(1===e[r]?t[r+n]:e[r]);return i},Hs=(t,e)=>t.length>e.length?Ls(t,e):Ls(e,t),Ws=t=>{let e=t[0].dims,n=Array.from(t[1].getBigInt64Array(),Number),i=Hs(e,n),r=t[0].dataType,s=9===r?4:1,o=Math.ceil(Se.size(i)/s),a=[{type:12,data:o},...Re(e,i)];return{name:"Expand",shaderCache:{hint:`${i.length}`,inputDependencies:["rank"]},getShaderSource:t=>{let n,o=je("input",r,e.length,s),a=Be("output",r,i.length,s);if(9===r){let t=(t,e,n="")=>`\n let outputIndices${e} = ${a.offsetToIndices(`outputOffset + ${e}u`)};\n let offset${e} = ${o.broadcastedIndicesToOffset(`outputIndices${e}`,a)};\n let index${e} = offset${e} / 4u;\n let component${e} = offset${e} % 4u;\n ${t}[${e}] = ${n}(${o.getByOffset(`index${e}`)}[component${e}]);\n `;n=`\n let outputOffset = global_idx * ${s};\n var data = vec4<u32>(0);\n ${t("data",0,"u32")}\n ${t("data",1,"u32")}\n ${t("data",2,"u32")}\n ${t("data",3,"u32")}\n ${a.setByOffset("global_idx","data")}\n }`}else n=`\n let outputIndices = ${a.offsetToIndices("global_idx")};\n let inputOffset = ${o.broadcastedIndicesToOffset("outputIndices",a)};\n ${a.setByOffset("global_idx",o.getByOffset("inputOffset"))}\n }`;return`\n ${t.registerUniform("vec_size","u32").declareVariables(o,a)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")}\n ${n}`},getRunData:()=>({outputs:[{dims:i,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:a})}},Vs=t=>{Bs(t.inputs),t.compute(Ws(t.inputs),{inputs:[0]})}})),eh=V((()=>{gu(),Mu(),Eu(),Fu(),Gs=t=>{let e=t[0].dataType,n=Se.size(t[0].dims),i=Se.size(t[1].dims),r=i%4==0;return{name:"FastGeluWithBias",shaderCache:{hint:`${r}`,inputDependencies:["type","type"]},getShaderSource:t=>{let n=je("x",e,[1],4),i=je("bias",e,[1],4),s=Be("y",e,[1],4),o=t=>`\n let bias${t}_offset: u32 = (global_idx * 4 + ${t}) % uniforms.bias_size;\n let bias${t} = ${i.getByOffset(`bias${t}_offset / 4`)}[bias${t}_offset % 4];`,a=r?`\n let bias = ${i.getByOffset("global_idx % (uniforms.bias_size / 4)")};`:`${o(0)}${o(1)}${o(2)}${o(3)}\n let bias = ${n.type.value}(bias0, bias1, bias2, bias3);`;return`${t.registerUniforms([{name:"output_vec_size",type:"u32"},{name:"bias_size",type:"u32"}]).declareVariables(n,i,s)}\n\n ${Ki(ze(e))}\n\n ${t.mainStart(Oe)}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_vec_size")}\n\n let x = ${n.getByOffset("global_idx")};\n ${a}\n let x_in = x + bias;\n ${s.setByOffset("global_idx",Xi("x_in"))}\n }`},getRunData:t=>({outputs:[{dims:t[0].dims,dataType:t[0].dataType}],programUniforms:[{type:12,data:Math.ceil(n/4)},{type:12,data:i}],dispatchGroup:{x:Math.ceil(n/Oe/4)}})}},Ys=t=>{t.inputs.length<2||0===Se.size(t.inputs[1].dims)?Qi(t):t.compute(Gs(t.inputs))}})),nh=V((()=>{gu(),Mu(),Su(),Eu(),Ks=t=>{if(!t||2!==t.length)throw new Error("Gather requires 2 inputs.")},Xs=(t,e)=>{let n=t[0].dims,i=t[1].dims,r=n.length,s=Se.normalizeAxis(e.axis,r),o=n.slice(0);o.splice(s,1,...i);let a=n[s],u=9===t[0].dataType?4:1,h=Math.ceil(Se.size(o)/u),l=[{type:12,data:h},{type:6,data:a},{type:12,data:s},...Re(t[0].dims,t[1].dims,o)];return{name:"Gather",shaderCache:{hint:e.cacheKey,inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:o,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:l}),getShaderSource:e=>{let n,a=je("data",t[0].dataType,t[0].dims.length,u),h=je("inputIndices",t[1].dataType,t[1].dims.length),l=Be("output",t[0].dataType,o.length,u),c=t=>{let e=i.length,n=`var indicesIndices${t} = ${h.type.indices}(0);`;for(let i=0;i<e;i++)n+=`${e>1?`indicesIndices${t}[${i}]`:`indicesIndices${t}`} = ${o.length>1?`outputIndices${t}[uniforms.axis + ${i}]`:`outputIndices${t}`};`;n+=`\n var idx${t} = ${h.getByIndices(`indicesIndices${t}`)};\n if (idx${t} < 0) {\n idx${t} = idx${t} + uniforms.axisDimLimit;\n }\n var dataIndices${t} : ${a.type.indices};\n `;for(let i=0,a=0;i<r;i++)i===s?(n+=`${r>1?`dataIndices${t}[${i}]`:`dataIndices${t}`} = u32(idx${t});`,a+=e):(n+=`${r>1?`dataIndices${t}[${i}]`:`dataIndices${t}`} = ${o.length>1?`outputIndices${t}[${a}]`:`outputIndices${t}`};`,a++);return n};if(9===t[0].dataType){let t=(t,e,n="")=>`\n let outputIndices${e} = ${l.offsetToIndices(`outputOffset + ${e}u`)};\n ${c(e)};\n let offset${e} = ${a.indicesToOffset(`dataIndices${e}`)};\n let index${e} = offset${e} / 4u;\n let component${e} = offset${e} % 4u;\n ${t}[${e}] = ${n}(${a.getByOffset(`index${e}`)}[component${e}]);\n `;n=`\n let outputOffset = global_idx * ${u};\n var value = vec4<u32>(0);\n ${t("value",0,"u32")}\n ${t("value",1,"u32")}\n ${t("value",2,"u32")}\n ${t("value",3,"u32")}\n ${l.setByOffset("global_idx","value")}\n `}else n=`\n let outputIndices = ${l.offsetToIndices("global_idx")};\n ${c("")};\n let value = ${a.getByIndices("dataIndices")};\n ${l.setByOffset("global_idx","value")};\n `;return`\n ${e.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(a,h,l)}\n ${e.mainStart()}\n ${e.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n ${n}\n }`}}},Qs=t=>xe({axis:t.axis}),Zs=(t,e)=>{let n=t.inputs;Ks(n),t.compute(Xs(t.inputs,e))}})),ih=V((()=>{gu(),Mu(),Su(),Eu(),Js=t=>{if(!t||2!==t.length)throw new Error("GatherElements requires 2 inputs.");if(t[0].dims.length<1)throw new Error("GatherElements requires that the data input be rank >= 1.");if(t[0].dims.length!==t[1].dims.length)throw new Error("GatherElements requires that the data input and\n indices input tensors be of same rank.")},to=(t,e)=>{let n=t[0].dims,i=t[0].dataType,r=n.length,s=t[1].dims,o=t[1].dataType,a=Se.normalizeAxis(e.axis,r),u=n[a],h=s.slice(0),l=Se.size(h),c=je("input",i,r),f=je("indicesInput",o,s.length),d=Be("output",i,h.length),p=[{type:12,data:l},{type:6,data:u},{type:12,data:a}];return p.push(...Re(n,s,h)),{name:"GatherElements",shaderCache:{inputDependencies:["rank","rank"]},getRunData:()=>({outputs:[{dims:h,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(l/64)},programUniforms:p}),getShaderSource:t=>`\n ${t.registerUniform("outputSize","u32").registerUniform("axisDimLimit","i32").registerUniform("axis","u32").declareVariables(c,f,d)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n\n let outputIndices = ${d.offsetToIndices("global_idx")};\n\n var idx = ${f.getByOffset("global_idx")};\n if (idx < 0) {\n idx = idx + uniforms.axisDimLimit;\n }\n var inputIndices = ${c.type.indices}(outputIndices);\n ${c.indicesSet("inputIndices","uniforms.axis","u32(idx)")};\n let value = ${c.getByIndices("inputIndices")};\n\n ${d.setByOffset("global_idx","value")};\n }`}},eo=t=>xe({axis:t.axis}),no=(t,e)=>{let n=t.inputs;Js(n),t.compute(to(t.inputs,e))}})),rh=V((()=>{gu(),Mu(),Eu(),io=t=>{if(!t)throw new Error("Input is missing");if(t.length<2||t.length>3)throw new Error("Invaid input number.");if(3===t.length&&t[2].dims.length>2)throw new Error("Invalid input shape of C");if(t[0].dataType!==t[1].dataType||3===t.length&&t[0].dataType!==t[2].dataType)throw new Error("Input types are mismatched")},ro=(t,e)=>{let n=t[0].dims.slice(),i=t[1].dims.slice(),[r,s,o]=Ee.getShapeOfGemmResult(n,e.transA,i,e.transB,3===t.length?t[2].dims:void 0),a=[r,s];if(!a)throw new Error("Can't use gemm on the given tensors");let u=Se.size(a),h=[{type:12,data:u},{type:12,data:r},{type:12,data:s},{type:12,data:o},{type:1,data:e.alpha},{type:1,data:e.beta}],l=["type","type"];return 3===t.length&&(h.push(...Re(t[2].dims)),l.push("rank")),h.push(...Re(a)),{name:"Gemm",shaderCache:{hint:`${e.cacheKey}`,inputDependencies:l},getRunData:()=>({outputs:[{dims:a,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:h}),getShaderSource:n=>{let i="";e.transA&&e.transB?i="value += a[k * uniforms.M + m] * b[n * uniforms.K + k];":e.transA&&!e.transB?i="value += a[k * uniforms.M + m] * b[k * uniforms.N + n];":!e.transA&&e.transB?i="value += a[m * uniforms.K + k] * b[n * uniforms.K + k];":!e.transA&&!e.transB&&(i="value += a[m * uniforms.K + k] * b[k * uniforms.N + n];");let r=1===e.alpha?"":"value *= uniforms.alpha;",s=je("a",t[0].dataType,t[0].dims),o=je("b",t[1].dataType,t[1].dims),u=s.type.value,h=null,l=[s,o];3===t.length&&(h=je("c",t[2].dataType,t[2].dims.length),l.push(h));let c=Be("output",t[0].dataType,a.length);return l.push(c),`\n ${n.registerUniforms([{name:"output_size",type:"u32"},{name:"M",type:"u32"},{name:"N",type:"u32"},{name:"K",type:"u32"},{name:"alpha",type:"f32"},{name:"beta",type:"f32"}]).declareVariables(...l)}\n\n ${n.mainStart()}\n ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n\n let m = global_idx / uniforms.N;\n let n = global_idx % uniforms.N;\n\n var value = ${u}(0);\n for (var k: u32 = 0u; k < uniforms.K; k++) {\n ${i}\n }\n\n ${r}\n ${null!=h?`let cOffset = ${h.broadcastedIndicesToOffset("vec2(m, n)",c)}; value += ${u}(uniforms.beta) * ${h.getByOffset("cOffset")};`:""}\n output[global_idx] = value;\n }`}}},so=t=>({transA:t.transA,transB:t.transB,alpha:t.alpha,beta:t.beta,cacheKey:`${t.transA};${t.transB};${1===t.alpha}`}),oo=(t,e)=>{io(t.inputs),t.compute(ro(t.inputs,e))}})),sh=V((()=>{gu(),Mu(),Su(),ku(),Tu(),Eu(),Cu(),ao=(t,e)=>t.length>e&&t[e].dims.length>0&&Se.size(t[e].dims)>0?t[e]:void 0,uo=(t,e)=>{let n=t[0],i=ao(t,1),r=ao(t,2),s=ao(t,3),o=ao(t,4),a=ao(t,5),u=ao(t,6),h=ao(t,7);if(3!==n.dims.length&&5!==n.dims.length)throw new Error("Input query is expected to have 3 or 5 dimensions");let l,c=n.dims[0],f=n.dims[1],d=3===n.dims.length?n.dims[2]:e.numHeads*n.dims[4],p=f,v=0,m=0,y=Math.floor(d/e.numHeads);if(u&&h){if(4!==u.dims.length)throw new Error('Input "past_key" is expected to have 4 dimensions');if(u.dims[0]!==c||u.dims[1]!==e.numHeads||u.dims[3]!==y)throw new Error('Input "past_key" shape (batch_size, num_heads, past_sequence_length, head_size)');if(h.dims[0]!==c||h.dims[1]!==e.numHeads||h.dims[3]!==y)throw new Error('Input "past_value" shape (batch_size, num_heads, past_sequence_length, head_size)');if(u.dims[2]!==h.dims[2])throw new Error('Input "past_key" and "past_value" shall have same dim 2 (past_sequence_length)');if(4!==h.dims.length)throw new Error('Input "past_value" is expected to have 4 dimensions');v=u.dims[2],m=u.dims[2]}else if(u||h)throw new Error('Input "past_key" and "past_value" shall be both present or both absent');if(i){if(3!==n.dims.length)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(i.dims.length<3||i.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(n.dims[0]!==i.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(3===i.dims.length){if(i.dims[2]!==n.dims[2])throw new Error('Input "query" and "key" shall have same dim 2 (hidden_size)');l=2,p=i.dims[1]}else if(5===i.dims.length){if(i.dims[2]!==e.numHeads||2!==i.dims[3]||i.dims[4]!==y)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(r)throw new Error('Expect "value" be none when "key" has packed kv format.');l=5,p=i.dims[1]}else{if(i.dims[1]!==e.numHeads||i.dims[3]!==y)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');l=0,p=i.dims[2]}}else{if(3!==n.dims.length&&5!==n.dims.length)throw new Error('Input "query" is expected to have 3 or 5 dimensions when key is empty');if(5===n.dims.length&&(n.dims[2]!==e.numHeads||3!==n.dims[3]))throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');l=3}if(s){if(1!==s.dims.length)throw new Error('Input "bias" is expected to have 1 dimension');if(r&&5===n.dims.length&&2===n.dims[3])throw new Error("bias is not allowed for packed kv.")}let w=0;if(o){w=8;let t=o.dims;throw 1===t.length?t[0]===c?w=1:t[0]===3*c+2&&(w=3):2===t.length&&t[0]===c&&t[1]===p&&(w=5),8===w?new Error('Input "key_padding_mask" shape shall be (batch_size) or (batch_size, kv_sequence_length)'):new Error("Mask not supported")}let g=!1,b=d;if(r){if(3!==r.dims.length&&4!==r.dims.length)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(n.dims[0]!==r.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(3===r.dims.length){if(p!==r.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');b=r.dims[2]}else{if(p!==r.dims[2])throw new Error('Input "past_key" and "past_value" shall have the same dim 2 (kv_sequence_length)');b=r.dims[1]*r.dims[3],g=!0}}let _=v+p;if(o)throw new Error("Key padding mask is not supported");if(a){if(4!==a.dims.length)throw new Error('Input "relative_position_bias" is expected to have 4 dimensions');if(a.dims[0]!==c&&1!==a.dims[0]||a.dims[1]!==e.numHeads||a.dims[2]!==f||a.dims[3]!==_)throw new Error('Input "relative_position_bias" shape (batch_size, 1, sequence_length, kv_sequence_length)')}return{batchSize:c,sequenceLength:f,pastSequenceLength:v,kvSequenceLength:p,totalSequenceLength:_,maxSequenceLength:m,inputHiddenSize:0,hiddenSize:d,vHiddenSize:b,headSize:y,vHeadSize:Math.floor(b/e.numHeads),numHeads:e.numHeads,isUnidirectional:!1,pastPresentShareBuffer:!1,maskFilterValue:e.maskFilterValue,maskType:w,scale:e.scale,broadcastResPosBias:!1,passPastInKv:g,qkvFormat:l}},ho=t=>xe({...t}),lo=xe({perm:[0,2,1,3]}),co=(t,e,n,i,r,s,o)=>{let a=[i,r,s],u=Se.size(a),h=[{type:12,data:u},{type:12,data:o},{type:12,data:s}];return t.compute({name:"MultiHeadAttentionAddBias",shaderCache:{inputDependencies:["type","type"]},getRunData:()=>({outputs:[{dims:a,dataType:e.dataType,gpuDataType:0}],dispatchGroup:{x:Math.ceil(u/64)},programUniforms:h}),getShaderSource:t=>{let i=Be("qkv_with_bias",e.dataType,a),r=je("qkv",e.dataType,a),s=je("bias",n.dataType,a);return`\n ${t.registerUniforms([{name:"output_size",type:"u32"},{name:"bias_offset",type:"u32"},{name:"hidden_size",type:"u32"}]).declareVariables(r,s,i)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n let bias_offset_idx = (global_idx % uniforms.hidden_size) + uniforms.bias_offset;\n\n qkv_with_bias[global_idx] = qkv[global_idx] + bias[bias_offset_idx];\n }`}},{inputs:[e,n],outputs:[-1]})[0]},fo=(t,e,n,i,r,s,o,a)=>{let u=s;if(o){if(1===i)throw new Error("AddBiasReshape is not implemented. Please export your model with packed QKV or KV");return u=co(t,s,o,e,i,n*r,a),u=u.reshape([e,i,n,r]),t.compute(Qe(u,lo.perm),{inputs:[u],outputs:[-1]})[0]}return 3===s.dims.length&&(u=s.reshape([e,i,n,r])),t.compute(Qe(u,lo.perm),{inputs:[u],outputs:[-1]})[0]},po=(t,e)=>{let n=uo(t.inputs,e),i=t.inputs[0],r=ao(t.inputs,1),s=ao(t.inputs,2),o=ao(t.inputs,3),a=ao(t.inputs,4),u=ao(t.inputs,5),h=ao(t.inputs,6),l=ao(t.inputs,7);if(5===i.dims.length)throw new Error("Packed QKV is not implemented");if(5===r?.dims.length)throw new Error("Packed KV is not implemented");let c=r&&s&&4===r.dims.length&&4===s.dims.length,f=fo(t,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,i,o,0);if(c)return ni(t,f,r,s,a,void 0,h,l,u,n,e);if(!r||!s)throw new Error("key and value must be provided");let d=fo(t,n.batchSize,n.numHeads,n.kvSequenceLength,n.headSize,r,o,n.hiddenSize),p=fo(t,n.batchSize,n.numHeads,n.kvSequenceLength,n.vHeadSize,s,o,2*n.hiddenSize);ni(t,f,d,p,a,void 0,h,l,u,n,e)}})),oh=V((()=>{gu(),Mu(),Eu(),vo=t=>Array.from(t.getBigInt64Array(),Number),mo=t=>{if(!t||2!==t.length)throw new Error("Tile requires 2 inputs.");if(1!==t[0].dataType&&10!==t[0].dataType&&6!==t[0].dataType&&12!==t[0].dataType)throw new Error("Tile only support float, float16, int32, and uint32 data types");if(7!==t[1].dataType)throw new Error("Tile `repeats` input should be of int64 data type");if(1!==t[1].dims.length)throw new Error("Tile `repeats` input should be 1-D");if(vo(t[1]).length!==t[0].dims.length)throw new Error("Tile `repeats` input should have same number of elements as rank of input data tensor")},yo=(t,e)=>{let n=[];for(let i=0;i<t.length;++i)n.push(t[i]*e[i]);return n},wo=(t,e)=>{let n=t[0].dims,i=e??vo(t[1]),r=yo(n,i),s=Se.size(r),o=t[0].dataType,a=je("input",o,n.length),u=Be("output",o,r.length);return{name:"Tile",shaderCache:{hint:`${i}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:r,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(s/64)},programUniforms:[{type:12,data:s},...Re(t[0].dims,r)]}),getShaderSource:t=>`\n const inputShape = ${a.indices(...n)};\n ${t.registerUniform("output_size","u32").declareVariables(a,u)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n let output_indices = ${u.offsetToIndices("global_idx")};\n var input_indices: ${a.type.indices};\n for (var i = 0; i < ${n.length}; i++) {\n let input_dim_i = ${a.indicesGet("uniforms.input_shape","i")};\n let input_dim_value = ${u.indicesGet("output_indices","i")} % input_dim_i;\n\n ${a.indicesSet("input_indices","i","input_dim_value")}\n }\n ${u.setByOffset("global_idx",a.getByIndices("input_indices"))}\n }`}},go=t=>{mo(t.inputs),t.compute(wo(t.inputs),{inputs:[0]})}})),ah=V((()=>{gu(),Mu(),Su(),Tu(),Eu(),sh(),oh(),Cu(),bo=(t,e)=>{let n=t[0],i=t[1],r=t[2],s=t[3],o=t[4];if(3!==n.dims.length&&5!==n.dims.length)throw new Error("Input query is expected to have 3 or 5 dimensions");let a,u=n.dims[0],h=n.dims[1],l=3===n.dims.length?n.dims[2]:e.numHeads*n.dims[4],c=h,f=0,d=0,p=Math.floor(l/e.numHeads),v=s&&0!==s.dims.length,m=o&&0!==o.dims.length;if(v&&m){if(4!==s.dims.length)throw new Error('Input "past_key" is expected to have 4 dimensions');if(4!==o.dims.length)throw new Error('Input "past_value" is expected to have 4 dimensions');f=s.dims[1],d=s.dims[1]}else if(v||m)throw new Error('Input "past_key" and "past_value" shall be both present or both absent');if(i){if(3!==n.dims.length)throw new Error('Input "query" is expected to have 3 dimensions when key is given');if(i.dims.length<3||i.dims.length>5)throw new Error('Input "key" is expected to have 3, 4, or 5 dimensions');if(n.dims[0]!==i.dims[0])throw new Error('Input "query" and "key" shall have same dim 0 (batch size)');if(3===i.dims.length){if(n.dims[2]%i.dims[2]!=0)throw new Error('Dimension 2 of "query" should be a multiple of "key"');a=2,c=i.dims[1]}else if(5===i.dims.length){if(i.dims[2]!==e.numHeads||2!==i.dims[3]||i.dims[4]!==p)throw new Error('Expect "key" shape (batch_size, kv_sequence_length, num_heads, 2, head_size) for packed kv');if(r)throw new Error('Expect "value" be none when "key" has packed kv format.');a=5,c=i.dims[1]}else{if(i.dims[1]!==e.numHeads||i.dims[3]!==p)throw new Error('Expect "key" shape (batch_size, num_heads, kv_sequence_length, head_size) for past_key');a=0,c=i.dims[2]}}else{if(3!==n.dims.length&&5!==n.dims.length)throw new Error('Input "query" is expected to have 3 or 5 dimensions when key is empty');if(5===n.dims.length&&(n.dims[2]!==e.numHeads||3!==n.dims[3]))throw new Error('Expect "query" shape (batch_size, kv_sequence_length, num_heads, 3, head_size) for packed kv');a=3}let y=!1,w=l;if(r){if(3!==r.dims.length&&4!==r.dims.length)throw new Error('Input "value" is expected to have 3 or 4 dimensions');if(n.dims[0]!==r.dims[0])throw new Error('Input "query" and "value" shall have same dim 0 (batch_size)');if(3===r.dims.length){if(c!==r.dims[1])throw new Error('Input "key" and "value" shall have the same dim 1 (kv_sequence_length)');w=r.dims[2]}else{if(c!==r.dims[2])throw new Error('Input "past_key" and "past_value" shall have the same dim 2 (kv_sequence_length)');w=r.dims[1]*r.dims[3],y=!0}}return{batchSize:u,sequenceLength:h,pastSequenceLength:f,kvSequenceLength:c,totalSequenceLength:f+c,maxSequenceLength:d,inputHiddenSize:0,hiddenSize:l,vHiddenSize:w,headSize:p,vHeadSize:Math.floor(w/e.kvNumHeads),numHeads:e.numHeads,kvNumHeads:e.kvNumHeads,nReps:e.numHeads/e.kvNumHeads,pastPresentShareBuffer:!1,maskType:0,scale:e.scale,broadcastResPosBias:!1,passPastInKv:y,qkvFormat:a,isPastkvBSNH:!0}},_o=(t,e,n,i)=>{let r=[i.batchSize,i.totalSequenceLength,i.kvNumHeads,i.headSize],s=Se.size(r)/4,o=i.totalSequenceLength,a=Be("present_kv",n,r.length,4),u=je("new_kv",t.dataType,t.dims.length,4),h=e?je("past_kv",e.dataType,e.dims.length,4):void 0,l=Math.ceil(i.headSize/4),c={x:o,y:t.dims[0],z:1},f=e?["rank","rank"]:["rank"],d=[{type:12,data:s},{type:12,data:i.pastSequenceLength},{type:12,data:i.kvSequenceLength},{type:12,data:i.totalSequenceLength}],p=[u];h?(d.push(...Re(t.dims),...Re(e.dims),...Re(r)),p.push(h)):d.push(...Re(t.dims),...Re(r));let v=[{name:"output_size",type:"u32"},{name:"past_seqlen",type:"u32"},{name:"new_seqlen",type:"u32"},{name:"present_seqlen",type:"u32"}],m=" let new_batch_stride = uniforms.new_seqlen * num_heads * H;\n let new_row_stride = num_heads * H;\n let new_head_stride = H;\n let in_offset = b * new_batch_stride + (s - past_seqlen) * new_row_stride + n * new_head_stride + h;\n present_kv[out_offset] = new_kv[in_offset];",y=e?`if (s < past_seqlen) {\n let past_batch_stride = uniforms.past_seqlen * num_heads * H;\n var past_head_stride = uniforms.past_seqlen * H;\n if (is_bsnh) {\n past_head_stride = H;\n }\n let in_offset = b * past_batch_stride + s * row_stride + n * past_head_stride + h;\n present_kv[out_offset] = past_kv[in_offset];\n } else if (s < past_seqlen + uniforms.new_seqlen) {\n ${m}\n }`:`if (s < past_seqlen + uniforms.new_seqlen) {\n ${m}\n }`;return{name:"ConcatPastNew",shaderCache:{hint:`${i.kvNumHeads}${l}${!!e}`,inputDependencies:f},getRunData:()=>({outputs:[{dims:r,dataType:n}],dispatchGroup:c,programUniforms:d}),getShaderSource:t=>`\n\n ${t.registerUniforms(v).declareVariables(...p,a)}\n ${t.mainStart([l,i.kvNumHeads,1])}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n var indices = ${a.offsetToIndices("global_idx")};\n let h = local_id.x;\n let n = local_id.y;\n let s = workgroup_id.x;\n let b = workgroup_id.y;\n let num_heads = ${i.kvNumHeads}u;\n let H = ${l}u;\n\n let present_seqlen = uniforms.present_seqlen;\n let present_batch_stride = present_seqlen * num_heads * H;\n var row_stride = H;\n let is_bsnh = ${i.isPastkvBSNH};\n\n if (is_bsnh) {\n row_stride = num_heads * H;\n }\n var present_head_stride = present_seqlen * H;\n if (is_bsnh) {\n present_head_stride = H;\n }\n\n let past_seqlen = uniforms.past_seqlen;\n\n let out_offset = b * present_batch_stride + s * row_stride + n * present_head_stride + h;\n ${y}\n }`}},xo=t=>xe({...t}),ko=xe({perm:[0,2,1,3]}),$o=(t,e,n,i,r)=>{let s=e,o=i.kvNumHeads,a=i.nReps;return 3===e.dims.length&&0!==i.kvSequenceLength&&(s=e.reshape([i.batchSize,i.kvSequenceLength,o,i.headSize])),s=n?t.compute(_o(s,n,s.dataType,i),{inputs:[s,n],outputs:[i.isPastkvBSNH?r:-1]})[0]:t.compute(_o(s,void 0,s.dataType,i),{inputs:[s],outputs:[i.isPastkvBSNH?r:-1]})[0],1!==a&&(s=t.compute(wo([s],[1,1,1,a]),{inputs:[s],outputs:[-1]})[0],s=s.reshape([i.batchSize,i.totalSequenceLength,o*a,i.headSize])),t.compute(Qe(s,ko.perm),{inputs:[s],outputs:[-1]})[0]},So=(t,e)=>{let n=bo(t.inputs,e);if(5===t.inputs[0].dims.length)throw new Error("Packed QKV is not implemented");if(5===t.inputs[1]?.dims.length)throw new Error("Packed KV is not implemented");let i=fo(t,n.batchSize,n.numHeads,n.sequenceLength,n.headSize,t.inputs[0],void 0,0),r=t.inputs[3]&&0!==t.inputs[3].dims.length?t.inputs[3]:void 0,s=t.inputs[4]&&0!==t.inputs[4].dims.length?t.inputs[4]:void 0,o=$o(t,t.inputs[1],r,n,1),a=$o(t,t.inputs[2],s,n,2);ni(t,i,o,a,void 0,void 0,void 0,void 0,void 0,n,e)}})),uh=V((()=>{gu(),Mu(),Eu(),Mo=(t,e)=>{let n=t[0].dims,i=n,r=Se.sizeToDimension(n,2),s=Se.sizeFromDimension(n,2),o=Fe(s),a=s/o,u=[n[0],n[1],a],h=[{type:12,data:s},{type:12,data:a}];return h.push(...Re(u,u)),{name:"InstanceNormalization",shaderCache:{hint:`${e.epsilon};${o}`,inputDependencies:["rank","type","type"]},getRunData:()=>({outputs:[{dims:i,dataType:t[0].dataType}],dispatchGroup:{x:r},programUniforms:h}),getShaderSource:n=>{let i=je("x",t[0].dataType,u.length,o),r=je("scale",t[1].dataType,t[1].dims),s=je("bias",t[2].dataType,t[2].dims),a=Be("output",t[0].dataType,u.length,o),h=[i,r,s,a],l=i.type.value,c=1===o?"f32":`vec${o}<f32>`;return`\n var<workgroup> meanShared : f32;\n var<workgroup> squaredNormShared : f32;\n var<workgroup> workgroupShared : array<${c}, 64>;\n const workgroupSize = 64u;\n ${n.registerUniforms([{name:"normSize",type:"u32"},{name:"normPackedSize",type:"u32"}]).declareVariables(...h)}\n ${n.mainStart(64)}\n let norm = global_idx / workgroupSize;\n let batch = norm / uniforms.x_shape[1];\n let channel = norm % uniforms.x_shape[1];\n let localIndex = local_id.x;\n\n // initialize workgroup memory\n var initial = ${c}(0);\n for (var h = localIndex; h < uniforms.normPackedSize; h += workgroupSize) {\n initial = initial + ${c}(${i.get("batch","channel","h")});\n }\n workgroupShared[localIndex] = initial;\n workgroupBarrier();\n\n // Calculate the mean of current channel data.\n for (var currSize = workgroupSize >> 1; currSize > 0; currSize = currSize >> 1) {\n if (localIndex < currSize) {\n workgroupShared[localIndex] = workgroupShared[localIndex] + workgroupShared[localIndex + currSize];\n }\n workgroupBarrier();\n }\n if (localIndex == 0) {\n meanShared = ${Ne("workgroupShared[0]",o)} / f32(uniforms.normSize);\n }\n workgroupBarrier();\n\n // reinitialize workgroup memory.\n initial = ${c}(0);\n for (var h = localIndex; h < uniforms.normPackedSize; h += workgroupSize) {\n let deviation = ${c}(${i.get("batch","channel","h")}) - ${c}(meanShared);\n initial = initial + deviation * deviation;\n }\n workgroupShared[localIndex] = initial;\n workgroupBarrier();\n\n // Calculate the sum of square of deviation of current channel data.\n for (var currSize = workgroupSize >> 1; currSize > 0; currSize = currSize >> 1) {\n if (localIndex < currSize) {\n workgroupShared[localIndex] = workgroupShared[localIndex] + workgroupShared[localIndex + currSize];\n }\n workgroupBarrier();\n }\n if (localIndex == 0) {\n squaredNormShared = ${Ne("workgroupShared[0]",o)};\n }\n workgroupBarrier();\n\n let invStdDev = inverseSqrt(squaredNormShared / f32(uniforms.normSize) + f32(${e.epsilon}));\n let channelScale = invStdDev * f32(${r.getByOffset("channel")});\n let channelShift = f32(${s.getByOffset("channel")}) - meanShared * channelScale;\n for (var h = localIndex; h < uniforms.normPackedSize; h += workgroupSize) {\n let value = ${i.get("batch","channel","h")} * ${l}(${c}(channelScale)) + ${l}(${c}(channelShift));\n ${a.set("batch","channel","h","value")};\n }\n }`}}},Eo=(t,e,n,i,r,s,o,a)=>{let u=Fe(o),h=1===u?"vec2f":`mat2x${u}f`,l=1===u?"f32":`vec${u}f`,c=(t,e)=>`${h}(${t}, ${e})`,f=r*o/u,d=[{type:12,data:Math.ceil(s/64)},{type:12,data:s},{type:12,data:Math.floor(o/u)},{type:12,data:Math.floor(s*o/u)}],p=t.compute({name:"InstanceNormComputeMean",shaderCache:{hint:`${u}`,inputDependencies:["type"]},getRunData:()=>({outputs:[{dims:[r,o,64,2],dataType:1}],dispatchGroup:{x:r*o/u},programUniforms:d}),getShaderSource:t=>{let n=je("input",e.dataType,e.dims,u);return`\n ${t.declareVariables(n)}\n @group(0) @binding(1) var<storage, read_write> output : array<${h}>;\n struct Uniforms {wg_size:u32, H:u32, C:u32, image_size:u32};\n @group(0) @binding(2) var<uniform> uniforms: Uniforms;\n\n ${t.mainStart(64)}\n let currentImageNumber = global_idx / 64 / uniforms.C;\n let currentChannelNumber = (global_idx / 64) % uniforms.C;\n let wgOffset = local_id.x * uniforms.wg_size;\n if (wgOffset >= uniforms.H) {\n return;\n }\n let wgMax = min(wgOffset + uniforms.wg_size, uniforms.H);\n\n let offset = currentImageNumber * uniforms.image_size + currentChannelNumber;\n var sum = ${Pe("f32",u)};\n var squaredSum = ${Pe("f32",u)};\n for (var i: u32 = wgOffset; i < wgMax; i++) {\n let value = ${l}(input[offset + i * uniforms.C]);\n sum += value;\n squaredSum += value * value;\n }\n output[global_idx] = ${c("sum","squaredSum")};\n }`}},{inputs:[e],outputs:[-1]})[0],v=[{type:12,data:f},{type:12,data:s},{type:12,data:Math.floor(o/u)},{type:12,data:Math.floor(64*o/u)}];return t.compute({name:"InstanceNormComputeChannelScaleShift",shaderCache:{hint:`${u};${a}`,inputDependencies:["type","type","type"]},getRunData:()=>({outputs:[{dims:[r,o,2],dataType:1}],dispatchGroup:{x:Math.ceil(f/64)},programUniforms:v}),getShaderSource:t=>{let e=je("scale",n.dataType,n.dims,u),r=je("bias",i.dataType,i.dims,u);return`\n @group(0) @binding(0) var<storage, read> input : array<${h}>;\n @group(0) @binding(1) var<storage, read> scale : array<${e.type.storage}>;\n @group(0) @binding(2) var<storage, read> bias : array<${r.type.storage}>;\n @group(0) @binding(3) var<storage, read_write> output : array<${h}>;\n struct Uniforms {units_of_work : u32, H: u32, C : u32, image_size : u32};\n @group(0) @binding(4) var<uniform> uniforms: Uniforms;\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.units_of_work")}\n let currentImageNumber = global_idx / uniforms.C;\n let currentChannelNumber = global_idx % uniforms.C;\n\n let offset = currentImageNumber * uniforms.image_size;\n var sum = ${Pe("f32",u)};\n var squaredSum = ${Pe("f32",u)};\n for (var i: u32 = 0; i < min(64, uniforms.H); i++) {\n let value = input[offset + i + currentChannelNumber * 64];\n sum += value[0];\n squaredSum += value[1];\n }\n sum = sum / f32(uniforms.H);\n squaredSum = squaredSum / f32(uniforms.H);\n let invStdDev = inverseSqrt(squaredSum - sum * sum + f32(${a}));\n let channelScale = invStdDev * ${l}(scale[currentChannelNumber]);\n let channelShift = ${l}(bias[currentChannelNumber]) - sum * channelScale;\n\n output[global_idx] = ${c("channelScale","channelShift")};\n }`}},{inputs:[p,n,i],outputs:[-1]})[0]},Co=(t,e,n)=>{let i=e[0].dims,r=i,s=i[0],o=i[i.length-1],a=Se.sizeFromDimension(i,1)/o,u=Fe(o),h=Se.size(r)/u,l=[{type:12,data:a},{type:12,data:Math.floor(o/u)}],c=Eo(t,e[0],e[1],e[2],s,a,o,n.epsilon);t.compute({name:"InstanceNormalizationNHWC",shaderCache:{hint:`${u}`,inputDependencies:["type","type"]},getRunData:()=>({outputs:[{dims:r,dataType:e[0].dataType}],dispatchGroup:{x:Math.ceil(h/64)},programUniforms:l}),getShaderSource:t=>{let n=Te(e[0].dataType),i=1===u?"vec2f":`mat2x${u}f`,s=1===u?n:`vec${u}<${n}>`,o=je("input",e[0].dataType,e[0].dims,u),a=Be("output",e[0].dataType,r,u);return`\n @group(0) @binding(0) var<storage, read> input : array<${o.type.storage}>;\n @group(0) @binding(1) var<storage, read> scaleInput : array<${i}>;\n @group(0) @binding(2) var<storage, read_write> output : array<${a.type.storage}>;\n struct Uniforms {H: u32, C : u32};\n @group(0) @binding(3) var<uniform> uniforms: Uniforms;\n\n ${t.mainStart()}\n let currentImageNumber = global_idx / (uniforms.C * uniforms.H);\n let currentChannelNumber = global_idx % uniforms.C;\n\n let scaleOffset = currentImageNumber * uniforms.C + currentChannelNumber;\n let scale = scaleInput[scaleOffset];\n output[global_idx] = fma(input[global_idx], ${s}(scale[0]), ${s}(scale[1]));\n }`}},{inputs:[e[0],c]})},Ao=(t,e)=>{"NHWC"===e.format?Co(t,t.inputs,e):t.compute(Mo(t.inputs,e))}})),hh=V((()=>{gu(),Mu(),Eu(),Oo=t=>{if(!t||t.length<2)throw new Error("layerNorm requires at least 2 inputs.")},Io=(t,e,n)=>{let i=e.simplified,r=t[0].dims,s=t[1],o=!i&&t[2],a=r,u=Se.normalizeAxis(e.axis,r.length),h=Se.sizeToDimension(r,u),l=Se.sizeFromDimension(r,u),c=Se.size(s.dims),f=o?Se.size(o.dims):0;if(c!==l||o&&f!==l)throw new Error(`Size of X.shape()[axis:] == ${l}.\n Size of scale and bias (if provided) must match this.\n Got scale size of ${c} and bias size of ${f}`);let d=[];for(let t=0;t<r.length;++t)t<u?d.push(r[t]):d.push(1);let p=Fe(l),v=["type","type"],m=[{type:12,data:h},{type:1,data:l},{type:12,data:Math.floor(l/p)},{type:1,data:e.epsilon}];o&&v.push("type");let y=n>1,w=n>2,g=[{dims:a,dataType:t[0].dataType}];return y&&g.push({dims:d,dataType:1}),w&&g.push({dims:d,dataType:1}),{name:"LayerNormalization",shaderCache:{hint:`${p};${n};${i}`,inputDependencies:v},getRunData:()=>({outputs:g,dispatchGroup:{x:Math.ceil(h/64)},programUniforms:m}),getShaderSource:e=>{let n=Te(t[0].dataType),r=[je("x",t[0].dataType,t[0].dims,p),je("scale",s.dataType,s.dims,p)];return o&&r.push(je("bias",o.dataType,o.dims,p)),r.push(Be("output",t[0].dataType,a,p)),y&&r.push(Be("mean_data_output",1,d)),w&&r.push(Be("inv_std_output",1,d)),`\n ${e.registerUniforms([{name:"norm_count",type:"u32"},{name:"norm_size",type:"f32"},{name:"norm_size_vectorized",type:"u32"},{name:"epsilon",type:"f32"}]).declareVariables(...r)}\n ${e.mainStart()}\n ${e.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.norm_count")}\n let offset = global_idx * uniforms.norm_size_vectorized;\n var mean_vector = ${Pe("f32",p)};\n var mean_square_vector = ${Pe("f32",p)};\n\n for (var h: u32 = 0u; h < uniforms.norm_size_vectorized; h++) {\n let value = ${De(n,p,"x[h + offset]")};\n mean_vector += value;\n mean_square_vector += value * value;\n }\n let mean = ${Ne("mean_vector",p)} / uniforms.norm_size;\n let inv_std_dev = inverseSqrt(${Ne("mean_square_vector",p)} / uniforms.norm_size ${i?"":"- mean * mean"} + uniforms.epsilon);\n\n for (var j: u32 = 0; j < uniforms.norm_size_vectorized; j++) {\n let f32input = ${De(n,p,"x[j + offset]")};\n let f32scale = ${De(n,p,"scale[j]")};\n output[j + offset] = ${r[0].type.value}((f32input ${i?"":"- mean"}) * inv_std_dev * f32scale\n ${o?`+ ${De(n,p,"bias[j]")}`:""}\n );\n }\n\n ${y?"mean_data_output[global_idx] = mean":""};\n ${w?"inv_std_output[global_idx] = inv_std_dev":""};\n }`}}},To=(t,e)=>{Oo(t.inputs),t.compute(Io(t.inputs,e,t.outputCount))}})),lh=V((()=>{gu(),Mu(),Su(),Eu(),zo=(t,e)=>{if(t.length<3||t.length>4)throw new Error("MatMulNBits requires 3 or 4 inputs");let n=t[0],i=n.dims.length;if(n.dims[i-1]!==e.k)throw new Error("The last dim of input shape does not match the k value");let r=Math.floor((e.k+e.blockSize-1)/e.blockSize),s=e.blockSize/8*e.bits,o=t[1];if(!Se.areEqual(o.dims,[e.n,r,s]))throw new Error("The second inputs must be 3D tensor with shape N X nBlocksPerCol X blobSize");let a=t[2].dims;if(Se.size(a)!==e.n*r)throw new Error("scales input size error.");if(4===t.length){let n=t[3].dims,i=e.bits>4?e.n*r:e.n*Math.floor((r+1)/2);if(Se.size(n)!==i)throw new Error("zeroPoints input size error.")}},Ro=(t,e,n,i)=>{let r=t[0].dims,s=r.length,o=Math.floor((e.k+e.blockSize-1)/e.blockSize),a=r[s-2],u=e.k,h=e.n,l=r.slice(0,s-2),c=Se.size(l),f=e.blockSize/8*e.bits/4,d=t[0].dataType,p=Fe(a),v=Fe(e.k),m=Fe(f),y=te(d),w=a*o*y,g=Math.floor(i/w),b=o<=n[0]&&g>0,_=!b||g>=4?Fe(h):g>=2&&Fe(h)>=2?2:1,x=l.concat([a,h]),k=Se.size(x)/_/p,$=b?[]:[{type:12,data:k},{type:12,data:e.blockSize}],S=[c,a,u/v],M=Se.convertShape(t[1].dims).slice();M.splice(-1,1,f/m),$.push(...Re(S)),$.push(...Re(M)),$.push(...Re(t[2].dims)),4===t.length&&$.push(...Re(Se.convertShape(t[3].dims)));let E=[c,a,h/_];return $.push(...Re(E)),{name:b?"BlockwiseMatMulNBits":"MatMulNBits",shaderCache:{hint:`${e.cacheKey};${a};${d};${t.length}`,inputDependencies:Array(t.length).fill("rank")},getRunData:()=>({outputs:[{dims:x,dataType:d}],name:b?"BlockwiseMatMulNBits":"MatMulNBits",dispatchGroup:b?{x:1,y:Math.ceil(h/_),z:c}:{x:Math.ceil(k/64)},programUniforms:$}),getShaderSource:n=>{let i=S.length,r=je("a",t[0].dataType,i,v),s=je("b",12,M.length,m),u=je("scales",t[2].dataType,t[2].dims.length),l=[r,s,u],c=4===t.length?je("zero_points",12,t[3].dims.length):void 0;c&&l.push(c);let d=E.length,y=Be("output",t[0].dataType,d,_),w=Te(t[0].dataType),g=(()=>{switch(v){case 1:return`array<${w}, 8>`;case 2:return`mat4x2<${w}>`;case 4:return`mat2x4<${w}>`;default:throw new Error(`${v}-component is not supported.`)}})(),x=`\n for (var word: u32 = 0; word < ${f}; word += ${m}) {\n ${s.indicesSet("b_indices","2","word")};\n let b_data = ${s.getByIndices("b_indices")};\n for (var i: u32 = 0; i < ${m}; i++) {\n let b_value: u32 = ${1===m?"b_data":"b_data[word + i]"};\n let b_mask: u32 = 0x0F0F0F0Fu;\n let b_value_lower: vec4<u32> = unpack4xU8(b_value & b_mask);\n let b_value_upper: vec4<u32> = unpack4xU8((b_value >> 4) & b_mask);\n let b_quantized_values = ${g}(${Array.from({length:4},((t,e)=>`${w}(b_value_lower[${e}]), ${w}(b_value_upper[${e}])`)).join(", ")});\n let b_dequantized_values = ${1===v?`${g}(${Array.from({length:8},((t,e)=>`(b_quantized_values[${e}] - zero_point) * scale`)).join(", ")});`:`(b_quantized_values - ${g}(${Array(8).fill("zero_point").join(",")})) * scale;`};\n // Number of B elements per 32-bit word is 32/bits = 32/4 = 8\n for (var m: u32 = 0; m < ${b?a:p}u; m++) {\n ${r.indicesSet("a_indices",i-2,b?"m":`row * ${p} + m`)};\n ${r.indicesSet("a_indices",i-1,"word_offset")};\n var input_offset = ${r.indicesToOffset("a_indices")};\n var a_data: ${g};\n for (var j: u32 = 0; j < ${8/v}; j++) {\n a_data[j] = ${r.getByOffset("input_offset")};\n input_offset++;\n }\n ${b?"workgroup_shared[workgroup_shared_offset + m]":"output_values[m]"}${_>1?"[c]":""} += ${Array.from({length:8/v},((t,e)=>1===v?`a_data[${e}] * b_dequantized_values[${e}]`:`dot(a_data[${e}], b_dequantized_values[${e}])`)).join(" + ")};\n }\n word_offset += ${8/v};\n }\n }`,k=c?`\n zero_point_offset += 4;\n if (zero_point_offset == 32) {\n zero_point_offset = 0;\n zero_point_index++;\n zero_point_word = ${c.getByOffset("zero_point_index")};\n }`:"";return b?`\n var<workgroup> workgroup_shared: array<${y.type.value}, ${a*o}>;\n ${n.declareVariables(...l,y)}\n ${n.mainStart([o,1,1])}\n var a_indices: ${r.type.indices};\n var block = local_id.x;\n var col = workgroup_id.y;\n var batch = workgroup_id.z;\n ${r.indicesSet("a_indices","0","batch")};\n // Two zero points are packed into one byte when uniforms.bits is 4.\n for (var c: u32 = 0; c < ${_}; c++) {\n let col_times_components_plus_c = col * ${_} + c;\n ${c?`\n var zero_point_bytes_per_col: u32 = (${o} + 1) / 2;\n var zero_point_byte_count: u32 = col_times_components_plus_c * zero_point_bytes_per_col + (block >> 0x1u);\n var zero_point_word_index: u32 = zero_point_byte_count >> 0x2u;\n var zero_point_byte_offset: u32 = zero_point_byte_count & 0x3u;\n var zero_point_nibble_offset: u32 = block & 0x1u;\n var zero_point_bits_offset: u32 = (zero_point_byte_offset << 3) + (zero_point_nibble_offset << 2);\n var zero_point_word: u32 = ${c.getByOffset("zero_point_word_index")} >> zero_point_bits_offset;`:""}\n var b_indices: ${s.type.indices};\n ${s.indicesSet("b_indices","0","col_times_components_plus_c")};\n // The scale and zero points are computed per block.\n var scales_index = col_times_components_plus_c * ${o} + block;\n let scale = ${u.getByOffset("scales_index")};\n // The default zero point is 8 for unsigned 4-bit quantization.\n let zero_point = ${w}(${c?"(zero_point_word) & 0xFu":8});\n ${s.indicesSet("b_indices","1","block")};\n var word_offset: u32 = block * ${e.blockSize/v};\n var workgroup_shared_offset: u32 = block * ${a};\n ${x}\n }\n workgroupBarrier();\n var output_indices: ${y.type.indices};\n var elements_per_thread: u32 = ${Math.ceil(a/o)};\n ${y.indicesSet("output_indices","0","batch")};\n ${y.indicesSet("output_indices",d-1,"col")};\n ${y.indicesSet("output_indices",d-2,"local_id.x * elements_per_thread")};\n var output_offset = ${y.indicesToOffset("output_indices")};\n for (var m: u32 = 0u; m < elements_per_thread; m++) {\n var row = m + local_id.x * elements_per_thread;\n if (row < ${a}) {\n var output_value: ${y.type.value} = ${y.type.value}(0);\n var workgroup_shared_offset: u32 = row;\n for (var b: u32 = 0u; b < ${o}u; b++) {\n output_value += workgroup_shared[workgroup_shared_offset];\n workgroup_shared_offset += ${a};\n }\n ${y.setByOffset("output_offset","output_value")};\n output_offset += ${h/_};\n }\n }\n }`:`\n ${n.registerUniforms([{name:"output_size",type:"u32"},{name:"block_size",type:"u32"}]).declareVariables(...l,y)}\n ${n.mainStart()}\n ${n.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n var output_values: array<${y.type.value}, ${p}>;\n var output_indices = ${y.offsetToIndices("global_idx")};\n var col = ${y.indicesGet("output_indices",d-1)};\n var row = ${y.indicesGet("output_indices",d-2)};\n var a_indices: ${r.type.indices} = output_indices;\n // Two zero points are packed into one byte because uniforms.bits <= 4.\n // zero_point_offset is either 0 or 4. It is bit offset within one byte.\n // TODO support zero_point_offset for bits > 4\n ${c?`\n var zero_point_abs_offset = col * ${_} * ((${o} + 1) / 2);\n var zero_point_index: u32 = zero_point_abs_offset / 4;\n var zero_point_word: u32 = ${c.getByOffset("zero_point_index")};\n var zero_point_offset: u32 = (zero_point_abs_offset % 4) * 8;`:""}\n var scale_index = col * ${o*_};\n var b_indices: ${s.type.indices};\n for (var c: u32 = 0; c < ${_}; c++) {\n ${s.indicesSet("b_indices","0",`col * ${_} + c`)};\n var block_offset: u32 = 0;\n for (var block: u32 = 0; block < ${o}; block++) {\n // The scale and zero points are computed per block.\n let scale = ${u.getByOffset("scale_index")};\n // The default zero point is 8 for unsigned 4-bit quantization.\n let zero_point = ${w}(${c?"extractBits(zero_point_word, zero_point_offset, 4)":8});\n ${s.indicesSet("b_indices","1","block")};\n var word_offset: u32 = block_offset;\n ${x}\n scale_index++;\n ${k}\n block_offset += uniforms.block_size / ${v};\n }\n // Drop the trailing 4 bits if the zero_poit_offset is not a byte boundary to align with the next byte.\n ${c?`if (zero_point_offset % 8 > 0) {\n ${k}\n }`:""}\n }\n for (var k: u32 = 0u; k < ${p}u; k++) {\n ${y.indicesSet("output_indices",d-2,`${p} * row + k`)};\n ${y.setByIndices("output_indices","output_values[k]")}\n }\n }`}}},Fo=(t,e)=>{zo(t.inputs,e);let n=t.getMaxComputeWorkgroupSizes(),i=t.getMaxComputeWorkgroupStoragesize();t.compute(Ro(t.inputs,e,n,i))},Po=t=>xe(t)})),ch=V((()=>{gu(),Mu(),Eu(),Do=t=>{if(!t||t.length<1)throw new Error("Too few inputs");if(1!==t[0].dataType&&10!==t[0].dataType)throw new Error("Input type must be float or float16.");if(t.length>=2){let e=2*t[0].dims.length===t[1].dims[0];if(4===t.length&&(e=2*t[3].dims[0]===t[1].dims[0]),!e)throw new Error("The pads should be a 1D tensor of shape [2 * input_rank] or [2 * num_axes].")}},No=(t,e,n)=>{let i="";for(let r=e-1;r>=0;--r)i+=`\n k = i32(${t.indicesGet("indices",r)}) - ${Ue("uniforms.pads",r,n)};\n if (k < 0) {\n break;\n }\n if (k >= i32(${Ue("uniforms.x_shape",r,e)})) {\n break;\n }\n offset += k * i32(${Ue("uniforms.x_strides",r,e)});\n `;return`\n value = ${t.type.value}(uniforms.constant_value);\n for (var i = 0; i < 1; i++) {\n var offset = 0;\n var k = 0;\n ${i}\n value = x[offset];\n }\n `},Uo=(t,e,n)=>{let i="";for(let r=e-1;r>=0;--r)i+=`\n k = i32(${t.indicesGet("indices",r)}) - ${Ue("uniforms.pads",r,n)};\n if (k < 0) {\n k = -k;\n }\n {\n let _2n_1 = 2 * (i32(${Ue("uniforms.x_shape",r,e)}) - 1);\n k = k % _2n_1;\n if(k >= i32(${Ue("uniforms.x_shape",r,e)})) {\n k = _2n_1 - k;\n }\n }\n offset += k * i32(${Ue("uniforms.x_strides",r,e)});\n `;return`\n var offset = 0;\n var k = 0;\n ${i}\n value = x[offset];\n `},qo=(t,e,n)=>{let i="";for(let r=e-1;r>=0;--r)i+=`\n k = i32(${t.indicesGet("indices",r)}) - ${Ue("uniforms.pads",r,n)};\n if (k < 0) {\n k = 0;\n }\n if (k >= i32(${Ue("uniforms.x_shape",r,e)})) {\n k = i32(${Ue("uniforms.x_shape",r,e)}) - 1;\n }\n offset += k * i32(${Ue("uniforms.x_strides",r,e)});\n `;return`\n var offset = 0;\n var k = 0;\n ${i}\n value = x[offset];\n `},jo=(t,e,n)=>{let i="";for(let r=e-1;r>=0;--r)i+=`\n k = i32(${t.indicesGet("indices",r)}) - ${Ue("uniforms.pads",r,n)};\n if (k < 0) {\n k += i32(${Ue("uniforms.x_shape",r,e)}]);\n }\n if (k >= i32(${Ue("uniforms.x_shape",r,e)})) {\n k -= i32(${Ue("uniforms.x_shape",r,e)});\n }\n offset += k * i32(${Ue("uniforms.x_strides",r,e)});\n `;return`\n var offset = 0;\n var k = 0;\n ${i}\n value = x[offset];\n `},Bo=(t,e,n)=>{switch(n.mode){case 0:return No(t,e,n.pads.length);case 1:return Uo(t,e,n.pads.length);case 2:return qo(t,e,n.pads.length);case 3:return jo(t,e,n.pads.length);default:throw new Error("Invalid mode")}},Lo=(t,e)=>{let n=Se.padShape(t[0].dims.slice(),e.pads),i=t[0].dims,r=[{type:12,data:Se.size(n)},{type:6,data:e.pads}];return 0===e.mode&&r.push({type:t[0].dataType,data:e.value}),r.push(...Re(t[0].dims,n)),{name:"Pad",shaderCache:{hint:`${e.mode}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:n,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(Se.size(n)/64)},programUniforms:r}),getShaderSource:r=>{let s=Be("output",t[0].dataType,n.length),o=je("x",t[0].dataType,i.length),a=o.type.value,u=Bo(s,i.length,e),h=[{name:"output_size",type:"u32"},{name:"pads",type:"i32",length:e.pads.length}];return 0===e.mode&&h.push({name:"constant_value",type:a}),`\n ${r.registerUniforms(h).declareVariables(o,s)}\n ${r.mainStart()}\n ${r.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n\n let indices = ${s.offsetToIndices("global_idx")};\n\n var value = ${a}(0);\n ${u}\n output[global_idx] = value;\n }`}}},Ho=(t,e)=>{if(t.length>1){let n=t[1].getBigInt64Array(),i=t.length>=3&&t[2].data?t[2].getFloat32Array()[0]:0,r=t[0].dims.length,s=new Int32Array(2*r).fill(0);if(t.length>=4){let e=t[3].getBigInt64Array();for(let t=0;t<e.length;t++)s[Number(e[t])]=Number(n[t]),s[Number(e[t])+r]=Number(n[t+e.length])}else n.forEach(((t,e)=>s[Number(e)]=Number(t)));let o=[];return s.forEach((t=>o.push(t))),{mode:e.mode,value:i,pads:o}}return e},Wo=(t,e)=>{Do(t.inputs);let n=Ho(t.inputs,e);t.compute(Lo(t.inputs,n),{inputs:[0]})}})),fh=V((()=>{mt(),gu(),Mu(),Eu(),Vo=t=>{if(y.webgpu.validateInputContent&&(!t||1!==t.length))throw new Error("Pool ops requires 1 input.")},Go=(t,e,n)=>{let i="NHWC"===e.format,r=t.dims.slice();i&&r.splice(1,0,r.pop());let s=Object.hasOwnProperty.call(e,"dilations"),o=e.kernelShape.slice(),a=e.strides.slice(),u=s?e.dilations.slice():[],h=e.pads.slice();Me.adjustPoolAttributes(n,r,o,a,u,h);let l=Me.computePoolOutputShape(n,r,a,u,o,h,e.autoPad),c=Object.assign({},e);s?Object.assign(c,{kernelShape:o,strides:a,pads:h,dilations:u,cacheKey:e.cacheKey}):Object.assign(c,{kernelShape:o,strides:a,pads:h,cacheKey:e.cacheKey});let f=l.slice();return f.push(f.splice(1,1)[0]),[c,i?f:l]},Yo=(t,e)=>{let n="NHWC"===e.format,i=[{type:12,data:Se.size(t)},{type:12,data:Se.size(e.kernelShape)}],r=[{name:"outputSize",type:"u32"},{name:"kernelSize",type:"u32"}];if(e.kernelShape.length<=2){let t=e.kernelShape[e.kernelShape.length-1],n=e.strides[e.strides.length-1],s=e.pads[e.pads.length/2-1],o=e.pads[e.pads.length-1],a=!!(s+o);i.push({type:12,data:t},{type:12,data:n},{type:12,data:s},{type:12,data:o}),r.push({name:"kw",type:"u32"},{name:"sw",type:"u32"},{name:"pwStart",type:"u32"},{name:"pwEnd",type:"u32"});let u=!1;if(2===e.kernelShape.length){let t=e.kernelShape[e.kernelShape.length-2],n=e.strides[e.strides.length-2],s=e.pads[e.pads.length/2-2],o=e.pads[e.pads.length-2];u=!!(s+o),i.push({type:12,data:t},{type:12,data:n},{type:12,data:s},{type:12,data:o}),r.push({name:"kh",type:"u32"},{name:"sh",type:"u32"},{name:"phStart",type:"u32"},{name:"phEnd",type:"u32"})}return[i,r,!0,a,u]}{if(n)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let t=Se.computeStrides(e.kernelShape);i.push({type:12,data:t},{type:12,data:e.pads},{type:12,data:e.strides}),r.push({name:"kernelStrides",type:"u32",length:t.length},{name:"pads",type:"u32",length:e.pads.length},{name:"strides",type:"u32",length:e.strides.length});let s=e.pads.reduce(((t,e)=>t+e));return[i,r,!!s,!1,!1]}},Ko=(t,e,n,i,r,s,o,a,u,h,l,c)=>{let f="NHWC"===r.format,d=e.type.value,p=Be("output",e.type.tensor,i);if(r.kernelShape.length<=2){let i="",h="",v="",m=n-(f?2:1);if(i=l?`\n for (var i: u32 = 0u; i < uniforms.kw; i++) {\n xIndices[${m}] = indices[${m}] * uniforms.sw - uniforms.pwStart + i;\n if (xIndices[${m}] < 0 || xIndices[${m}]\n >= uniforms.x_shape[${m}]) {\n pad++;\n continue;\n }\n let x_val = x[${e.indicesToOffset("xIndices")}];\n ${s}\n }`:`\n for (var i: u32 = 0u; i < uniforms.kw; i++) {\n xIndices[${m}] = indices[${m}] * uniforms.sw - uniforms.pwStart + i;\n let x_val = x[${e.indicesToOffset("xIndices")}];\n ${s}\n }`,2===r.kernelShape.length){let t=n-(f?3:2);h=c?`\n for (var j: u32 = 0u; j < uniforms.kh; j++) {\n xIndices[${t}] = indices[${t}] * uniforms.sh - uniforms.phStart + j;\n if (xIndices[${t}] < 0 || xIndices[${t}] >= uniforms.x_shape[${t}]) {\n pad += i32(uniforms.kw);\n continue;\n }\n `:`\n for (var j: u32 = 0u; j < uniforms.kh; j++) {\n xIndices[${t}] = indices[${t}] * uniforms.sh - uniforms.phStart + j;\n `,v="\n }\n "}return`\n ${t.registerUniforms(u).declareVariables(e,p)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n\n let indices = ${p.offsetToIndices("global_idx")};\n var xIndices = ${p.offsetToIndices("global_idx")};\n\n var value = ${d}(${a});\n var pad = 0;\n ${h}\n ${i}\n ${v}\n ${o}\n\n output[global_idx] = value;\n }`}{if(f)throw new Error("Pooling with kernelShape.length > 2 is not supported for NHWC format.");let i=r.kernelShape.length,l=r.pads.length,c="";return c=h?`\n if (xIndices[j] >= uniforms.x_shape[j]) {\n pad++;\n isPad = true;\n break;\n }\n }\n if (!isPad) {\n let x_val = x[${e.indicesToOffset("xIndices")}];\n ${s}\n }`:`\n }\n let x_val = x[${e.indicesToOffset("xIndices")}];\n ${s}\n `,`\n ${t.registerUniforms(u).declareVariables(e,p)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n let indices = ${p.offsetToIndices("global_idx")};\n var xIndices = ${p.offsetToIndices("global_idx")};\n\n var offsets: array<u32, ${i}>;\n\n var value = ${d}(${a});\n var pad = 0;\n var isPad = false;\n\n for (var i: u32 = 0u; i < uniforms.kernelSize; i++) {\n var offset = i;\n for (var j = 0u; j < ${i-1}u; j++) {\n offsets[j] = offset / ${Ue("uniforms.kernelStrides","j",i)};\n offset -= offsets[j] * ${Ue("uniforms.kernelStrides","j",i)};\n }\n offsets[${i-1}] = offset;\n\n isPad = false;\n for (var j = ${n-i}u; j < ${n}u; j++) {\n xIndices[j] = indices[j] * ${Ue("uniforms.strides",`j - ${n-i}u`,i)}\n + offsets[j - ${n-i}u] - ${Ue("uniforms.pads","j - 2u",l)};\n ${c}\n }\n ${o}\n\n output[global_idx] = value;\n }`}},Xo=t=>`${t.format};${t.ceilMode};${t.autoPad};${t.kernelShape.length}`,Qo=t=>`${Xo(t)};${t.countIncludePad}`,Zo=t=>`${Xo(t)};${t.storageOrder};${t.dilations}`,Jo=t=>({format:t.format,autoPad:["NOTSET","VALID","SAME_UPPER","SAME_LOWER"][t.auto_pad],ceilMode:t.ceil_mode,kernelShape:t.kernel_shape,strides:t.strides,pads:t.pads}),ta=(t,e,n,i)=>{let[r,s]=Go(e,i,n),o=je("x",e.dataType,e.dims.length),a=o.type.value,u="";r.countIncludePad?u+=`value /= ${a}(uniforms.kernelSize);`:u+=`value /= ${a}(i32(uniforms.kernelSize) - pad);`;let[h,l,c,f,d]=Yo(s,r);return h.push(...Re(e.dims,s)),{name:t,shaderCache:{hint:`${i.cacheKey};${c};${f};${d}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:s,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(Se.size(s)/64)},programUniforms:h}),getShaderSource:t=>Ko(t,o,e.dims.length,s.length,r,"value += x_val;",u,0,l,c,f,d)}},ea=t=>{let e=0!==t.count_include_pad,n=Jo(t);if(0!==n.ceilMode)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");let i={countIncludePad:e,...n,cacheKey:""};return{...i,cacheKey:Qo(i)}},na=(t,e)=>{Vo(t.inputs),t.compute(ta("AveragePool",t.inputs[0],!1,e))},ia={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[]},ra=t=>{let e=t.format;return{format:e,...ia,cacheKey:e}},sa=(t,e)=>{Vo(t.inputs),t.compute(ta("GlobalAveragePool",t.inputs[0],!0,e))},oa=(t,e,n,i)=>{let[r,s]=Go(e,i,n),o=je("x",e.dataType,e.dims.length),[a,u,h,l,c]=Yo(s,r);return a.push(...Re(e.dims,s)),{name:t,shaderCache:{hint:`${i.cacheKey};${h};${l};${c}`,inputDependencies:["rank"]},getRunData:()=>({outputs:[{dims:s,dataType:e.dataType}],dispatchGroup:{x:Math.ceil(Se.size(s)/64)},programUniforms:a}),getShaderSource:t=>Ko(t,o,e.dims.length,s.length,r,"\n value = max(x_val, value);\n ","",10===e.dataType?-65504:-1e5,u,h,l,c)}},aa=(t,e)=>{Vo(t.inputs),t.compute(oa("MaxPool",t.inputs[0],!1,e))},ua=t=>{let e=t.storage_order,n=t.dilations,i=Jo(t);if(0!==e)throw new Error("column major storage order is not yet supported for MaxPool");if(0!==i.ceilMode)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");let r={storageOrder:e,dilations:n,...i,cacheKey:""};return{...r,cacheKey:Zo(r)}},ha=t=>{let e=t.format;return{format:e,...ia,cacheKey:e}},la=(t,e)=>{Vo(t.inputs),t.compute(oa("GlobalMaxPool",t.inputs[0],!0,e))}})),dh=V((()=>{mt(),gu(),Eu(),ca=(t,e,n)=>{if(t===e||t<e&&n<0||t>e&&n>0)throw new Error("Range these inputs' contents are invalid.")},fa=(t,e,n,i)=>{let r=Math.abs(Math.ceil((e-t)/n)),s=[r],o=r,a=[{type:12,data:o},{type:i,data:t},{type:i,data:n},...Re(s)];return{name:"Range",shaderCache:{hint:`${i}`},getShaderSource:t=>{let e=Be("output",i,s.length),n=e.type.value,r=[{name:"outputSize",type:"u32"},{name:"start",type:n},{name:"delta",type:n}];return`\n ${t.registerUniforms(r).declareVariables(e)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n output[global_idx] = uniforms.start + ${n}(global_idx) * uniforms.delta;\n }`},getRunData:()=>({outputs:[{dims:s,dataType:i}],dispatchGroup:{x:Math.ceil(o/64)},programUniforms:a})}},da=t=>{let e=0,n=0,i=0;6===t.inputs[0].dataType?(e=t.inputs[0].getInt32Array()[0],n=t.inputs[1].getInt32Array()[0],i=t.inputs[2].getInt32Array()[0]):1===t.inputs[0].dataType&&(e=t.inputs[0].getFloat32Array()[0],n=t.inputs[1].getFloat32Array()[0],i=t.inputs[2].getFloat32Array()[0]),y.webgpu.validateInputContent&&ca(e,n,i),t.compute(fa(e,n,i,t.inputs[0].dataType),{inputs:[]})}})),ph=V((()=>{gu(),Mu(),Su(),Eu(),pa=(t,e)=>{if(t.every((t=>t>0||(()=>{throw new Error("Resize requires scales input values to be positive")}))),t.length>0)if("linear"===e.mode){if(!(2===t.length||3===t.length||4===t.length&&1===t[0]&&1===t[1]||4===t.length&&1===t[0]&&1===t[3]||5===t.length&&1===t[0]&&1===t[1]))throw new Error("For linear mode, Resize requires scales to be 2D, 3D, 4D with either two outermost or one innermost and\n one outermost scale values equal to 1, or 5D with two outermost scale values equal to 1")}else if("cubic"===e.mode&&!(2===t.length||4===t.length&&1===t[0]&&1===t[1]||4===t.length&&1===t[0]&&1===t[3]))throw new Error("Resize requires scales input size to be 2 or 4 for cubic mode")},va=(t,e,n)=>{e.every((t=>t>=0&&t<n||(()=>{throw new Error("Resize requires axes input values to be positive and less than rank")})));let i=new Array(n).fill(1);return e.forEach(((e,n)=>i[e]=t[n])),i},ma=(t,e,n,i,r,s)=>{let[o,a,u]=n>10?[1,2,3]:[-1,t.length>1?1:-1,-1],h=t[0].dims.length;if(o>0&&t.length>o&&t[o].dims.length>0)t[o].getFloat32Array().forEach((t=>s.push(t)));else if("tf_crop_and_resize"===e.coordinateTransformMode)throw new Error("Resize requires RoI input to be specified when coordinateTransformMode is tfCropAndResize");if(a>0&&t.length>a&&t[a].dims.length>0){if(t[a].getFloat32Array().forEach((t=>i.push(t))),0!==i.length&&i.length!==h&&n>=18&&i.length!==e.axes.length)throw new Error("Resize requires scales input size to be same as input rank or axes size for opset 18 and up");pa(i,e),e.axes.length>0&&va(i,e.axes,h).forEach(((t,e)=>i[e]=t))}if(u>0&&t.length>u&&(t[u].getBigInt64Array().forEach((t=>r.push(Number(t)))),r.length!==h||n>=18&&r.length===e.axes.length))throw new Error("Resize requires sizes input size to be same as input rank or axes size for opset 18 and up");if(e.axes.length>0){if(i.length!==e.axes.length)throw new Error('Resize requires "scales" input size to be of axes rank when axes attributes is specified');if(r.length!==e.axes.length)throw new Error('Resize requires "sizes" input size to be of rank axes rank when axes attributes is specified')}if(typeof i<"u"&&typeof r<"u"&&i.length>0&&r.length>h)throw new Error("Resize requires only of scales or sizes to be specified")},ya=(t,e)=>`fn getOriginalCoordinateFromResizedCoordinate(xResized: u32, xScale: f32, lengthResized: u32,\n lengthOriginal: u32, roiStart: f32, roiEnd: f32) -> ${e} { `+(()=>{switch(t){case"asymmetric":return`return ${e}(xResized) / ${e}(xScale);`;case"pytorch_half_pixel":return`if (lengthResized > 1) {\n return (${e}(xResized) + 0.5) / ${e}(xScale) - 0.5;\n } else {\n return 0.0;\n }`;case"tf_half_pixel_for_nn":return`return (${e}(xResized) + 0.5) / ${e}(xScale);`;case"align_corners":return`if (lengthResized == 1) {\n return 0.0;\n } else {\n // The whole part and the fractional part are calculated separately due to inaccuracy of floating\n // point division. As an example, f32(21) / f32(7) may evaluate to 2.99... instead of 3, causing an\n // offset-by-one error later in floor().\n let whole = ${e}(xResized * (lengthOriginal - 1) / (lengthResized - 1));\n let fract =\n ${e}(xResized * (lengthOriginal - 1) % (lengthResized - 1)) / ${e}(lengthResized - 1);\n return whole + fract;\n }`;case"tf_crop_and_resize":return`if (lengthResized > 1) {\n return ${e}(roiStart) * ${e}(lengthOriginal - 1) +\n (${e}(xResized) * ${e}(roiEnd - roiStart) * ${e}(lengthOriginal - 1)) /\n ${e}(lengthResized - 1);\n } else {\n return 0.5 * ${e}(roiStart + roiEnd) * ${e}(lengthOriginal - 1);\n }`;case"half_pixel_symmetric":return`const outputWidth = ${e}xScale * ${e}(lengthResized);\n const adjustment = ${e}(lengthResized) / outputWidth;\n const center = ${e}(lengthOriginal) / 2;\n const offset = center * (1 - adjustment);\n return offset + ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;case"half_pixel":return`return ((${e}(xResized) + 0.5) / ${e}(xScale)) - 0.5;`;default:throw new Error(`Coordinate transform mode ${t} is not supported`)}})()+"}",wa=(t,e,n)=>`fn getNearestPixelFromOriginal(xOriginal: ${n}, isDownSample: bool) -> ${n} {`+(()=>{switch(t){case"round_prefer_ceil":return"if (fract(xOriginal) == 0.5) { return ceil(xOriginal); } else { return round(xOriginal); }";case"floor":return"return floor(xOriginal);";case"ceil":return"return ceil(xOriginal);";case"round_prefer_floor":return"if (fract(xOriginal) == 0.5) { return floor(xOriginal); } else { return round(xOriginal); }";default:if(e<11)return"if (isDownSample) { return ceil(xOriginal); } else { return xOriginal; }";throw new Error(`Nearest mode ${t} is not supported`)}})()+"}",ga=(t,e,n)=>{let i=new Array(n).fill(0).concat(new Array(n).fill(1)),r=0===t.length?i:t.slice();return e.length>0?(e.forEach(((t,s)=>{i[t]=r[s],i[s+n]=r[e.length+s]})),i):r},ba=(t,e,n,i)=>{let r=[];if(n.length>0)if(i.length>0){if(t.forEach((t=>r.push(t))),Math.max(...i)>t.length)throw new Error("axes is out of bound");i.forEach(((t,e)=>r[t]=n[e]))}else n.forEach((t=>r.push(t)));else{if(0===e.length)throw new Error("Resize requires either scales or sizes.");r=t.map(((t,n)=>Math.round(t*e[n])))}return r},_a=(t,e,n)=>{let i=(()=>{switch(n.keepAspectRatioPolicy){case"not_larger":return n.axes.length>0?Math.min(...n.axes.map((t=>e[t])),Number.MAX_VALUE):Math.min(...e,Number.MAX_VALUE);case"not_smaller":return n.axes.length>0?Math.max(...n.axes.map((t=>e[t])),Number.MIN_VALUE):Math.max(...e,Number.MIN_VALUE);default:throw new Error(`Keep aspect ratio policy ${n.keepAspectRatioPolicy} is not supported`)}})();e.fill(1,0,e.length);let r=t.slice();return n.axes.length>0?(n.axes.forEach((t=>e[t]=i)),n.axes.forEach((n=>r[n]=Math.round(t[n]*e[n])))):(e.fill(i,0,e.length),r.forEach(((t,n)=>r[n]=Math.round(t*e[n])))),r},xa=(t,e,n,i,r)=>`\n fn calculateOriginalIndicesFromOutputIndices(output_indices: ${t.type.indices}) -> array<${t.type.value}, ${n.length}> {\n var original_indices: array<${t.type.value}, ${n.length}>;\n for (var i:u32 = 0; i < ${n.length}; i++) {\n var output_index = ${t.indicesGet("output_indices","i")};\n var scale = ${Ue("uniforms.scales","i",i)};\n var roi_low = ${Ue("uniforms.roi","i",r)};\n var roi_hi = ${Ue("uniforms.roi",`i + ${e.length}`,r)};\n if (scale == 1.0) {\n original_indices[i] = ${t.type.value}(output_index);\n } else {\n var input_shape_i = ${Ue("uniforms.input_shape","i",e.length)};\n var output_shape_i = ${Ue("uniforms.output_shape","i",n.length)};\n original_indices[i] = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i,\n input_shape_i, roi_low, roi_hi);\n }\n }\n return original_indices;\n }`,ka=(t,e,n,i,r,s,o)=>`\n fn calculateInputIndicesFromOutputIndices(output_indices: ${e.type.indices}) -> ${t.type.indices} {\n var input_indices: ${t.type.indices};\n for (var i:u32 = 0; i < ${i.length}; i++) {\n var output_index = ${e.indicesGet("output_indices","i")};\n var input_index: u32;\n var scale = ${Ue("uniforms.scales","i",r)};\n if (scale == 1.0) {\n input_index = output_index;\n } else {\n var roi_low = ${Ue("uniforms.roi","i",s)};\n var roi_hi = ${Ue("uniforms.roi",`i + ${n.length}`,s)};\n var input_shape_i = ${Ue("uniforms.input_shape","i",n.length)};\n var output_shape_i = ${Ue("uniforms.output_shape","i",i.length)};\n var original_idx = getOriginalCoordinateFromResizedCoordinate(output_index, scale, output_shape_i,\n input_shape_i, roi_low, roi_hi);\n if (!${o} || (original_idx >= 0 && original_idx < ${e.type.value}(input_shape_i))) {\n if (original_idx < 0) {\n input_index = 0;\n } else if (original_idx > ${e.type.value}(input_shape_i - 1)) {\n input_index = input_shape_i - 1;\n } else {\n input_index = u32(getNearestPixelFromOriginal(original_idx, scale < 1));\n }\n } else {\n input_index = u32(original_idx);\n }\n }\n ${t.indicesSet("input_indices","i"," input_index")}\n }\n return input_indices;\n }`,$a=(t,e)=>`\n fn checkInputIndices(input_indices: ${t.type.indices}) -> bool {\n for (var i:u32 = 0; i < ${e.length}; i++) {\n var input_index = ${t.indicesGet("input_indices","i")};\n if (input_index < 0 || input_index >= ${Ue("uniforms.input_shape","i",e.length)}) {\n return false;\n }\n }\n return true;\n }`,Sa=(t,e,n,i)=>t.rank>i?`\n ${t.indicesSet("input_indices",e,"channel")};\n ${t.indicesSet("input_indices",n,"batch")};\n`:"",Ma=(t,e,n,i,r)=>{let[s,o,a,u]=2===n.length?[-1,0,1,-1]:[0,2,3,1],h=t.type.value;return`\n fn getInputValue(batch: u32, channel: u32, row: u32, col: u32) -> ${h} {\n var input_indices: ${t.type.indices};\n ${t.indicesSet("input_indices",o,`max(0, min(row, ${n[o]} - 1))`)};\n ${t.indicesSet("input_indices",a,`max(0, min(col, ${n[a]} - 1))`)};\n ${Sa(t,u,s,2)}\n return ${t.getByIndices("input_indices")};\n }\n\n fn bilinearInterpolation(output_indices: ${e.type.indices}) -> ${h} {\n var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices);\n var row:${h} = originalIndices[${o}];\n var col:${h} = originalIndices[${a}];\n ${i?`if (row < 0 || row > (${n[o]} - 1) || col < 0 || col > (${n[a]} - 1)) {\n return ${r};\n }`:""};\n row = max(0, min(row, ${n[o]} - 1));\n col = max(0, min(col, ${n[a]} - 1));\n var row1: u32 = u32(row);\n var col1: u32 = u32(col);\n var row2: u32 = u32(row + 1);\n var col2: u32 = u32(col + 1);\n var channel: u32 = ${n.length>2?`u32(originalIndices[${u}])`:"0"};\n var batch: u32 = ${n.length>2?`u32(originalIndices[${s}])`:"0"};\n var x11: ${h} = getInputValue(batch, channel, row1, col1);\n var x12: ${h} = getInputValue(batch, channel, row1, col2);\n var x21: ${h} = getInputValue(batch, channel, row2, col1);\n var x22: ${h} = getInputValue(batch, channel, row2, col2);\n var dx1: ${h} = abs(row - ${h}(row1));\n var dx2: ${h} = abs(${h}(row2) - row);\n var dy1: ${h} = abs(col - ${h}(col1));\n var dy2: ${h} = abs(${h}(col2) - col);\n if (row1 == row2) {\n dx1 = 0.5;\n dx2 = 0.5;\n }\n if (col1 == col2) {\n dy1 = 0.5;\n dy2 = 0.5;\n }\n return (x11 * dx2 * dy2 + x12 * dx2 * dy1 + x21 * dx1 * dy2 + x22 * dx1 * dy1);\n }`},Ea=(t,e,n,i,r,s,o,a,u,h)=>{let l=2===n.length,[c,f]=l?[0,1]:[2,3],d=t.type.value,p=o=>{let l=o===c?"row":"col";return`\n fn ${l}CubicInterpolation(input_indices: ${t.type.indices}, output_indices: ${e.type.indices}) -> ${d} {\n var output_index = ${e.indicesGet("output_indices",o)};\n var originalIdx: ${d} = getOriginalCoordinateFromResizedCoordinate(output_index, ${r[o]},\n ${i[o]}, ${n[o]}, ${s[o]}, ${s[o]} + ${n.length});\n var fractOriginalIdx: ${d} = originalIdx - floor(originalIdx);\n var coefs = getCubicInterpolationCoefs(fractOriginalIdx);\n\n if (${a} && (originalIdx < 0 || originalIdx > (${n[o]} - 1))) {\n return ${u};\n }\n var data: array<${d}, 4> = array<${d}, 4>(0.0, 0.0, 0.0, 0.0);\n for (var i: i32 = -1; i < 3; i++) {\n var ${l}: ${d} = originalIdx + ${d}(i);\n if (${l} < 0 || ${l} >= ${n[o]}) {\n ${h?"coefs[i + 1] = 0.0;\n continue;":a?`return ${u};`:`${l} = max(0, min(${l}, ${n[o]} - 1));`};\n }\n var input_indices_copy: ${t.type.indices} = input_indices;\n ${t.indicesSet("input_indices_copy",o,`u32(${l})`)};\n data[i + 1] = ${o===c?t.getByIndices("input_indices_copy"):"rowCubicInterpolation(input_indices_copy, output_indices)"};\n }\n return cubicInterpolation1D(data, coefs);\n }`};return`\n ${p(c)};\n ${p(f)};\n fn getCubicInterpolationCoefs(s: ${d}) -> array<${d}, 4> {\n var absS = abs(s);\n var coeffs: array<${d}, 4> = array<${d}, 4>(0.0, 0.0, 0.0, 0.0);\n var oneMinusAbsS: ${d} = 1.0 - absS;\n var twoMinusAbsS: ${d} = 2.0 - absS;\n var onePlusAbsS: ${d} = 1.0 + absS;\n coeffs[0] = ((${o} * onePlusAbsS - 5 * ${o}) * onePlusAbsS + 8 * ${o}) * onePlusAbsS - 4 * ${o};\n coeffs[1] = ((${o} + 2) * absS - (${o} + 3)) * absS * absS + 1;\n coeffs[2] = ((${o} + 2) * oneMinusAbsS - (${o} + 3)) * oneMinusAbsS * oneMinusAbsS + 1;\n coeffs[3] = ((${o} * twoMinusAbsS - 5 * ${o}) * twoMinusAbsS + 8 * ${o}) * twoMinusAbsS - 4 * ${o};\n return coeffs;\n }\n\n fn cubicInterpolation1D(x: array<${d}, 4>, coefs: array<${d}, 4>) -> ${d} {\n var coefsSum: ${d} = coefs[0] + coefs[1] + coefs[2] + coefs[3];\n return (x[0] * coefs[0] + x[1] * coefs[1]+ x[2] * coefs[2]+ x[3] * coefs[3]) / coefsSum;\n }\n\n fn bicubicInterpolation(output_indices: ${e.type.indices}) -> ${d} {\n var input_indices: ${t.type.indices} = output_indices;\n return colCubicInterpolation(input_indices, output_indices);\n }\n `},Ca=(t,e,n,i,r)=>{let[s,o,a,u,h]=3===n.length?[-1,0,1,2,-1]:[0,2,3,4,1],l=t.type.value;return`\n fn getInputValue(batch: u32, channel: u32, depth:u32, height: u32, width: u32) -> ${l} {\n var input_indices: ${t.type.indices};\n ${t.indicesSet("input_indices",o,`max(0, min(depth, ${n[o]} - 1))`)};\n ${t.indicesSet("input_indices",a,`max(0, min(height, ${n[a]} - 1))`)};\n ${t.indicesSet("input_indices",u,`max(0, min(width, ${n[u]} - 1))`)};\n ${Sa(t,h,s,3)}\n return ${t.getByIndices("input_indices")};\n }\n\n fn trilinearInterpolation(output_indices: ${e.type.indices}) -> ${l} {\n var originalIndices = calculateOriginalIndicesFromOutputIndices(output_indices);\n var depth:${l} = originalIndices[${o}];\n var height:${l} = originalIndices[${a}];\n var width:${l} = originalIndices[${u}];\n ${i?`if (depth < 0 || depth > (${n[o]} - 1) || height < 0 || height > (${n[a]} - 1) || width < 0 || (width > ${n[u]} - 1)) {\n return ${r};\n }`:""};\n\n depth = max(0, min(depth, ${n[o]} - 1));\n height = max(0, min(height, ${n[a]} - 1));\n width = max(0, min(width, ${n[u]} - 1));\n var depth1: u32 = u32(depth);\n var height1: u32 = u32(height);\n var width1: u32 = u32(width);\n var depth2: u32 = u32(depth + 1);\n var height2: u32 = u32(height + 1);\n var width2: u32 = u32(width + 1);\n var channel: u32 = ${n.length>3?`u32(originalIndices[${h}])`:"0"};\n var batch: u32 = ${n.length>3?`u32(originalIndices[${s}])`:"0"};\n\n var x111: ${l} = getInputValue(batch, channel, depth1, height1, width1);\n var x112: ${l} = getInputValue(batch, channel, depth1, height1, width2);\n var x121: ${l} = getInputValue(batch, channel, depth1, height2, width1);\n var x122: ${l} = getInputValue(batch, channel, depth1, height2, width2);\n var x211: ${l} = getInputValue(batch, channel, depth2, height1, width1);\n var x212: ${l} = getInputValue(batch, channel, depth2, height1, width2);\n var x221: ${l} = getInputValue(batch, channel, depth2, height2, width1);\n var x222: ${l} = getInputValue(batch, channel, depth2, height2, width2);\n var dx1: ${l} = abs(depth - ${l}(depth1));\n var dx2: ${l} = abs(${l}(depth2) - depth);\n var dy1: ${l} = abs(height - ${l}(height1));\n var dy2: ${l} = abs(${l}(height2) - height);\n var dz1: ${l} = abs(width - ${l}(width1));\n var dz2: ${l} = abs(${l}(width2) - width);\n if (depth1 == depth2) {\n dx1 = 0.5;\n dx2 = 0.5;\n }\n if (height1 == height2) {\n dy1 = 0.5;\n dy2 = 0.5;\n }\n if (width1 == width2) {\n dz1 = 0.5;\n dz2 = 0.5;\n }\n return (x111 * dx2 * dy2 * dz2 + x112 * dx2 * dy2 * dz1 + x121 * dx2 * dy1 *dz2 + x122 * dx2 * dy1 * dz1 +\n x211 * dx1 * dy2 * dz2 + x212 * dx1 * dy2 * dz1 + x221 * dx1 * dy1 *dz2 + x222 * dx1 * dy1 * dz1);\n }`},Aa=(t,e,n,i,r,s)=>{let o=t.dims,a=ga(s,e.axes,o.length),u=ba(o,i,r,e.axes),h=i.slice();0===i.length&&(h=o.map(((t,e)=>0===t?1:u[e]/t)),"stretch"!==e.keepAspectRatioPolicy&&(u=_a(o,h,e)));let l=Be("output",t.dataType,u.length),c=je("input",t.dataType,o.length),f=Se.size(u),d=o.length===u.length&&o.every(((t,e)=>t===u[e])),p="tf_crop_and_resize"===e.coordinateTransformMode,v=e.extrapolationValue,m=c.type.value;return{name:"Resize",shaderCache:{hint:`${e.cacheKey}|${n}|${h.length>0?h:""}|${r.length>0?r:""}|${a.length>0?a:""}|${d}|${o}`,inputDependencies:["rank"]},getShaderSource:t=>`\n ${d?"":`\n ${ya(e.coordinateTransformMode,m)};\n ${(()=>{switch(e.mode){case"nearest":return`\n ${$a(c,o)};\n ${wa(e.nearestMode,n,m)};\n ${ka(c,l,o,u,h.length,a.length,p)};\n `;case"linear":return`\n ${xa(l,o,u,h.length,a.length)};\n ${(()=>{if(2===o.length||4===o.length)return`${Ma(c,l,o,p,v)}`;if(3===o.length||5===o.length)return`${Ca(c,l,o,p,v)}`;throw Error("Linear mode only supports input dims 2, 3, 4 and 5 are supported in linear mode.")})()};\n `;case"cubic":return`\n ${(()=>{if(2===o.length||4===o.length)return`${Ea(c,l,o,u,h,a,e.cubicCoeffA,p,e.extrapolationValue,e.excludeOutside)}`;throw Error("Cubic mode only supports input dims 2 and 4 are supported in linear mode.")})()};\n `;default:throw Error("Invalid resize mode")}})()};\n `}\n ${t.registerUniform("output_size","u32").registerUniform("scales","f32",h.length).registerUniform("roi","f32",a.length).declareVariables(c,l)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.output_size")}\n ${d?"output[global_idx] = input[global_idx];":`\n let output_indices = ${l.offsetToIndices("global_idx")};\n var input_indices: ${c.type.indices};\n ${(()=>{switch(e.mode){case"nearest":return`input_indices = calculateInputIndicesFromOutputIndices(output_indices);\n if (checkInputIndices(input_indices)) {\n output[global_idx] = ${c.getByIndices("input_indices")};\n } else {\n output[global_idx] = ${e.extrapolationValue};\n }`;case"linear":return`output[global_idx] = ${2===o.length||4===o.length?"bilinearInterpolation":"trilinearInterpolation"}(output_indices);`;case"cubic":return"output[global_idx] = bicubicInterpolation(output_indices);";default:throw Error(`Unsupported resize mode: ${e.mode}`)}})()};\n`}\n }`,getRunData:()=>({outputs:[{dims:u,dataType:t.dataType}],dispatchGroup:{x:Math.ceil(f/64)},programUniforms:[{type:12,data:f},{type:1,data:h},{type:1,data:a},...Re(o,u)]})}},Oa=t=>{let e=t.customDataBuffer;return new Uint32Array(e,e.byteOffset,1)[0]},Ia=(t,e)=>{let n=[],i=[],r=[],s=Oa(t);if(0!==e.antialias)throw Error("Only default value (0) for Antialias attribute is supported");ma(t.inputs,e,s,n,i,r),t.compute(Aa(t.inputs[0],e,s,n,i,r),{inputs:[0]})},Ta=t=>{let e=t.antialias,n=t.axes,i=t.coordinateTransformMode,r=t.cubicCoeffA,s=0!==t.excludeOutside,o=t.extrapolationValue,a=t.keepAspectRatioPolicy,u=t.mode,h=""===t.nearestMode?"simple":t.nearestMode;return xe({antialias:e,axes:n,coordinateTransformMode:i,cubicCoeffA:r,excludeOutside:s,extrapolationValue:o,keepAspectRatioPolicy:a,mode:u,nearestMode:h})}})),vh=V((()=>{gu(),Mu(),Su(),Eu(),za=(t,e)=>{let[n,i,r,s]=t,{numHeads:o,rotaryEmbeddingDim:a}=e;if(3!==n.dims.length&&4!==n.dims.length)throw new Error(`Input 'x' is expected to have 3 or 4 dimensions, got ${n.dims.length}`);if(!Se.areEqual(i.dims,[])&&!Se.areEqual(i.dims,[1])&&2!==i.dims.length)throw new Error(`Input 'position_ids' is expected to have 0, 1, or 2 dimensions, got ${i.dims.length}`);if(2!==r.dims.length)throw new Error(`Input 'cos_cache' is expected to have 2 dimensions, got ${r.dims.length}`);if(2!==s.dims.length)throw new Error(`Input 'sin_cache' is expected to have 2 dimensions, got ${s.dims.length}`);if(!Se.areEqual(r.dims,s.dims))throw new Error("Inputs 'cos_cache' and 'sin_cache' are expected to have the same shape");if(a>0&&0===o)throw new Error("num_heads must be provided if rotary_embedding_dim is specified");let u=n.dims[0],h=n.dims[n.dims.length-2],l=r.dims[0],c=Se.sizeFromDimension(n.dims,1)/h,f=0===a?2*r.dims[1]:c/o;if(a>f)throw new Error("rotary_embedding_dim must be less than or equal to head_size");if(2===i.dims.length){if(u!==i.dims[0])throw new Error(`Input 'position_ids' dimension 0 should be of size batch_size, got ${i.dims[0]}`);if(h!==i.dims[1])throw new Error(`Input 'position_ids' dimension 1 should be of size sequence_length, got ${i.dims[1]}`)}if(f/2!==r.dims[1]&&a/2!==r.dims[1])throw new Error(`Input 'cos_cache' dimension 1 should be same as head_size / 2 or rotary_embedding_dim / 2, got ${r.dims[1]}`);if(h>l)throw new Error("Updating cos_cache and sin_cache in RotaryEmbedding is not currently supported")},Ra=(t,e)=>{let{interleaved:n,numHeads:i,rotaryEmbeddingDim:r,scale:s}=e,o=t[0].dims[0],a=Se.sizeFromDimension(t[0].dims,1),u=t[0].dims[t[0].dims.length-2],h=a/u,l=t[2].dims[1],c=0===r?2*l:h/i,f=new Array(o,u,h/c,c-l),d=Se.computeStrides(f),p=[{type:1,data:s},{type:12,data:f},{type:12,data:d},...3===t[0].dims.length?new Array({type:12,data:[a,h,c,1]}):[],...4===t[0].dims.length?new Array({type:12,data:[a,c,u*c,1]}):[],...Re(t[0].dims,t[1].dims,t[2].dims,t[3].dims,t[0].dims)];return{name:"RotaryEmbedding",shaderCache:{hint:xe({interleaved:n}).cacheKey,inputDependencies:["rank","rank","rank","rank"]},getShaderSource:e=>{let i=je("input",t[0].dataType,t[0].dims.length),r=je("position_ids",t[1].dataType,t[1].dims.length),s=je("cos_cache",t[2].dataType,t[2].dims.length),o=je("sin_cache",t[3].dataType,t[3].dims.length),a=Be("output",t[0].dataType,t[0].dims.length);return e.registerUniforms([{name:"scale",type:"f32"},{name:"global_shape",type:"u32",length:f.length},{name:"global_strides",type:"u32",length:d.length},{name:"input_output_strides",type:"u32",length:d.length}]),`\n ${e.declareVariables(i,r,s,o,a)}\n\n ${e.mainStart(Oe)}\n let half_rotary_emb_dim = uniforms.${s.name}_shape[1];\n let bsnh = global_idx / uniforms.global_strides % uniforms.global_shape;\n let size = uniforms.global_shape[0] * uniforms.global_strides[0];\n ${e.guardAgainstOutOfBoundsWorkgroupSizes("size")}\n\n if (bsnh[3] < half_rotary_emb_dim) {\n let position_ids_idx =\n ${r.broadcastedIndicesToOffset("bsnh.xy",Be("",r.type.tensor,2))};\n let position_id =\n u32(${r.getByOffset("position_ids_idx")}) + select(0, bsnh[1], position_ids_idx == 0);\n let i = dot(bsnh, uniforms.input_output_strides) + select(0, bsnh[3], ${n});\n let j = i + select(half_rotary_emb_dim, 1, ${n});\n let re = ${i.getByOffset("i")} * ${s.get("position_id","bsnh[3]")} -\n ${i.getByOffset("j")} * ${o.get("position_id","bsnh[3]")};\n ${a.setByOffset("i","re")}\n let im = ${i.getByOffset("i")} * ${o.get("position_id","bsnh[3]")} +\n ${i.getByOffset("j")} * ${s.get("position_id","bsnh[3]")};\n ${a.setByOffset("j","im")}\n } else {\n let k = dot(bsnh, uniforms.input_output_strides) + half_rotary_emb_dim;\n ${a.setByOffset("k",i.getByOffset("k"))}\n }\n }`},getRunData:()=>({outputs:[{dims:t[0].dims,dataType:t[0].dataType}],dispatchGroup:{x:Math.ceil(Se.size(f)/Oe)},programUniforms:p})}},Fa=(t,e)=>{za(t.inputs,e),t.compute(Ra(t.inputs,e))}})),mh=V((()=>{gu(),Mu(),Eu(),Pa=t=>{if(!t||t.length<3)throw new Error("layerNorm requires at least 3 inputs.");let e=t[0],n=t[1],i=t[2];if(e.dataType!==n.dataType||e.dataType!==i.dataType)throw new Error("All inputs must have the same data type");if(3!==e.dims.length&&2!==e.dims.length)throw new Error("Input must be 2D or 3D");if(3!==n.dims.length&&2!==n.dims.length)throw new Error("Skip must be 2D or 3D");let r=e.dims[e.dims.length-1],s=e.dims[e.dims.length-2];if(n.dims[n.dims.length-1]!==r)throw new Error("Skip must have the same hidden size as input");if(n.dims[n.dims.length-2]!==s)throw new Error("Skip must have the same sequence length as input");if(1!==i.dims.length)throw new Error("Gamma must be 1D");if(i.dims[i.dims.length-1]!==r)throw new Error("Gamma must have the same hidden size as input");if(t.length>3){let e=t[3];if(1!==e.dims.length)throw new Error("Beta must be 1D");if(e.dims[e.dims.length-1]!==r)throw new Error("Beta must have the same hidden size as input")}if(t.length>4){let e=t[4];if(1!==e.dims.length)throw new Error("Bias must be 1D");if(e.dims[e.dims.length-1]!==r)throw new Error("Bias must have the same hidden size as input")}},Da=(t,e,n,i)=>{let r=e.simplified,s=t[0].dims,o=Se.size(s),a=s,u=o,h=s.slice(-1)[0],l=i?s.slice(0,-1).concat(1):[],c=!r&&t.length>3,f=t.length>4,d=i&&n>1,p=i&&n>2,v=n>3,m=Fe(h),y=[{type:12,data:u},{type:12,data:m},{type:12,data:h},{type:1,data:e.epsilon}],w=[{dims:a,dataType:t[0].dataType}];return n>1&&w.push({dims:l,dataType:1}),n>2&&w.push({dims:l,dataType:1}),n>3&&w.push({dims:s,dataType:t[0].dataType}),{name:"SkipLayerNormalization",shaderCache:{hint:`${m};${d};${p};${v}`,inputDependencies:t.map(((t,e)=>"type"))},getShaderSource:e=>{let n=[je("x",t[0].dataType,t[0].dims,m),je("skip",t[1].dataType,t[1].dims,m),je("gamma",t[2].dataType,t[2].dims,m)];c&&n.push(je("beta",t[3].dataType,t[3].dims,m)),f&&n.push(je("bias",t[4].dataType,t[4].dims,m)),n.push(Be("output",t[0].dataType,a,m)),d&&n.push(Be("mean_output",1,l)),p&&n.push(Be("inv_std_output",1,l)),v&&n.push(Be("input_skip_bias_sum",t[0].dataType,a,m));let i=Te(t[0].dataType),s=Te(1,m);return`\n\n ${e.registerUniforms([{name:"output_size",type:"u32"},{name:"components",type:"u32"},{name:"hidden_size",type:"u32"},{name:"epsilon",type:"f32"}]).declareVariables(...n)}\n var<workgroup> sum_shared : array<${s}, 64>;\n var<workgroup> sum_squared_shared : array<${s}, 64>;\n\n ${e.mainStart([64,1,1])}\n let ix = local_id.x;\n let iy = global_id.x / 64;\n\n let hidden_size_vectorized: u32 = uniforms.hidden_size / uniforms.components;\n var stride = hidden_size_vectorized / 64;\n let offset = ix * stride + iy * hidden_size_vectorized;\n let offset1d = stride * ix;\n if (ix == 63) {\n stride = hidden_size_vectorized - stride * ix;\n }\n for (var i: u32 = 0; i < stride; i++) {\n let skip_value = skip[offset + i];\n let bias_value = ${f?"bias[offset1d + i]":i+"(0.0)"};\n let input_value = x[offset + i];\n let value = input_value + skip_value + bias_value;\n ${v?"input_skip_bias_sum[offset + i] = value;":""}\n output[offset + i] = value;\n let f32_value = ${De(i,m,"value")};\n sum_shared[ix] += f32_value;\n sum_squared_shared[ix] += f32_value * f32_value;\n }\n workgroupBarrier();\n\n var reduce_size : u32 = 64;\n for (var curr_size = reduce_size >> 1; curr_size > 0; curr_size = reduce_size >> 1) {\n reduce_size = curr_size + (reduce_size & 1);\n if (ix < curr_size) {\n sum_shared[ix] += sum_shared[ix + reduce_size];\n sum_squared_shared[ix] += sum_squared_shared[ix + reduce_size];\n }\n workgroupBarrier();\n }\n\n let sum = sum_shared[0];\n let square_sum = sum_squared_shared[0];\n let mean = ${Ne("sum",m)} / f32(uniforms.hidden_size);\n let inv_std_dev = inverseSqrt(${Ne("square_sum",m)} / f32(uniforms.hidden_size) ${r?"":"- mean * mean"} + uniforms.epsilon);\n ${d?"mean_output[global_idx] = mean;":""}\n ${p?"inv_std_output[global_idx] = inv_std_dev;":""}\n\n for (var i: u32 = 0; i < stride; i++) {\n output[offset + i] = (output[offset + i] ${r?"":`- ${i}(mean)`}) *\n ${i}(inv_std_dev) * gamma[offset1d + i]\n ${c?"+ beta[offset1d + i]":""};\n }\n }`},getRunData:()=>({outputs:w,dispatchGroup:{x:Math.ceil(u/h)},programUniforms:y})}},Na=(t,e)=>{Pa(t.inputs);let n=[0];t.outputCount>1&&n.push(-3),t.outputCount>2&&n.push(-3),t.outputCount>3&&n.push(3),t.compute(Da(t.inputs,e,t.outputCount,!1),{outputs:n})}})),yh=V((()=>{gu(),Mu(),Su(),Eu(),Ua=(t,e)=>{if(!t||t.length<1)throw new Error("too few inputs");if(0!==e.axes.length){if(e.axes.length!==e.starts.length||e.axes.length!==e.ends.length)throw new Error("axes, starts and ends must have the same length")}else if(e.starts.length!==e.ends.length)throw new Error("starts and ends must have the same length");t.slice(1).forEach(((e,n)=>{if(6!==t[n+1].dataType&&7!==t[n+1].dataType)throw new Error(`Input ${n} must be an array of int32 or int64`)}))},qa=(t,e)=>{let n=[];if(t.length>e)if(7===t[e].dataType)t[e].getBigInt64Array().forEach((t=>n.push(Number(t))));else{if(6!==t[e].dataType)throw new Error(`Input ${e} must be an array of int32 or int64`);t[e].getInt32Array().forEach((t=>n.push(Number(t))))}return n},ja=(t,e)=>{if(t.length>1){let e=qa(t,1),n=qa(t,2),i=qa(t,3);return 0===i.length&&(i=[...Array(t[0].dims.length).keys()]),xe({starts:e,ends:n,axes:i})}return e},Ba=(t,e,n,i,r)=>{let s=t;return t<0&&(s+=n[i[e]]),r[e]<0?Math.max(0,Math.min(s,n[i[e]]-1)):Math.max(0,Math.min(s,n[i[e]]))},La=(t,e,n)=>`fn calculateInputIndices(output_indices: ${e.type.indices}) -> ${t.type.indices} {\n var input_indices: ${t.type.indices};\n var carry = 0u;\n for (var i = ${n.length}; i >= 0; i--) {\n let input_shape_i = ${Ue("uniforms.input_shape","i",n.length)};\n let steps_i = ${Ue("uniforms.steps","i",n.length)};\n let signs_i = ${Ue("uniforms.signs","i",n.length)};\n let starts_i = ${Ue("uniforms.starts","i",n.length)};\n var output_index = ${e.indicesGet("output_indices","i")};\n var input_index = output_index * steps_i + starts_i + carry;\n carry = input_index / input_shape_i;\n input_index = input_index % input_shape_i;\n if (signs_i < 0) {\n input_index = input_shape_i - input_index - 1u + starts_i;\n }\n ${t.indicesSet("input_indices","i","input_index")};\n }\n return input_indices;\n }`,Ha=(t,e)=>{let n=t[0].dims,i=Se.size(n),r=e.axes.length>0?Se.normalizeAxes(e.axes,n.length):[...Array(n.length).keys()],s=qa(t,4);s.forEach((t=>0!==t||(()=>{throw new Error("step cannot be 0")}))),0===s.length&&(s=Array(r.length).fill(1));let o=e.starts.map(((t,e)=>Ba(t,e,n,r,s))),a=e.ends.map(((t,e)=>Ba(t,e,n,r,s)));if(r.length!==o.length||r.length!==a.length)throw new Error("start, ends and axes should have the same number of elements");if(r.length!==n.length)for(let t=0;t<n.length;++t)r.includes(t)||(o.splice(t,0,0),a.splice(t,0,n[t]),s.splice(t,0,1));let u=s.map((t=>Math.sign(t)));s.forEach(((t,e,n)=>{if(t<0){let i=(a[e]-o[e])/t,r=o[e],u=r+i*s[e];o[e]=u,a[e]=r,n[e]=-t}}));let h=n.slice(0);r.forEach(((t,e)=>{h[t]=Math.ceil((a[t]-o[t])/s[t])}));let l={dims:h,dataType:t[0].dataType},c=Be("output",t[0].dataType,h.length),f=je("input",t[0].dataType,t[0].dims.length),d=Se.size(h),p=[{name:"outputSize",type:"u32"},{name:"starts",type:"u32",length:o.length},{name:"signs",type:"i32",length:u.length},{name:"steps",type:"u32",length:s.length}],v=[{type:12,data:d},{type:12,data:o},{type:6,data:u},{type:12,data:s},...Re(t[0].dims,h)];return{name:"Slice",shaderCache:{hint:`${u.length}_${o.length}_${s.length}`,inputDependencies:["rank"]},getShaderSource:t=>`\n ${t.registerUniforms(p).declareVariables(f,c)}\n ${La(f,c,n)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.outputSize")}\n let output_indices = ${c.offsetToIndices("global_idx")};\n let input_indices = calculateInputIndices(output_indices);\n ${c.setByOffset("global_idx",f.getByIndices("input_indices"))}\n }`,getRunData:()=>({outputs:[l],dispatchGroup:{x:Math.ceil(i/64)},programUniforms:v})}},Wa=(t,e)=>{Ua(t.inputs,e);let n=ja(t.inputs,e);t.compute(Ha(t.inputs,n),{inputs:[0]})},Va=t=>{let e=t.starts,n=t.ends,i=t.axes;return xe({starts:e,ends:n,axes:i})}})),wh=V((()=>{gu(),Mu(),Su(),Eu(),Ga=t=>{if(!t||1!==t.length)throw new Error("Softmax op requires 1 input.")},Ya=(t,e)=>{let n=t.dims,i=Se.size(n),r=e.axis;if(r<0&&(r=n.length+r),r<n.length-1)throw new Error("softmax only supports last axis for now.");let s=n[r],o=i/s,a=Fe(s),u=s/a,h=je("x",t.dataType,t.dims,a),l=Be("result",t.dataType,t.dims,a),c=h.type.value,f="f32"===Te(t.dataType)?`var threadMax = ${c}(-3.402823e+38f);`:`var threadMax = ${c}(-65504.0h);`;return{name:"Softmax",shaderCache:{hint:`${a}`,inputDependencies:["type"]},getRunData:()=>({outputs:[{dims:n,dataType:t.dataType}],dispatchGroup:{x:o},programUniforms:[{type:6,data:u}]}),getShaderSource:t=>`\n var<workgroup> rowMaxShared : ${c};\n var<workgroup> rowSumShared : ${c};\n var<workgroup> threadShared : array<${c}, 64>;\n\n fn getValue(row: i32, col: i32, row_stride: i32) -> ${c} {\n let index = row * row_stride + col;\n return x[index];\n }\n\n fn setValue(row: i32, col: i32, row_stride: i32, value: ${c}) {\n let index = row * row_stride + col;\n result[index] = value;\n }\n ${t.registerUniform("packedCols","i32").declareVariables(h,l)}\n ${t.mainStart()}\n let gindex = i32(global_idx);\n let lindex = i32(local_idx);\n const wg = 64;\n let row = gindex / wg;\n let cols = uniforms.packedCols;\n let row_stride : i32 = uniforms.packedCols;\n\n // find the rows max\n ${f}\n for (var col = lindex; col < cols; col += wg) {\n let value = getValue(row, col, row_stride);\n threadMax = max(threadMax, value);\n }\n if (lindex < cols) {\n threadShared[lindex] = threadMax;\n }\n workgroupBarrier();\n\n var reduceSize = min(cols, wg);\n for (var currSize = reduceSize >> 1; currSize > 0; currSize = reduceSize >> 1) {\n reduceSize = currSize + (reduceSize & 1);\n if (lindex < currSize) {\n threadShared[lindex] = max(threadShared[lindex], threadShared[lindex + reduceSize]);\n }\n workgroupBarrier();\n }\n if (lindex == 0) {\n rowMaxShared = ${c}(${((t,e)=>4===e?`max(max(${t}.x, ${t}.y), max(${t}.z, ${t}.w))`:2===e?`max(${t}.x, ${t}.y)`:3===e?`max(max(${t}.x, ${t}.y), ${t}.z)`:t)("threadShared[0]",a)});\n }\n workgroupBarrier();\n\n // find the rows sum\n var threadSum = ${c}(0.0);\n for (var col = lindex; col < cols; col += wg) {\n let subExp = exp(getValue(row, col, row_stride) - rowMaxShared);\n threadSum += subExp;\n }\n threadShared[lindex] = threadSum;\n workgroupBarrier();\n\n for (var currSize = wg >> 1; currSize > 0; currSize = currSize >> 1) {\n if (lindex < currSize) {\n threadShared[lindex] = threadShared[lindex] + threadShared[lindex + currSize];\n }\n workgroupBarrier();\n }\n if (lindex == 0) {\n rowSumShared = ${c}(${Ne("threadShared[0]",a)});\n }\n workgroupBarrier();\n\n // calculate final value for each element in the row\n for (var col = lindex; col < cols; col += wg) {\n let value = exp(getValue(row, col, row_stride) - rowMaxShared) / rowSumShared;\n setValue(row, col, row_stride, value);\n }\n }`}},Ka=(t,e)=>{Ga(t.inputs),t.compute(Ya(t.inputs[0],e))},Xa=t=>xe({axis:t.axis})})),gh=V((()=>{gu(),Mu(),Su(),Eu(),Qa=t=>{if(!t||t.length<1)throw new Error("too few inputs")},Za=(t,e)=>{let n=[],i=e.numOutputs;return t[1].dims[0]>0&&(t[1].getBigInt64Array().forEach((t=>n.push(Number(t)))),i=n.length),xe({numOutputs:i,axis:e.axis,splitSizes:n})},Ja=t=>`\nfn calculateOutputIndex(index: u32) -> u32 {\n for (var i: u32 = 0u; i < ${t}u; i += 1u ) {\n if (index < ${Ue("uniforms.size_in_split_axis","i",t)}) {\n return i;\n }\n }\n return ${t}u;\n}`,tu=t=>{let e=t.length,n=[];for(let i=0;i<e;++i){let r=t[i].setByIndices("indices","input[global_idx]");1===e?n.push(r):0===i?n.push(`if (output_number == ${i}u) { ${r} }`):i===e-1?n.push(`else { ${r} }`):n.push(`else if (output_number == ${i}) { ${r} }`)}return`\n fn writeBufferData(output_number: u32, indices: ${t[0].type.indices}, global_idx: u32) {\n ${n.join("\n")}\n }`},eu=(t,e)=>{let n=t[0].dims,i=Se.size(n),r=t[0].dataType,s=Se.normalizeAxis(e.axis,n.length),o=new Array(e.numOutputs),a=je("input",r,n.length),u=new Array(e.numOutputs),h=[],l=[],c=0,f=[{type:12,data:i}];for(let i=0;i<e.numOutputs;i++){c+=e.splitSizes[i],u[i]=c;let s=n.slice();s[e.axis]=e.splitSizes[i],l.push(s),o[i]=Be(`output${i}`,r,s.length),h.push({dims:l[i],dataType:t[0].dataType})}return f.push({type:12,data:u},...Re(n,...l)),{name:"Split",shaderCache:{hint:e.cacheKey,inputDependencies:["rank"]},getShaderSource:t=>`\n ${t.registerUniform("input_size","u32").registerUniform("size_in_split_axis","u32",u.length).declareVariables(a,...o)}\n ${Ja(u.length)}\n ${tu(o)}\n\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.input_size")}\n\n var indices = ${a.offsetToIndices("global_idx")};\n var index = ${a.indicesGet("indices",s)};\n let output_number = calculateOutputIndex(index);\n if (output_number != 0) {\n index -= ${Ue("uniforms.size_in_split_axis","output_number - 1u",u.length)};\n ${a.indicesSet("indices",s,"index")};\n }\n writeBufferData(output_number, indices, global_idx);\n }`,getRunData:()=>({outputs:h,dispatchGroup:{x:Math.ceil(i/64)},programUniforms:f})}},nu=(t,e)=>{Qa(t.inputs);let n=1===t.inputs.length?e:Za(t.inputs,e);t.compute(eu(t.inputs,n),{inputs:[0]})},iu=t=>{let e=t.axis,n=t.splitSizes,i=t.numOutputs<0?n.length:t.numOutputs;if(i!==n.length)throw new Error("numOutputs and splitSizes lengh must be equal");return xe({axis:e,numOutputs:i,splitSizes:n})}})),bh=V((()=>{gu(),Mu(),Eu(),ru=(t,e,n,i,r)=>{let s,o=Be("output_data",r,n.length,4),a=je("a_data",e[1].dataType,e[1].dims.length,4),u=je("b_data",e[2].dataType,e[2].dims.length,4),h=je("c_data",e[0].dataType,e[0].dims.length,4),l=(t,e,n)=>`select(${e}, ${t}, ${n})`;if(i){let t=(t,e,n="")=>{let i=`a_data[index_a${e}][component_a${e}]`,r=`b_data[index_b${e}][component_b${e}]`,s=`bool(c_data[index_c${e}] & (0xffu << (component_c${e} * 8)))`;return`\n let output_indices${e} = ${o.offsetToIndices(`global_idx * 4u + ${e}u`)};\n let offset_a${e} = ${a.broadcastedIndicesToOffset(`output_indices${e}`,o)};\n let offset_b${e} = ${u.broadcastedIndicesToOffset(`output_indices${e}`,o)};\n let offset_c${e} = ${h.broadcastedIndicesToOffset(`output_indices${e}`,o)};\n let index_a${e} = offset_a${e} / 4u;\n let index_b${e} = offset_b${e} / 4u;\n let index_c${e} = offset_c${e} / 4u;\n let component_a${e} = offset_a${e} % 4u;\n let component_b${e} = offset_b${e} % 4u;\n let component_c${e} = offset_c${e} % 4u;\n ${t}[${e}] = ${n}(${l(i,r,s)});\n `};s=9===r?`\n var data = vec4<u32>(0);\n ${t("data",0,"u32")}\n ${t("data",1,"u32")}\n ${t("data",2,"u32")}\n ${t("data",3,"u32")}\n output_data[global_idx] = dot(vec4<u32>(0x1, 0x100, 0x10000, 0x1000000), vec4<u32>(data));`:`\n ${t("output_data[global_idx]",0)}\n ${t("output_data[global_idx]",1)}\n ${t("output_data[global_idx]",2)}\n ${t("output_data[global_idx]",3)}\n `}else s=o.setByOffset("global_idx",l(a.getByOffset("global_idx"),u.getByOffset("global_idx"),h.getByOffset("global_idx")));return`\n ${t.registerUniform("vec_size","u32").declareVariables(h,a,u,o)}\n ${t.mainStart()}\n ${t.guardAgainstOutOfBoundsWorkgroupSizes("uniforms.vec_size")}\n ${s}\n }`},su=t=>{let e=t[1].dims,n=t[2].dims,i=t[0].dims,r=t[1].dataType,s=!(Se.areEqual(e,n)&&Se.areEqual(n,i)),o=e,a=Se.size(e);if(s){let t=$e.calcShape($e.calcShape(e,n,!1),i,!1);if(!t)throw new Error("Can't perform where op on the given tensors");o=t,a=Se.size(o)}let u=Math.ceil(a/4);return{name:"Where",shaderCache:{inputDependencies:["rank","rank","rank"]},getShaderSource:e=>ru(e,t,o,s,r),getRunData:()=>({outputs:[{dims:o,dataType:r}],dispatchGroup:{x:Math.ceil(a/64/4)},programUniforms:[{type:12,data:u},...Re(i,e,n,o)]})}},ou=t=>{t.compute(su(t.inputs))}})),_h=V((()=>{Iu(),Tu(),zu(),Ru(),Pu(),Du(),Nu(),Gu(),Xu(),Qu(),Zu(),Ju(),th(),eh(),nh(),ih(),rh(),ah(),uh(),hh(),Vu(),lh(),sh(),ch(),fh(),dh(),Ou(),ph(),vh(),mh(),yh(),wh(),gh(),oh(),Cu(),Fu(),bh(),au=new Map([["Abs",[pi]],["Acos",[vi]],["Acosh",[mi]],["Add",[hr]],["ArgMax",[Xn,Qn]],["ArgMin",[Kn,Qn]],["Asin",[yi]],["Asinh",[wi]],["Atan",[gi]],["Atanh",[bi]],["Attention",[ri]],["AveragePool",[na,ea]],["BatchNormalization",[ui]],["BiasAdd",[ci]],["BiasSplitGelu",[sr]],["Cast",[xi,_i]],["Ceil",[Si]],["Clip",[$i]],["Concat",[kr,$r]],["Conv",[hs,ss]],["ConvTranspose",[ks,ws]],["Cos",[Mi]],["Cosh",[Ei]],["CumSum",[Ss,Ms]],["DepthToSpace",[Os,Is]],["Div",[lr]],["Einsum",[qs,js]],["Elu",[Ai,Ci]],["Equal",[cr]],["Erf",[Ii]],["Exp",[Ti]],["Expand",[Vs]],["FastGelu",[Ys]],["Floor",[zi]],["FusedConv",[hs,ss]],["Gather",[Zs,Qs]],["GatherElements",[no,eo]],["Gelu",[Ri]],["Gemm",[oo,so]],["GlobalAveragePool",[sa,ra]],["GlobalMaxPool",[la,ha]],["Greater",[vr]],["GreaterOrEqual",[yr]],["GroupQueryAttention",[So,xo]],["HardSigmoid",[Bi,ji]],["InstanceNormalization",[Ao]],["LayerNormalization",[To]],["LeakyRelu",[Fi,Ci]],["Less",[mr]],["LessOrEqual",[wr]],["Log",[Ji]],["MatMul",[ts]],["MatMulNBits",[Fo,Po]],["MaxPool",[aa,ua]],["Mul",[fr]],["MultiHeadAttention",[po,ho]],["Neg",[Di]],["Not",[Pi]],["Pad",[Wo]],["Pow",[dr]],["QuickGelu",[nr,Ci]],["Range",[da]],["Reciprocal",[Ni]],["ReduceMin",[Ln]],["ReduceMean",[Nn]],["ReduceMax",[Bn]],["ReduceSum",[Wn]],["ReduceProd",[Hn]],["ReduceL1",[Un]],["ReduceL2",[qn]],["ReduceLogSum",[Gn]],["ReduceLogSumExp",[jn]],["ReduceSumSquare",[Vn]],["Relu",[Ui]],["Resize",[Ia,Ta]],["RotaryEmbedding",[Fa]],["Sigmoid",[qi]],["Sin",[Li]],["Sinh",[Hi]],["Slice",[Wa,Va]],["SkipLayerNormalization",[Na]],["Split",[nu,iu]],["Sqrt",[Wi]],["Softmax",[Ka,Xa]],["Sub",[pr]],["Tan",[Vi]],["Tanh",[Yi]],["ThresholdedRelu",[Zi,Ci]],["Tile",[go]],["Transpose",[Ze,Je]],["Where",[ou]]])})),xh=V((()=>{mt(),_u(),Eu(),uu=class{constructor(t){this.backend=t,this.repo=new Map,this.attributesBound=!1}getArtifact(t){return this.repo.get(t)}setArtifact(t,e){this.repo.set(t,e)}run(t,e,n,i,r){F(t.programInfo.name);let s=this.backend.device,o=this.backend.getComputePassEncoder();this.backend.writeTimestamp(2*this.backend.pendingDispatchNumber);let a=[];for(let t of e)a.push({binding:a.length,resource:{buffer:t.buffer}});for(let t of n)a.push({binding:a.length,resource:{buffer:t.buffer}});r&&a.push({binding:a.length,resource:r});let u=s.createBindGroup({layout:t.computePipeline.getBindGroupLayout(0),entries:a,label:t.programInfo.name});if("capturing"===this.backend.sessionStatus){let e={kernelId:this.backend.currentKernelId,computePipeline:t.computePipeline,bindGroup:u,dispatchGroup:i};this.backend.capturedCommandList.get(this.backend.currentSessionId).push(e)}o.setPipeline(t.computePipeline),o.setBindGroup(0,u),o.dispatchWorkgroups(...i),this.backend.writeTimestamp(2*this.backend.pendingDispatchNumber+1),this.backend.pendingDispatchNumber++,(this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber||"at-passes"===this.backend.queryType)&&this.backend.endComputePass(),this.backend.pendingDispatchNumber>=this.backend.maxDispatchNumber&&this.backend.flush(),P(t.programInfo.name)}dispose(){}build(t,e){F(t.name);let n=this.backend.device,i=[];n.features.has("shader-f16")&&i.push("enable f16;");let r=We(e,this.backend.device.limits),s=t.getShaderSource(r),o=`${i.join("\n")}\n${r.additionalImplementations}\n${s}`,a=n.createShaderModule({code:o,label:t.name});le("verbose",(()=>`[WebGPU] ${t.name} shader code: ${o}`));let u=n.createComputePipeline({compute:{module:a,entryPoint:"main"},layout:"auto",label:t.name});return P(t.name),{programInfo:t,computePipeline:u,uniformVariablesInfo:r.variablesInfo}}normalizeDispatchGroupSize(t){let e="number"==typeof t?t:t.x,n="number"==typeof t?1:t.y||1,i="number"==typeof t?1:t.z||1,r=this.backend.device.limits.maxComputeWorkgroupsPerDimension;if(e<=r&&n<=r&&i<=r)return[e,n,i];let s=e*n*i,o=Math.ceil(Math.sqrt(s));if(o>r){if(o=Math.ceil(Math.cbrt(s)),o>r)throw new Error("Total dispatch size exceeds WebGPU maximum.");return[o,o,o]}return[o,o,1]}}})),kh=V((()=>{mt(),gu(),_u(),xu(),$u(),_h(),xh(),hu=(t,e)=>{if(e.length!==t.length)throw new Error(`inputDependencies length ${e.length} is not equal to inputTensors length ${t.length}.`);let n=[];for(let i=0;i<t.length;++i){let r=t[i].dataType;switch(e[i]){case"none":n.push("");break;case"type":n.push(`${r}`);break;case"rank":{let e=t[i].dims.length;n.push(`${r};${e}`);break}case"dims":{let e=t[i].dims.join(",");n.push(`${r};${e}`);break}default:throw new Error(`unsupported input dependency: ${e[i]}`)}}return n.join("|")},lu=(t,e,n)=>{let i=t.name;return t.shaderCache?.hint&&(i+="["+t.shaderCache.hint+"]"),i+=":"+n+`:${hu(e,t.shaderCache?.inputDependencies??new Array(e.length).fill("dims"))}`,i},cu=class{constructor(t){t&&(this.architecture=t.architecture,this.vendor=t.vendor)}isArchitecture(t){return this.architecture===t}isVendor(t){return this.vendor===t}},fu=class{constructor(){this.currentSessionId=null,this.currentKernelId=null,this.commandEncoder=null,this.computePassEncoder=null,this.maxDispatchNumber=16,this.pendingDispatchNumber=0,this.pendingKernels=[],this.pendingQueries=new Map,this.sessionStatus="default",this.capturedCommandList=new Map,this.capturedPendingKernels=new Map,this.sessionExternalDataMapping=new Map}get currentKernelCustomData(){if(null===this.currentKernelId)throw new Error("currentKernelCustomData(): currentKernelId is null. (should not happen)");let t=this.kernelCustomData.get(this.currentKernelId);return t||(t={},this.kernelCustomData.set(this.currentKernelId,t)),t}async initialize(t,e){this.env=t;let n=[],i={requiredLimits:{maxComputeWorkgroupStorageSize:e.limits.maxComputeWorkgroupStorageSize,maxComputeWorkgroupsPerDimension:e.limits.maxComputeWorkgroupsPerDimension,maxStorageBufferBindingSize:e.limits.maxStorageBufferBindingSize,maxBufferSize:e.limits.maxBufferSize,maxComputeInvocationsPerWorkgroup:e.limits.maxComputeInvocationsPerWorkgroup,maxComputeWorkgroupSizeX:e.limits.maxComputeWorkgroupSizeX,maxComputeWorkgroupSizeY:e.limits.maxComputeWorkgroupSizeY,maxComputeWorkgroupSizeZ:e.limits.maxComputeWorkgroupSizeZ},requiredFeatures:n};e.features.has("chromium-experimental-timestamp-query-inside-passes")?n.push("chromium-experimental-timestamp-query-inside-passes"):e.features.has("timestamp-query")&&n.push("timestamp-query"),e.features.has("shader-f16")&&n.push("shader-f16"),this.device=await e.requestDevice(i),this.adapterInfo=new cu(e.info||await e.requestAdapterInfo()),this.gpuDataManager=be(this),this.programManager=new uu(this),this.kernels=new Map,this.kernelPersistentData=new Map,this.kernelCustomData=new Map,ue(t.logLevel,!!t.debug),this.device.onuncapturederror=t=>{t.error,GPUValidationError},Object.defineProperty(this.env.webgpu,"device",{value:this.device,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(this.env.webgpu,"adapter",{value:e,writable:!1,enumerable:!0,configurable:!1}),this.setQueryType()}dispose(){typeof this.querySet<"u"&&this.querySet.destroy(),this.gpuDataManager.dispose()}getCommandEncoder(){return this.commandEncoder||(this.commandEncoder=this.device.createCommandEncoder()),this.commandEncoder}getComputePassEncoder(){if(!this.computePassEncoder){let t=this.getCommandEncoder(),e={};"at-passes"===this.queryType&&(e.timestampWrites={querySet:this.querySet,beginningOfPassWriteIndex:2*this.pendingDispatchNumber,endOfPassWriteIndex:2*this.pendingDispatchNumber+1}),this.computePassEncoder=t.beginComputePass(e)}return this.computePassEncoder}endComputePass(){this.computePassEncoder&&(this.computePassEncoder.end(),this.computePassEncoder=null)}flush(){if(!this.commandEncoder)return;let t;F(),this.endComputePass(),"none"!==this.queryType&&(this.commandEncoder.resolveQuerySet(this.querySet,0,2*this.pendingDispatchNumber,this.queryResolveBuffer,0),t=this.device.createBuffer({size:16*this.pendingDispatchNumber,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST}),this.pendingQueries.set(t,this.pendingKernels),this.pendingKernels=[],this.commandEncoder.copyBufferToBuffer(this.queryResolveBuffer,0,t,0,16*this.pendingDispatchNumber)),this.device.queue.submit([this.commandEncoder.finish()]),this.gpuDataManager.refreshPendingBuffers(),this.commandEncoder=null,this.pendingDispatchNumber=0,"none"!==this.queryType&&t.mapAsync(GPUMapMode.READ).then((()=>{let e=new BigUint64Array(t.getMappedRange()),n=this.pendingQueries.get(t);for(let t=0;t<e.length/2;t++){let i=n[t],r=i.kernelId,s=this.kernels.get(r),o=s.kernelType,a=s.kernelName,u=i.programName,h=i.inputTensorViews,l=i.outputTensorViews,c=e[2*t],f=e[2*t+1];typeof this.queryTimeBase>"u"&&(this.queryTimeBase=c);let d=Number(c-this.queryTimeBase),p=Number(f-this.queryTimeBase);if(!Number.isSafeInteger(d)||!Number.isSafeInteger(p))throw new RangeError("incorrect timestamp range");if(this.env.webgpu.profiling?.ondata)this.env.webgpu.profiling.ondata({version:1,inputsMetadata:h.map((t=>({dims:t.dims,dataType:Jt(t.dataType)}))),outputsMetadata:l.map((t=>({dims:t.dims,dataType:Jt(t.dataType)}))),kernelId:r,kernelType:o,kernelName:a,programName:u,startTime:d,endTime:p});else{let t="";h.forEach(((e,n)=>{t+=`input[${n}]: [${e.dims}] | ${Jt(e.dataType)}, `}));let e="";l.forEach(((t,n)=>{e+=`output[${n}]: [${t.dims}] | ${Jt(t.dataType)}, `}))}z("GPU",`${u}::${c}::${f}`)}t.unmap(),this.pendingQueries.delete(t)})),P()}run(t,e,n,i,r,s){F(t.name);let o=[];for(let t=0;t<e.length;++t){let n=e[t].data;if(0===n)continue;let i=this.gpuDataManager.get(n);if(!i)throw new Error(`no GPU data for input: ${n}`);o.push(i)}let{outputs:a,dispatchGroup:u,programUniforms:h}=t.getRunData(e),l=0===n.length?a.map(((t,e)=>e)):n;if(l.length!==a.length)throw new Error(`Output size ${l.length} must be equal to ${a.length}.`);let c,f=[],d=[];for(let t=0;t<a.length;++t){if(!Number.isInteger(l[t])||l[t]<-3||l[t]>=s)throw new Error(`Invalid output index: ${l[t]}`);if(-3===l[t])continue;let e=-1===l[t],n=-2===l[t],o=e||n?r(a[t].dataType,a[t].dims):i(l[t],a[t].dataType,a[t].dims);if(f.push(o),0===o.data)continue;let u=this.gpuDataManager.get(o.data);if(!u)throw new Error(`no GPU data for output: ${o.data}`);if(e&&this.temporaryData.push(u),n){let t=this.kernelPersistentData.get(this.currentKernelId);t||(t=[],this.kernelPersistentData.set(this.currentKernelId,t)),t.push(u)}d.push(u)}if(o.length!==e.length||d.length!==f.length){if(0===d.length)return P(t.name),f;throw new Error(`Program ${t.name} has zero-sized tensor(s) in inputs or outputs. This is not supported now.`)}if(h){let t=0,e=[];h.forEach((n=>{let i="number"==typeof n.data?[n.data]:n.data;if(0===i.length)return;let r,s,o=10===n.type?2:4;10===n.type?(s=i.length>4?16:i.length>2?8:i.length*o,r=i.length>4?16:o*i.length):(s=i.length<=2?i.length*o:16,r=16),t=Math.ceil(t/s)*s,e.push(t);let a=10===n.type?8:4;t+=i.length>4?Math.ceil(i.length/a)*r:i.length*o}));let n=16;t=Math.ceil(t/n)*n;let i=new ArrayBuffer(t);h.forEach(((t,n)=>{let r=e[n],s="number"==typeof t.data?[t.data]:t.data;if(6===t.type)new Int32Array(i,r,s.length).set(s);else if(12===t.type)new Uint32Array(i,r,s.length).set(s);else if(10===t.type)new Uint16Array(i,r,s.length).set(s);else{if(1!==t.type)throw new Error(`Unsupported uniform type: ${Jt(t.type)}`);new Float32Array(i,r,s.length).set(s)}}));let r=this.gpuDataManager.create(t,GPUBufferUsage.COPY_DST|GPUBufferUsage.UNIFORM);this.device.queue.writeBuffer(r.buffer,0,i,0,t),this.gpuDataManager.release(r.id),c={offset:0,size:t,buffer:r.buffer}}let p=this.programManager.normalizeDispatchGroupSize(u),v=1===p[1]&&1===p[2],m=lu(t,e,v),y=this.programManager.getArtifact(m);if(y||(y=this.programManager.build(t,p),this.programManager.setArtifact(m,y),le("info",(()=>`[artifact] key: ${m}, programName: ${t.name}`))),h&&y.uniformVariablesInfo){if(h.length!==y.uniformVariablesInfo.length)throw new Error(`Uniform variables count mismatch: expect ${y.uniformVariablesInfo.length}, got ${h.length} in program "${y.programInfo.name}".`);for(let t=0;t<h.length;t++){let e=h[t],n=e.type,i="number"==typeof e.data?1:e.data.length,[r,s]=y.uniformVariablesInfo[t];if(n!==r||i!==s)throw new Error(`Uniform variable ${t} mismatch: expect type ${r} with size ${s}, got type ${n} with size ${i} in program "${y.programInfo.name}".`)}}if(le("info",(()=>`[ProgramManager] run "${t.name}" (key=${m}) with ${p[0]}x${p[1]}x${p[2]}`)),"none"!==this.queryType||"capturing"===this.sessionStatus){let t={kernelId:this.currentKernelId,programName:y.programInfo.name,inputTensorViews:e,outputTensorViews:f};this.pendingKernels.push(t),"capturing"===this.sessionStatus&&this.capturedPendingKernels.get(this.currentSessionId).push(t)}return this.programManager.run(y,o,d,p,c),P(t.name),f}upload(t,e){this.gpuDataManager.upload(t,e)}memcpy(t,e){this.gpuDataManager.memcpy(t,e)}async download(t,e){await this.gpuDataManager.download(t,e)}alloc(t){return this.gpuDataManager.create(t).id}free(t){return this.gpuDataManager.release(t)}createKernel(t,e,n,i){let r=au.get(t);if(!r)throw new Error(`kernel not implemented: ${t}`);let s={kernelType:t,kernelName:i,kernelEntry:r[0],attributes:[r[1],n]};this.kernels.set(e,s)}releaseKernel(t){let e=this.kernelPersistentData.get(t);if(e){for(let t of e)this.gpuDataManager.release(t.id);this.kernelPersistentData.delete(t)}this.kernelCustomData.delete(t),this.kernels.delete(t)}computeKernel(t,e,n){let i=this.kernels.get(t);if(!i)throw new Error(`kernel not created: ${t}`);let r=i.kernelType,s=i.kernelName,o=i.kernelEntry,a=i.attributes;if(null!==this.currentKernelId)throw new Error(`kernel "[${r}] ${s}" is not allowed to be called recursively`);this.currentKernelId=t,a[0]&&(a[1]=a[0](a[1]),a[0]=void 0),le("info",(()=>`[WebGPU] Start to run kernel "[${r}] ${s}"...`));let u=this.env.debug;this.temporaryData=[];try{return u&&this.device.pushErrorScope("validation"),o(e,a[1]),0}catch(t){return n.push(Promise.resolve(`[WebGPU] Kernel "[${r}] ${s}" failed. ${t}`)),1}finally{u&&n.push(this.device.popErrorScope().then((t=>t?`GPU validation error for kernel "[${r}] ${s}": ${t.message}`:null)));for(let t of this.temporaryData)this.gpuDataManager.release(t.id);this.temporaryData=[],this.currentKernelId=null}}registerBuffer(t,e,n,i){let r=this.sessionExternalDataMapping.get(t);r||(r=new Map,this.sessionExternalDataMapping.set(t,r));let s=r.get(e),o=this.gpuDataManager.registerExternalBuffer(n,i,s?.[1]);return r.set(e,[o,n]),o}unregisterBuffers(t){let e=this.sessionExternalDataMapping.get(t);e&&(e.forEach((t=>this.gpuDataManager.unregisterExternalBuffer(t[1]))),this.sessionExternalDataMapping.delete(t))}getBuffer(t){let e=this.gpuDataManager.get(t);if(!e)throw new Error(`no GPU data for buffer: ${t}`);return e.buffer}createDownloader(t,e,n){return async()=>{let i=await we(this,t,e);return ce(i.buffer,n)}}writeTimestamp(t){"inside-passes"===this.queryType&&this.computePassEncoder.writeTimestamp(this.querySet,t)}setQueryType(){this.queryType="none",("default"===this.env.webgpu.profiling?.mode||(typeof this.env.trace>"u"?this.env.wasm.trace:this.env.trace))&&(this.device.features.has("chromium-experimental-timestamp-query-inside-passes")?this.queryType="inside-passes":this.device.features.has("timestamp-query")&&(this.queryType="at-passes"),"none"!==this.queryType&&typeof this.querySet>"u"&&(this.querySet=this.device.createQuerySet({type:"timestamp",count:2*this.maxDispatchNumber}),this.queryResolveBuffer=this.device.createBuffer({size:16*this.maxDispatchNumber,usage:GPUBufferUsage.COPY_SRC|GPUBufferUsage.QUERY_RESOLVE})))}captureBegin(){le("info","captureBegin"),this.capturedCommandList.get(this.currentSessionId)||this.capturedCommandList.set(this.currentSessionId,[]),this.capturedPendingKernels.get(this.currentSessionId)||this.capturedPendingKernels.set(this.currentSessionId,[]),this.flush(),this.sessionStatus="capturing"}captureEnd(){le("info","captureEnd"),this.flush(),this.sessionStatus="default"}replay(){le("info","replay"),this.sessionStatus="replaying";let t=this.capturedCommandList.get(this.currentSessionId),e=this.capturedPendingKernels.get(this.currentSessionId),n=t.length;this.pendingKernels=[];for(let i=0;i<n;i++){let n=this.getComputePassEncoder(),r=t[i];this.writeTimestamp(2*this.pendingDispatchNumber),n.setPipeline(r.computePipeline),n.setBindGroup(0,r.bindGroup),n.dispatchWorkgroups(...r.dispatchGroup),this.writeTimestamp(2*this.pendingDispatchNumber+1),this.pendingDispatchNumber++,"none"!==this.queryType&&this.pendingKernels.push(e[i]),(this.pendingDispatchNumber>=this.maxDispatchNumber||"at-passes"===this.queryType)&&this.endComputePass(),this.pendingDispatchNumber>=this.maxDispatchNumber&&this.flush()}this.flush(),this.sessionStatus="default"}onReleaseSession(t){this.unregisterBuffers(t),this.capturedCommandList.has(t)&&this.capturedCommandList.delete(t),this.capturedPendingKernels.has(t)&&this.capturedPendingKernels.delete(t),this.gpuDataManager.onReleaseSession(t)}onRunStart(t){this.currentSessionId=t,this.setQueryType()}}})),$h={};G($h,{init:()=>Eh});var Sh,Mh,Eh,Ch,Ah,Oh,Ih,Th,zh,Rh,Fh,Ph,Dh,Nh,Uh,qh,jh,Bh,Lh,Hh,Wh,Vh,Gh,Yh,Kh,Xh,Qh,Zh,Jh,tl,el,nl,il,rl,sl,ol,al,ul,hl=V((()=>{gu(),kh(),_u(),Mu(),Sh=class t{constructor(t,e,n,i){this.module=t,this.dataType=e,this.data=n,this.dims=i}getFloat32Array(){if(1!==this.dataType)throw new Error("Invalid data type");let t=Se.size(this.dims);return 0===t?new Float32Array:new Float32Array(this.module.HEAP8.buffer,this.data,t)}getBigInt64Array(){if(7!==this.dataType)throw new Error("Invalid data type");let t=Se.size(this.dims);return 0===t?new BigInt64Array:new BigInt64Array(this.module.HEAP8.buffer,this.data,t)}getInt32Array(){if(6!==this.dataType)throw new Error("Invalid data type");let t=Se.size(this.dims);return 0===t?new Int32Array:new Int32Array(this.module.HEAP8.buffer,this.data,t)}reshape(e){if(Se.size(e)!==Se.size(this.dims))throw new Error("Invalid new shape");return new t(this.module,this.dataType,this.data,e)}},Mh=class{constructor(t,e,n){this.module=t,this.backend=e,this.customDataOffset=0,this.customDataSize=0,this.adapterInfo=e.adapterInfo;let i=t.HEAPU32,r=n>>>2;this.opKernelContext=i[r++];let s=i[r++];this.outputCount=i[r++],this.customDataOffset=i[r++],this.customDataSize=i[r++];let o=[];for(let e=0;e<s;e++){let e=i[r++],n=i[r++],s=i[r++],a=[];for(let t=0;t<s;t++)a.push(i[r++]);o.push(new Sh(t,e,n,a))}this.inputs=o}get kernelCustomData(){return this.backend.currentKernelCustomData}get customDataBuffer(){return this.module.HEAPU8.subarray(this.customDataOffset,this.customDataOffset+this.customDataSize)}getMaxComputeWorkgroupSizes(){return[this.backend.device.limits.maxComputeWorkgroupSizeX,this.backend.device.limits.maxComputeWorkgroupSizeY,this.backend.device.limits.maxComputeWorkgroupSizeZ]}getMaxComputeWorkgroupStoragesize(){return this.backend.device.limits.maxComputeWorkgroupStorageSize}compute(t,e){let n=e?.inputs?.map((t=>"number"==typeof t?this.inputs[t]:t))??this.inputs,i=e?.outputs??[];return this.backend.run(t,n,i,((t,e,n)=>new Sh(this.module,e,this.output(t,n),n)),((t,e)=>{let n=te(t);if(!n)throw new Error(`Unsupported data type: ${t}`);let i=n*Se.size(e),r=i>0?this.backend.gpuDataManager.create(i).id:0;return new Sh(this.module,t,r,e)}),this.outputCount)}output(t,e){let n=this.module.stackSave();try{let n=this.module.stackAlloc(4*(1+e.length)),i=n>>2;this.module.HEAPU32[i++]=e.length;for(let t=0;t<e.length;t++)this.module.HEAPU32[i++]=e[t];return this.module.Rt(this.opKernelContext,t,n)}catch(n){throw new Error(`Failed to generate kernel's output[${t}] with dims [${e}]. If you are running with pre-allocated output, please make sure the output type/dims are correct. Error: ${n}`)}finally{this.module.stackRestore(n)}}},Eh=async(t,e,n,i)=>{let r=e.jsepInit;if(!r)throw new Error("Failed to initialize JSEP. The WebAssembly module is not built with JSEP support.");if("webgpu"===t){let t=new fu;await t.initialize(n,i),r("webgpu",[t,e=>t.alloc(e),e=>t.free(e),(n,i,r,s=!1)=>{if(s)le("verbose",(()=>`[WebGPU] jsepCopyGpuToGpu: src=${n}, dst=${i}, size=${r}`)),t.memcpy(n,i);else{le("verbose",(()=>`[WebGPU] jsepCopyCpuToGpu: dataOffset=${n}, gpuDataId=${i}, size=${r}`));let s=e.HEAPU8.subarray(n>>>0,(n>>>0)+r);t.upload(i,s)}},async(n,i,r)=>{le("verbose",(()=>`[WebGPU] jsepCopyGpuToCpu: gpuDataId=${n}, dataOffset=${i}, size=${r}`)),await t.download(n,(()=>e.HEAPU8.subarray(i>>>0,(i>>>0)+r)))},(n,i,r)=>t.createKernel(n,i,r,e.UTF8ToString(e.Ft(i))),e=>t.releaseKernel(e),(n,i,r,s)=>{le("verbose",(()=>`[WebGPU] jsepRun: sessionHandle=${r}, kernel=${n}, contextDataOffset=${i}`));let o=new Mh(e,t,i);return t.computeKernel(n,o,s)},()=>t.captureBegin(),()=>t.captureEnd(),()=>t.replay()])}else r("webnn")}})),ll=V((()=>{yu(),wu(),gu(),vu(),mu(),bu(),Ch=(t,e)=>{0!==Bt().rt(t,e)&&Wt("Can't initialize onnxruntime.")},Ah=async t=>{Ch(t.wasm.numThreads,ne(t.logLevel))},Oh=async(t,e)=>{{let n=(hl(),Y($h)).init;if("webgpu"===e){if(typeof navigator>"u"||!navigator.gpu)throw new Error("WebGPU is not supported in current environment");let e=t.webgpu.adapter;if(e){if("object"!=typeof e.limits||"object"!=typeof e.features||"function"!=typeof e.requestDevice)throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.")}else{let n=t.webgpu.powerPreference;if(void 0!==n&&"low-power"!==n&&"high-performance"!==n)throw new Error(`Invalid powerPreference setting: "${n}"`);let i=t.webgpu.forceFallbackAdapter;if(void 0!==i&&"boolean"!=typeof i)throw new Error(`Invalid forceFallbackAdapter setting: "${i}"`);if(e=await navigator.gpu.requestAdapter({powerPreference:n,forceFallbackAdapter:i}),!e)throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.')}await n("webgpu",Bt(),t,e)}if("webnn"===e){if(typeof navigator>"u"||!navigator.ml)throw new Error("WebNN is not supported in current environment");await n("webnn",Bt(),t)}}},Ih=new Map,Th=t=>{let e=Bt(),n=e.stackSave();try{let n=e.stackAlloc(8);return 0!==e.yt(t,n,n+4)&&Wt("Can't get session input/output count."),[e.HEAP32[n/4],e.HEAP32[n/4+1]]}finally{e.stackRestore(n)}},zh=t=>{let e=Bt(),n=e.Pt(t.byteLength);if(0===n)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,n),[n,t.byteLength]},Rh=async(t,e)=>{let n,i,r=Bt();Array.isArray(t)?[n,i]=t:t.buffer===r.HEAPU8.buffer?[n,i]=[t.byteOffset,t.byteLength]:[n,i]=zh(t);let s=0,o=0,a=0,u=[],h=[],l=[];try{if([o,u]=Qt(e),e?.externalData&&r.mountExternalData){let t=[];for(let n of e.externalData){let e="string"==typeof n?n:n.path;t.push(se("string"==typeof n?n:n.data).then((t=>{r.mountExternalData(e,t)})))}await Promise.all(t)}for(let t of e?.executionProviders??[])if("webnn"===("string"==typeof t?t:t.name)){if(r.currentContext)throw new Error("WebNN execution provider is already set.");if("string"!=typeof t){let e=t,n=e?.context,i=e?.gpuDevice,s=e?.deviceType,o=e?.numThreads,a=e?.powerPreference;r.currentContext=n||(i?await navigator.ml.createContext(i):await navigator.ml.createContext({deviceType:s,numThreads:o,powerPreference:a}))}else r.currentContext=await navigator.ml.createContext();break}s=await r._(n,i,o),0===s&&Wt("Can't create a session."),r.currentContext&&(r.currentContext=void 0);let[t,c]=Th(s),f=!!e?.enableGraphCapture,d=[],p=[],v=[];for(let e=0;e<t;e++){let t=r.wt(s,e);0===t&&Wt("Can't get an input name."),h.push(t),d.push(r.UTF8ToString(t))}for(let t=0;t<c;t++){let n=r.bt(s,t);0===n&&Wt("Can't get an output name."),l.push(n);let i=r.UTF8ToString(n);p.push(i);{if(f&&void 0===e?.preferredOutputLocation){v.push("gpu-buffer");continue}let t="string"==typeof e?.preferredOutputLocation?e.preferredOutputLocation:e?.preferredOutputLocation?.[i]??"cpu";if("cpu"!==t&&"cpu-pinned"!==t&&"gpu-buffer"!==t)throw new Error(`Not supported preferred output location: ${t}.`);if(f&&"gpu-buffer"!==t)throw new Error(`Not supported preferred output location: ${t}. Only 'gpu-buffer' location is supported when enableGraphCapture is true.`);v.push(t)}}let m=null;return v.some((t=>"gpu-buffer"===t))&&(a=r.Ct(s),0===a&&Wt("Can't create IO binding."),m={handle:a,outputPreferredLocations:v,outputPreferredLocationsEncoded:v.map((t=>re(t)))}),Ih.set(s,[s,h,l,m,f,!1]),[s,d,p]}catch(t){throw h.forEach((t=>r._t(t))),l.forEach((t=>r._t(t))),0!==a&&r.Tt(a),0!==s&&r.vt(s),t}finally{r.Dt(n),0!==o&&r.ft(o),u.forEach((t=>r.Dt(t))),r.unmountExternalData?.()}},Fh=t=>{let e=Bt(),n=Ih.get(t);if(!n)throw new Error(`cannot release session. invalid session id: ${t}`);let[i,r,s,o,a]=n;o&&(a&&e.Ot(o.handle),e.Tt(o.handle)),e.jsepOnReleaseSession?.(t),r.forEach((t=>e._t(t))),s.forEach((t=>e._t(t))),e.vt(i),Ih.delete(t)},Ph=(t,e,n,i,r,s=!1)=>{if(!t)return void e.push(0);let o,a,u=Bt(),h=t[0],l=t[1],c=t[3];if("string"===h&&"gpu-buffer"===c)throw new Error("String tensor is not supported on GPU.");if(s&&"gpu-buffer"!==c)throw new Error(`External buffer must be provided for input/output index ${r} when enableGraphCapture is true.`);if("gpu-buffer"===c){let e=t[2].gpuBuffer,n=te(Zt(h));a=l.reduce(((t,e)=>t*e),1)*n;let s=u.jsepRegisterBuffer;if(!s)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');o=s(i,r,e,a)}else{let e=t[2];if(Array.isArray(e)){a=4*e.length,o=u.Pt(a),n.push(o);let t=o/4;for(let i=0;i<e.length;i++){if("string"!=typeof e[i])throw new TypeError(`tensor data at index ${i} is not a string`);u.HEAPU32[t++]=Lt(e[i],n)}}else a=e.byteLength,o=u.Pt(a),n.push(o),u.HEAPU8.set(new Uint8Array(e.buffer,e.byteOffset,a),o)}let f=u.stackSave(),d=u.stackAlloc(4*l.length);try{let t=d/4;l.forEach((e=>u.HEAP32[t++]=e));let n=u.xt(Zt(h),o,a,d,l.length,re(c));0===n&&Wt(`Can't create tensor for input/output. session=${i}, index=${r}.`),e.push(n)}finally{u.stackRestore(f)}},Dh=async(t,e,n,i,r,s)=>{let o=Bt(),a=Ih.get(t);if(!a)throw new Error(`cannot run inference. invalid session id: ${t}`);let u=a[0],h=a[1],l=a[2],c=a[3],f=a[4],d=a[5],p=e.length,v=i.length,m=0,y=[],w=[],g=[],b=[],_=o.stackSave(),x=o.stackAlloc(4*p),k=o.stackAlloc(4*p),$=o.stackAlloc(4*v),S=o.stackAlloc(4*v);try{[m,y]=Vt(s);for(let i=0;i<p;i++)Ph(n[i],w,b,t,e[i],f);for(let e=0;e<v;e++)Ph(r[e],g,b,t,p+i[e],f);let a,_=x/4,M=k/4,E=$/4,C=S/4;for(let t=0;t<p;t++)o.HEAPU32[_++]=w[t],o.HEAPU32[M++]=h[e[t]];for(let t=0;t<v;t++)o.HEAPU32[E++]=g[t],o.HEAPU32[C++]=l[i[t]];if(c&&!d){let{handle:n,outputPreferredLocations:s,outputPreferredLocationsEncoded:a}=c;if(h.length!==p)throw new Error(`input count from feeds (${p}) is expected to be always equal to model's input count (${h.length}).`);for(let i=0;i<p;i++){let r=e[i];0!==await o.nt(n,h[r],w[i])&&Wt(`Can't bind input[${i}] for session=${t}.`)}for(let e=0;e<v;e++){let u=i[e];r[e]?.[3]?0!==o.At(n,l[u],g[e],0)&&Wt(`Can't bind pre-allocated output[${e}] for session=${t}.`):0!==o.At(n,l[u],0,a[u])&&Wt(`Can't bind output[${e}] to ${s[e]} for session=${t}.`)}Ih.set(t,[u,h,l,c,f,!0])}o.jsepOnRunStart?.(u),a=c?await o.et(u,c.handle,v,$,m):await o.tt(u,k,x,p,S,v,$,m),0!==a&&Wt("failed to call OrtRun().");let A=[];for(let t=0;t<v;t++){let e=o.HEAPU32[$/4+t];if(e===g[t]){A.push(r[t]);continue}let n,s=o.stackSave(),a=o.stackAlloc(16),u=!1,h=0;try{0!==o.kt(e,a,a+4,a+8,a+12)&&Wt(`Can't access output tensor data on index ${t}.`);let r=a/4,s=o.HEAPU32[r++];h=o.HEAPU32[r++];let l=o.HEAPU32[r++],f=o.HEAPU32[r++],d=[];for(let t=0;t<f;t++)d.push(o.HEAPU32[l/4+t]);o._t(l);let p=d.reduce(((t,e)=>t*e),1);n=Jt(s);let v=c?.outputPreferredLocations[i[t]];if("string"===n){if("gpu-buffer"===v)throw new Error("String tensor is not supported on GPU.");let t=[],e=h/4;for(let n=0;n<p;n++){let i=o.HEAPU32[e++],r=n===p-1?void 0:o.HEAPU32[e]-i;t.push(o.UTF8ToString(i,r))}A.push([n,d,t,"cpu"])}else if("gpu-buffer"===v&&p>0){let t=o.jsepGetBuffer;if(!t)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let i=t(h),r=te(s);if(void 0===r||!ie(n))throw new Error(`Unsupported data type: ${n}`);u=!0,A.push([n,d,{gpuBuffer:i,download:o.jsepCreateDownloader(i,p*r,n),dispose:()=>{o.$t(e)}},"gpu-buffer"])}else{let t=new(ee(n))(p);new Uint8Array(t.buffer,t.byteOffset,t.byteLength).set(o.HEAPU8.subarray(h,h+t.byteLength)),A.push([n,d,t,"cpu"])}}finally{o.stackRestore(s),"string"===n&&h&&o.Dt(h),u||o.$t(e)}}return c&&!f&&(o.Ot(c.handle),Ih.set(t,[u,h,l,c,f,!1])),A}finally{o.stackRestore(_),w.forEach((t=>o.$t(t))),g.forEach((t=>o.$t(t))),b.forEach((t=>o.Dt(t))),0!==m&&o.Et(m),y.forEach((t=>o.Dt(t)))}},Nh=t=>{let e=Bt(),n=Ih.get(t);if(!n)throw new Error("invalid session id");let i=n[0],r=e.zt(i);0===r&&Wt("Can't get an profile file name."),e._t(r)},Uh=t=>{let e=[];for(let n of t){let t=n[2];!Array.isArray(t)&&"buffer"in t&&e.push(t.buffer)}return e}})),cl=V((()=>{mt(),ll(),vu(),pu(),qh=()=>!!y.wasm.proxy&&typeof document<"u",Bh=!1,Lh=!1,Hh=!1,Gh=new Map,Yh=(t,e)=>{let n=Gh.get(t);n?n.push(e):Gh.set(t,[e])},Kh=()=>{if(Bh||!Lh||Hh||!jh)throw new Error("worker not ready")},Xh=t=>{switch(t.data.type){case"init-wasm":Bh=!1,t.data.err?(Hh=!0,Vh[1](t.data.err)):(Lh=!0,Vh[0]()),Wh&&(URL.revokeObjectURL(Wh),Wh=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=Gh.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}}},Qh=async()=>{if(!Lh){if(Bh)throw new Error("multiple calls to 'initWasm()' detected.");if(Hh)throw new Error("previous call to 'initWasm()' failed.");if(Bh=!0,qh())return new Promise(((t,e)=>{jh?.terminate(),Tt().then((([n,i])=>{try{(jh=i).onerror=t=>e(t),jh.onmessage=Xh,Vh=[t,e];let r={type:"init-wasm",in:y};jh.postMessage(r),Wh=n}catch(t){e(t)}}),e)}));try{await jt(y.wasm),await Ah(y),Lh=!0}catch(t){throw Hh=!0,t}finally{Bh=!1}}},Zh=async t=>{if(qh())return Kh(),new Promise(((e,n)=>{Yh("init-ep",[e,n]);let i={type:"init-ep",in:{epName:t,env:y}};jh.postMessage(i)}));await Oh(y,t)},Jh=async t=>qh()?(Kh(),new Promise(((e,n)=>{Yh("copy-from",[e,n]);let i={type:"copy-from",in:{buffer:t}};jh.postMessage(i,[t.buffer])}))):zh(t),tl=async(t,e)=>{if(qh()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return Kh(),new Promise(((n,i)=>{Yh("create",[n,i]);let r={type:"create",in:{model:t,options:{...e}}},s=[];t instanceof Uint8Array&&s.push(t.buffer),jh.postMessage(r,s)}))}return Rh(t,e)},el=async t=>{if(qh())return Kh(),new Promise(((e,n)=>{Yh("release",[e,n]);let i={type:"release",in:t};jh.postMessage(i)}));Fh(t)},nl=async(t,e,n,i,r,s)=>{if(qh()){if(n.some((t=>"cpu"!==t[3])))throw new Error("input tensor on GPU is not supported for proxy.");if(r.some((t=>t)))throw new Error("pre-allocated output tensor is not supported for proxy.");return Kh(),new Promise(((r,o)=>{Yh("run",[r,o]);let a=n,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:a,outputIndices:i,options:s}};jh.postMessage(u,Uh(a))}))}return Dh(t,e,n,i,r,s)},il=async t=>{if(qh())return Kh(),new Promise(((e,n)=>{Yh("end-profiling",[e,n]);let i={type:"end-profiling",in:t};jh.postMessage(i)}));Nh(t)}})),fl=V((()=>{mt(),cl(),gu(),yt(),bu(),rl=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},sl=t=>{switch(t[3]){case"cpu":return new T(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!ie(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:n,download:i,dispose:r}=t[2];return T.fromGpuBuffer(n,{dataType:e,dims:t[1],download:i,dispose:r})}default:throw new Error(`invalid data location: ${t[3]}`)}},ol=class{async fetchModelAndCopyToWasmMemory(t){return Jh(await se(t))}async loadModel(t,e){let n;F(),n="string"==typeof t?await this.fetchModelAndCopyToWasmMemory(t):t,[this.sessionId,this.inputNames,this.outputNames]=await tl(n,e),P()}async dispose(){return el(this.sessionId)}async run(t,e,n){F();let i=[],r=[];Object.entries(t).forEach((t=>{let e=t[0],n=t[1],s=this.inputNames.indexOf(e);if(-1===s)throw new Error(`invalid input '${e}'`);i.push(n),r.push(s)}));let s=[],o=[];Object.entries(e).forEach((t=>{let e=t[0],n=t[1],i=this.outputNames.indexOf(e);if(-1===i)throw new Error(`invalid output '${e}'`);s.push(n),o.push(i)}));let a=i.map(((t,e)=>rl(t,(()=>`input "${this.inputNames[r[e]]}"`)))),u=s.map(((t,e)=>t?rl(t,(()=>`output "${this.outputNames[o[e]]}"`)):null)),h=await nl(this.sessionId,r,a,o,u,n),l={};for(let t=0;t<h.length;t++)l[this.outputNames[o[t]]]=s[t]??sl(h[t]);return P(),l}startProfiling(){}endProfiling(){il(this.sessionId)}}})),dl=V((()=>{mt(),cl(),fl(),pu(),al=()=>{if(("number"!=typeof y.wasm.initTimeout||y.wasm.initTimeout<0)&&(y.wasm.initTimeout=0),y.wasm.simd,"boolean"!=typeof y.wasm.proxy&&(y.wasm.proxy=!1),"boolean"!=typeof y.wasm.trace&&(y.wasm.trace=!1),"number"!=typeof y.wasm.numThreads||!Number.isInteger(y.wasm.numThreads)||y.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)y.wasm.numThreads=1;else{let t=typeof navigator>"u"?W("node:os").cpus().length:navigator.hardwareConcurrency;y.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}},ul=class{async init(t){al(),await Qh(),await Zh(t)}async createInferenceSessionHandler(t,e){let n=new ol;return await n.loadModel(t,e),Promise.resolve(n)}}})),pl={};G(pl,{wasmBackend:()=>vl});var vl,ml=V((()=>{dl(),vl=new ul}));mt(),mt(),mt();var yl=vt;{let t=(ml(),Y(pl)).wasmBackend;c("webgpu",t,5),c("webnn",t,5),c("cpu",t,10),c("wasm",t,10)}Object.defineProperty(y.versions,"web",{value:"1.19.2",enumerable:!0});let wl=new Worker(URL.createObjectURL(new Blob(["(",function(){const t=262145;let e=new Uint32Array(t),n=new Uint32Array(2e7),i=new Uint32Array(2e7);self.onmessage=r=>{(async r=>{((r,s)=>{const o=r.qt,a=!!o.find((t=>t.jt)),u=r.Bt;let h=1/0,l=-1/0,c=0,f=1/0,d=0;const p=a?6:2,v=Math.floor(u/p),m=u*v;for(let t=0,e=o.length;t<e;t+=1){const e=o[t],{Lt:n,Ht:i,Wt:r,Vt:s,Gt:a,Yt:u,Kt:p}=e;c+=p,f=Math.min(f,u),d=Math.max(d,u);const v=r[2],m=r[6],y=r[10],w=r[14];for(let t=0;t<8;++t){let e=v*(1&t?i[0]:n[0])+m*(2&t?i[1]:n[1])+y*(4&t?i[2]:n[2])+w;h=Math.min(h,e),l=Math.max(l,e)}}h-=1;const y=t*(d-f+1);e=y<e.length?new Uint32Array(e.buffer,0,y):new Uint32Array(y),c<n.length?(n=new Uint32Array(n.buffer,0,c),i=new Uint32Array(i.buffer,0,c)):c>n.length&&(n=new Uint32Array(c),i=new Uint32Array(c));for(var w=0;w<y;w+=1)e[w]=0;const g=1/(l-h)*262144,b=[],_=Math.ceil(Math.log2(u*u));let x,k=0;for(let r=0,s=o.length;r<s;r+=1){const s=o[r],{Lt:a,Ht:l,Wt:c,Vt:f,Gt:y,Yt:w,Xt:x,Kt:$}=s;let S=0;for(let t=0,e=x.length;t<e;t+=1){const n=x[t];let i=b.indexOf(n._id);-1==i?(b.push(n._id),n.Qt=b.length-1):n.Qt=i;let r,s=f+"_"+t;r=t<e-1?n.Zt[s][1]*v:$-S,n.pixelOffsetInThisTexture=n.Zt[s][0]*u,n.countInThisTexture=r,n.startIdxInTile=S,S+=r}const M=d-w,E=c[2],C=c[6],A=c[10],O=c[14],I=new Float32Array(y);let T=0,z=x[T],R=z.Qt,F=z.startIdxInTile;for(let r=0;r<$;r+=1){const s=3*r,o=((E*I[s]+C*I[s+1]+A*I[s+2]+O-h)*g|0)+M*t;if(n[k]=o,x.length>1&&r>=m){const t=r/m|0;t!==T&&(T=t,z=x[T],R=z.Qt,F=z.startIdxInTile)}const a=r-F,l=z.pixelOffsetInThisTexture+(a/v|0)*u+a%v*p;i[k]=(R<<_)+l,e[o]+=1,k+=1}}for(let t=1;t<y;t+=1)e[t]+=e[t-1];x=r.Jt.length<i.length?new Int32Array(i.length):new Int32Array(r.Jt);for(let t=i.length-1;t>=0;t--){const r=n[t];x[--e[r]]=i[t]}x=x.reverse();const $=[],S=[],M=[],E=[0],C=[];o.forEach((t=>{$.push(t.Vt),S.push(t.te),C.push(t.Yt),M.push(t.Gt),E.push(t.Kt+E[E.length-1])})),E.pop(),self.postMessage({ee:s,jt:a,ne:$,ie:S,Gt:M,Zt:E,Jt:x,re:b,se:x.length-k,oe:k},[x.buffer,...M])})(r,r.ee)})(r.data)}}.toString(),")(self)"],{type:"application/javascript"})));const gl=wl;for(var bl,_l=[],xl=0;xl<256;++xl)_l.push((xl+256).toString(16).slice(1));var kl=new Uint8Array(16);function $l(){if(!bl&&!(bl="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return bl(kl)}var Sl={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Ml(t,e,n){if(Sl.randomUUID&&!t)return Sl.randomUUID();var i=(t=t||{}).random||(t.rng||$l)();return i[6]=15&i[6]|64,i[8]=63&i[8]|128,function(t,e=0){return(_l[t[e+0]]+_l[t[e+1]]+_l[t[e+2]]+_l[t[e+3]]+"-"+_l[t[e+4]]+_l[t[e+5]]+"-"+_l[t[e+6]]+_l[t[e+7]]+"-"+_l[t[e+8]]+_l[t[e+9]]+"-"+_l[t[e+10]]+_l[t[e+11]]+_l[t[e+12]]+_l[t[e+13]]+_l[t[e+14]]+_l[t[e+15]]).toLowerCase()}(i)}class El{static idCount=0;_id;ae;ue;he;ce;fe;_texture;Zt={};de;pe=-2;ve=0;me=!1;constructor(t,e){this._id=El.idCount++,this.fe=e,this.ue=this.he=t,this.de=[[0,this.he]],this.ce=t,this._texture=new r.Texture({name:this._id,context:this.fe,internalFormat:r.WebGLConstants.RGBA32F,pixelFormat:r.WebGLConstants.RGBA,pixelDatatype:r.WebGLConstants.FLOAT,width:t,height:t,flipY:!1,sampler:new r.Sampler({minificationFilter:r.TextureMinificationFilter.NEAREST,magnificationFilter:r.TextureMagnificationFilter.NEAREST})})}ye(t,e,n){const i=this.we(t.height),r=this.de[i][0];this._texture.copyFrom({xOffset:0,yOffset:r,source:t}),this.Zt[e]=[r,t.height],this.ce-=t.height,this.ae?(this.ae.x=(this.ae.x*this.ve+n.x)/(this.ve+1),this.ae.y=(this.ae.y*this.ve+n.y)/(this.ve+1),this.ae.z=(this.ae.z*this.ve+n.z)/(this.ve+1)):this.ae=n,this.ve+=1,this.be()}_e(t,e){this.ce+=this.Zt[t][1],delete this.Zt[t],this.be(),this.de.length&&this.ae?(this.ae.x=(this.ae.x*this.ve-e.x)/(this.ve-1),this.ae.y=(this.ae.y*this.ve-e.y)/(this.ve-1),this.ae.z=(this.ae.z*this.ve-e.z)/(this.ve-1)):this.ae=void 0,this.ve-=1}be(){const t=Object.values(this.Zt).map((t=>[t[0],t[0]+t[1]])).sort(((t,e)=>t[0]<e[0]?-1:1)).flat();t.unshift(0),t.push(this.he);const e=[];for(let n=0;n<t.length;n+=2)t[n]!==t[n+1]&&e.push([t[n],t[n+1]]);this.de=e}we(t){for(let e=0;e<this.de.length;e+=1)if(this.de[e][1]-this.de[e][0]>=t)return e;return-1}xe(){this.ce=this.he,this.ae=void 0,this.ve=0,this.Zt={},this.de=[[0,this.he]]}ke(){return this.ce===this.he}_destroy(){this.me||(this.me=!0,this.xe(),this._texture.destroy(),this._texture=null)}}class Cl{$e=[];Se={};fe;Bt;Xt={};constructor(t,e){this.fe=t,this.Bt=e}Me(t){return t.map((t=>this.Xt[t]))}Ee(t,e,n,i){if(this.Se[i]){let r=this.Ce(t,e,n,this.Se[i]);return r||(r=this.$e.length?this.$e.pop():new El(this.Bt,this.fe),r.pe=i,this.Se[i].push(r),this.Xt[r._id]=r),r}{this.Se[i]=[];const t=new El(this.Bt,this.fe);return t.pe=i,this.Se[i].push(t),this.Xt[t._id]=t,t}}_destroy(){Object.keys(this.Se).forEach((t=>{this.Se[t].forEach((t=>{t._destroy(),delete this.Xt[t._id]})),delete this.Se[t]})),this.$e.forEach((t=>{t._destroy(),delete this.Xt[t._id]})),this.$e=[]}Ce(t,n,i,r){let s,o=1/0;for(let a=r.length-1;a>=0;a-=1){const u=r[a];if(-1!==u.we(i)){const i=e.Cartesian3.distance(t,u.ae);i<n&&i<o&&(o=i,s=u)}}return s}Ae(t){const{Xt:e}=t;e?.forEach(((e,n)=>{const i=t.Oe+"_"+n;if(e._e(i,t.Ie),e.ke()){e.xe(),this.$e.length<2?this.$e.push(e):e._destroy();const n=this.Se[t.Yt].indexOf(e);-1!==n&&this.Se[t.Yt].splice(n,1),delete this.Xt[e._id]}}))}}class Al{Te=Ml();fe;ze=0;Re;_texture;Fe;textureWidth;Pe=!0;De;Ne={Gt:new ArrayBuffer(0),Wt:[],oe:0,Lt:[0,0,0],Ht:[0,0,0]};Ue;afterSort;qe={Jt:new Int32Array(0),ne:[],_modelMatrix:r.Matrix4.IDENTITY.clone(),Xt:[],oe:0,je:-1,Be:void 0,Le:[0],jt:!1};He=[0,0,0];constructor(t){this.fe=t.fe,this.Fe=t.Fe,this.textureWidth=Math.min(4096,this.fe._gl.getParameter(this.fe._gl.MAX_TEXTURE_SIZE)),this.Ue=new Cl(this.fe,this.textureWidth),gl.addEventListener("message",(t=>{this.We(t.data)})),t.Ve&&(this.De=t.Ve,this.Ge(),this.Ye()),this.He=t.He}updateData(t,e){this.De=t,this.He=e,this.Ge(),this.Ye()}We(t){const{Jt:e,Zt:n,oe:i,ee:s}=t;if(s!==this.Te)return;const o=r.Cartesian3.fromDegrees(this.Fe[0],this.Fe[1],this.Fe[2]),a=r.Transforms.eastNorthUpToFixedFrame(o);this.qe={ne:["single-model"],Jt:e,_modelMatrix:a,Xt:[this._texture],oe:i,je:this.qe.je,Be:this.qe.Be,Le:[i],jt:!1},this.Pe=!0,this.afterSort&&this.afterSort(this.qe)}Ye(){if(this._texture&&this._texture.destroy(),!this.De)return;const t=this.textureWidth;let e=Math.ceil(this.De.byteLength/16/t);e=Math.pow(2,Math.ceil(Math.log2(e)));const n=new Float32Array(new ArrayBuffer(t*e*16));n.set(new Float32Array(this.De),0);const i=new r.Cartesian3(this.He[0],this.He[1],this.He[2]),s=this.Ue.Ee(i,600,e,4);s.ye({width:t,height:e,arrayBufferView:n},"single-buffer",i),this._texture=s}_destroy(){this.qe=void 0,this.Ne=void 0}Ke(t,e){this.qe.je=t,this.qe.Be=e||void 0}Xe(t){const e=t.camera.viewMatrix,n=(new Date).getTime();let i=!1;if(!(0==this.Pe||this.qe&&this.qe.Jt.buffer.detached)&&(this.ze?this.Qe(this.Re,e)&&(i=!0):i=!0,i)){const i=t.camera.frustum.projectionMatrix;this.ze=n,this.Re=e.clone(),this.Pe=!1;const s=[this.qe.Jt.buffer],o=r.Cartesian3.fromDegrees(this.Fe[0],this.Fe[1],this.Fe[2]),a=r.Transforms.eastNorthUpToFixedFrame(o);r.Matrix4.multiply(e,a,a),r.Matrix4.multiply(i,a,a);const u={ee:this.Te,Ze:e,Jt:this.qe.Jt,Zt:[0],qt:[{Yt:0,Vt:this.Te,Gt:this.Ne.Gt,Wt:a,Lt:this.Ne.Lt,Ht:this.Ne.Ht,Kt:this.Ne.oe}]};gl.postMessage(u,s)}}Qe(t,e){let n=t[2]*e[2]+t[6]*e[6]+t[10]*e[10];const i=(t[2]**2+t[6]**2+t[10]**2)**.5,r=(e[2]**2+e[6]**2+e[10]**2)**.5;return Math.abs(n/i/r-1)>.01}Ge(){if(!this.De)return;const t=new Float32Array(this.De),e=[1/0,1/0,1/0,-1/0,-1/0,-1/0],n=new Float32Array(this.De.byteLength/8/4*3);for(let i=0;i<t.length;i+=8){const r=t[i],s=t[i+1],o=t[i+2];n[i/8*3]=r,n[i/8*3+1]=s,n[i/8*3+2]=o,e[0]=Math.min(e[0],r),e[1]=Math.min(e[1],s),e[2]=Math.min(e[2],o),e[3]=Math.max(e[3],r),e[4]=Math.max(e[4],s),e[5]=Math.max(e[5],o)}this.Ne.Ht=[e[0],e[1],e[2]],this.Ne.Lt=[e[3],e[4],e[5]],this.Ne.Gt=n.buffer,this.Ne.oe=n.length/3}}var Ol="#version 300 es\nprecision highp int;precision highp float;in vec3 position;in float pIdx;uniform vec2 viewport;uniform highp sampler2D u_txts[16];uniform mat4 u_mvs;uniform mat4 u_view;uniform mat3 u_normalMatrix;uniform ivec4 u_params;uniform int u_sltid;uniform vec4 u_sltc;uniform vec2 u_filter;out vec3 texCoord;out vec4 color;out vec4 allMap;out vec3 vPosition;out float maxScale;vec3 rgbToHls(vec3 rgb){float maxC=max(max(rgb.r,rgb.g),rgb.b);float minC=min(min(rgb.r,rgb.g),rgb.b);float h,l,s;l=(maxC+minC)/2.0f;if(maxC==minC){s=0.0f;h=0.0f;}else{float delta=maxC-minC;s=(l<0.5f)? delta/(maxC+minC): delta/(2.0f-maxC-minC);if(maxC==rgb.r){h=(rgb.g-rgb.b)/delta+(rgb.g<rgb.b ? 6.0f : 0.0f);}else if(maxC==rgb.g){h=(rgb.b-rgb.r)/delta+2.0f;}else{h=(rgb.r-rgb.g)/delta+4.0f;}h/=6.0f;}return vec3(h,l,s);}float hueToRgb(float t1,float t2,float hue){if(hue<0.0f)hue+=1.0f;if(hue>1.0f)hue-=1.0f;if(hue<1.0f/6.0f)return t1+(t2-t1)*6.0f*hue;if(hue<0.5f)return t2;if(hue<2.0f/3.0f)return t1+(t2-t1)*(2.0f/3.0f-hue)*6.0f;return t1;}vec3 hlsToRgb(vec3 hls){float h=hls.x;float l=hls.y;float s=hls.z;vec3 rgb;if(s==0.0f){rgb=vec3(l);}else{float temp2=(l<0.5f)? l*(1.0f+s): l+s-l*s;float temp1=2.0f*l-temp2;rgb.r=hueToRgb(temp1,temp2,h+1.0f/3.0f);rgb.g=hueToRgb(temp1,temp2,h);rgb.b=hueToRgb(temp1,temp2,h-1.0f/3.0f);}return rgb;}vec4 modify(vec4 color,vec2 f){vec3 hls=rgbToHls(color.xyz);hls.y*=f.x;hls.z*=f.y;hls=clamp(hls,0.0f,1.0f);return vec4(hlsToRgb(hls),color.a);}vec3 unpack111011s(uint bits){return vec3((uvec3(bits)>>uvec3(21u,11u,0u))&uvec3(0x7ffu,0x3ffu,0x7ffu))/vec3(2047.0f,1023.0f,2047.0f)*2.0f-1.0f;}void fetchScale(in uvec4 t,out float scale,out vec3 a,out vec3 b,out vec3 c){scale=uintBitsToFloat(t.x);a=unpack111011s(t.y);b=unpack111011s(t.z);c=unpack111011s(t.w);}void fetch(in uvec4 t,out vec3 a,out vec3 b,out vec3 c,out vec3 d){a=unpack111011s(t.x);b=unpack111011s(t.y);c=unpack111011s(t.z);d=unpack111011s(t.w);}void fetch(in uint t,out vec3 a){a=unpack111011s(t);}void readSHData(in uvec4 p0,in uvec4 p1,in uvec4 p2,in uvec4 p3,out vec3 sh[15],out float scale){fetchScale(p0,scale,sh[0],sh[1],sh[2]);fetch(p1,sh[3],sh[4],sh[5],sh[6]);fetch(p2,sh[7],sh[8],sh[9],sh[10]);fetch(p3,sh[11],sh[12],sh[13],sh[14]);}\n#define SH_C1 0.4886025119029199f\n#define SH_C2_0 1.0925484305920792f\n#define SH_C2_1 -1.0925484305920792f\n#define SH_C2_2 0.31539156525252005f\n#define SH_C2_3 -1.0925484305920792f\n#define SH_C2_4 0.5462742152960396f\n#define SH_C3_0 -0.5900435899266435f\n#define SH_C3_1 2.890611442640554f\n#define SH_C3_2 -0.4570457994644658f\n#define SH_C3_3 0.3731763325901154f\n#define SH_C3_4 -0.4570457994644658f\n#define SH_C3_5 1.445305721320277f\n#define SH_C3_6 -0.5900435899266435f\nvec3 evalSH(in uvec4 p0,in uvec4 p1,in uvec4 p2,in uvec4 p3,in vec3 dir){vec3 sh[15];float scale;readSHData(p0,p1,p2,p3,sh,scale);float x=dir.x;float y=dir.y;float z=dir.z;vec3 result=SH_C1*(-sh[0]*y+sh[1]*z-sh[2]*x);float xx=x*x;float yy=y*y;float zz=z*z;float xy=x*y;float yz=y*z;float xz=x*z;result+=sh[3]*(SH_C2_0*xy)*+sh[4]*(SH_C2_1*yz)+sh[5]*(SH_C2_2*(2.0f*zz-xx-yy))+sh[6]*(SH_C2_3*xz)+sh[7]*(SH_C2_4*(xx-yy));result+=sh[8]*(SH_C3_0*y*(3.0f*xx-yy))+sh[9]*(SH_C3_1*xy*z)+sh[10]*(SH_C3_2*y*(4.0f*zz-xx-yy))+sh[11]*(SH_C3_3*z*(2.0f*zz-3.0f*xx-3.0f*yy))+sh[12]*(SH_C3_4*x*(4.0f*zz-xx-yy))+sh[13]*(SH_C3_5*z*(xx-yy))+sh[14]*(SH_C3_6*x*(xx-3.0f*yy));return result*scale;}void main(){int idx=floatBitsToInt(pIdx);int px=u_params.x;int py=u_params.y;int bits=u_params.z;int tw=u_params.w;bool hasSH=px==1;int texId=idx>>bits;idx=idx&((1<<bits)-1);int v=idx/tw;int u_1=idx % tw;int u_2=u_1+1;ivec2 a=ivec2(u_1,v);highp vec4 ct;vec4 cvf;uvec4 p0,p1,p2,p3;switch(texId){case 0:ct=texelFetch(u_txts[0],a,0);a.x+=1;cvf=texelFetch(u_txts[0],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[0],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[0],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[0],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[0],a,0));}break;case 1:ct=texelFetch(u_txts[1],a,0);a.x+=1;cvf=texelFetch(u_txts[1],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[1],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[1],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[1],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[1],a,0));}break;case 2:ct=texelFetch(u_txts[2],a,0);a.x+=1;cvf=texelFetch(u_txts[2],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[2],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[2],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[2],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[2],a,0));}break;case 3:ct=texelFetch(u_txts[3],a,0);a.x+=1;cvf=texelFetch(u_txts[3],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[3],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[3],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[3],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[3],a,0));}break;case 4:ct=texelFetch(u_txts[4],a,0);a.x+=1;cvf=texelFetch(u_txts[4],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[4],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[4],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[4],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[4],a,0));}break;case 5:ct=texelFetch(u_txts[5],a,0);a.x+=1;cvf=texelFetch(u_txts[5],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[5],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[5],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[5],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[5],a,0));}break;case 6:ct=texelFetch(u_txts[6],a,0);a.x+=1;cvf=texelFetch(u_txts[6],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[6],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[6],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[6],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[6],a,0));}break;case 7:ct=texelFetch(u_txts[7],a,0);a.x+=1;cvf=texelFetch(u_txts[7],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[7],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[7],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[7],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[7],a,0));}break;case 8:ct=texelFetch(u_txts[8],a,0);a.x+=1;cvf=texelFetch(u_txts[8],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[8],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[8],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[8],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[8],a,0));}break;case 9:ct=texelFetch(u_txts[9],a,0);a.x+=1;cvf=texelFetch(u_txts[9],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[9],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[9],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[9],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[9],a,0));}break;case 10:ct=texelFetch(u_txts[10],a,0);a.x+=1;cvf=texelFetch(u_txts[10],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[10],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[10],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[10],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[10],a,0));}break;case 11:ct=texelFetch(u_txts[11],a,0);a.x+=1;cvf=texelFetch(u_txts[11],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[11],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[11],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[11],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[11],a,0));}break;case 12:ct=texelFetch(u_txts[12],a,0);a.x+=1;cvf=texelFetch(u_txts[12],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[12],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[12],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[12],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[12],a,0));}break;case 13:ct=texelFetch(u_txts[13],a,0);a.x+=1;cvf=texelFetch(u_txts[13],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[13],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[13],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[13],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[13],a,0));}break;case 14:ct=texelFetch(u_txts[14],a,0);a.x+=1;cvf=texelFetch(u_txts[14],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[14],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[14],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[14],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[14],a,0));}break;case 15:ct=texelFetch(u_txts[15],a,0);a.x+=1;cvf=texelFetch(u_txts[15],a,0);if(hasSH){a.x+=1;p0=floatBitsToUint(texelFetch(u_txts[15],a,0));a.x+=1;p1=floatBitsToUint(texelFetch(u_txts[15],a,0));a.x+=1;p2=floatBitsToUint(texelFetch(u_txts[15],a,0));a.x+=1;p3=floatBitsToUint(texelFetch(u_txts[15],a,0));}break;}vec4 splat_cam=u_mvs*vec4(ct.xyz,1);vec4 splat_proj=czm_projection*splat_cam;splat_proj.z=clamp(splat_proj.z,-abs(splat_proj.w),abs(splat_proj.w));vPosition=ct.xyz;if(splat_proj.z<-splat_proj.w){gl_Position=vec4(0.0f,0.0f,0.0f,0.0f);return;}uvec4 cov=floatBitsToUint(cvf);vec2 s1=unpackHalf2x16(cov.y),s2=unpackHalf2x16(cov.z);vec3 scale=vec3(s1.x,s1.y,s2.x);maxScale=max(max(s1.x,s1.y),s2.x);vec4 rot=vec4((cov.x)&0xffu,(cov.x>>8)&0xffu,(cov.x>>16)&0xffu,(cov.x>>24)&0xffu);rot=(rot-128.0f)/128.0f;mat3 M=mat3((1.0f-2.0f*(rot.z*rot.z+rot.w*rot.w))*scale.x,(2.0f*(rot.y*rot.z+rot.x*rot.w))*scale.x,(2.0f*(rot.y*rot.w-rot.x*rot.z))*scale.x,(2.0f*(rot.y*rot.z-rot.x*rot.w))*scale.y,(1.0f-2.0f*(rot.y*rot.y+rot.w*rot.w))*scale.y,(2.0f*(rot.z*rot.w+rot.x*rot.y))*scale.y,(2.0f*(rot.y*rot.w+rot.x*rot.z))*scale.z,(2.0f*(rot.z*rot.w-rot.x*rot.y))*scale.z,(1.0f-2.0f*(rot.y*rot.y+rot.z*rot.z))*scale.z);vec2 u1=vec2(M[0].x*M[0].x+M[1].x*M[1].x+M[2].x*M[2].x,M[0].x*M[0].y+M[1].x*M[1].y+M[2].x*M[2].y)*4.0f;vec2 u2=vec2(M[0].x*M[0].z+M[1].x*M[1].z+M[2].x*M[2].z,M[0].y*M[0].y+M[1].y*M[1].y+M[2].y*M[2].y)*4.0f;vec2 u3=vec2(M[0].y*M[0].z+M[1].y*M[1].z+M[2].y*M[2].z,M[0].z*M[0].z+M[1].z*M[1].z+M[2].z*M[2].z)*4.0f;mat3 Vrk=mat3(u1.x,u1.y,u2.x,u1.y,u2.y,u3.x,u2.x,u3.x,u3.y);float focal=viewport.x*czm_projection[0][0];mat3 J=mat3(focal/splat_cam.z,0.f,-(focal*splat_cam.x)/(splat_cam.z*splat_cam.z),0.f,focal/splat_cam.z,-(focal*splat_cam.y)/(splat_cam.z*splat_cam.z),0.f,0.f,0.f);mat3 W=transpose(mat3(u_mvs));mat3 T=W*J;mat3 cov2d=transpose(T)*Vrk*T;float diagonal1=cov2d[0][0];float offDiagonal=cov2d[0][1];float diagonal2=cov2d[1][1];float mid=0.5f*(diagonal1+diagonal2);float _radius=length(vec2((diagonal1-diagonal2)/2.0f,offDiagonal));float lambda1=mid+_radius;float lambda2=max(mid-_radius,0.1f);vec2 diagonalVector=normalize(vec2(offDiagonal,lambda1-diagonal1));vec2 v1=min(sqrt(2.0f*lambda1),1024.0f)*diagonalVector;vec2 v2=min(sqrt(2.0f*lambda2),1024.0f)*vec2(diagonalVector.y,-diagonalVector.x);color=clamp(splat_proj.z/splat_proj.w+1.0f,0.0f,1.0f)*vec4((cov.w)&0xffu,(cov.w>>8)&0xffu,(cov.w>>16)&0xffu,(cov.w>>24)&0xffu)/255.0f;if(px==1){vec3 splat_view=splat_cam.xyz/splat_cam.w;vec3 dir=normalize(splat_view*mat3(u_mvs));color.xyz+=evalSH(p0,p1,p2,p3,dir);}color=modify(color,u_filter);if((u_sltid!=0&&(floatBitsToUint(ct.w)&0xffu)==uint(u_sltid))||u_sltid==-1){if(u_sltc.a==0.0f){return;}color.rgb=mix(color.rgb,u_sltc.rgb,u_sltc.a);}texCoord=vec3(position.xy,clamp(splat_proj.z,50.0f,1000.0f));vec2 vct=vec2(splat_proj)/splat_proj.w;gl_Position=vec4((vct+position.x*v1/viewport+position.y*v2/viewport)*splat_proj.w,splat_proj.z,splat_proj.w);vec3 smallAxis=M[0]/max(0.001f,scale.x);if(scale.y<scale.x&&scale.y<scale.z){smallAxis=M[1]/max(0.001f,scale.y);}else if(scale.z<scale.x&&scale.z<scale.y){smallAxis=M[2]/max(0.001f,scale.z);}vec3 normal=(u_normalMatrix*smallAxis);vec3 localNormal=mat3(u_view)*normal;float negMask=dot(localNormal,-splat_cam.xyz)<0.0f ?-1.0f : 1.0f;if(negMask<0.0f){localNormal=-localNormal;}float localDistance=abs(dot(localNormal.xyz,splat_cam.xyz));allMap=vec4(localNormal,localDistance);vPosition=ct.xyz;}";class Il{events;constructor(){this.events=new Map}on(t,e){this.events.has(t)||this.events.set(t,[]),this.events.get(t).push(e)}clear(t){t?this.events.set(t,[]):this.events.clear()}off(t,e){const n=this.events.get(t);if(!n)return;const i=n.indexOf(e);-1!==i&&n.splice(i,1),0===n.length&&this.events.delete(t)}emit(t,e){const n=this.events.get(t);n&&n.forEach((t=>t(e)))}}class Tl{Je;tn;en;nn;rn;Ve;sn=!1;me=!1;an;un;hn=!1;classificationType=r.ClassificationType.BOTH;constructor(t,e,n){this.Ve=t,this.an=e,this.un=n}prePassesUpdate(t){this.un.ln}update(t){this.me||this.sn&&this.un.sn&&(t.commandList.push(this.rn),this.un.ln?(t.commandList.push(this.tn),t.commandList.push(this.nn)):t.commandList.push(this.Je),t.commandList.push(this.en))}postPassesUpdate(t){}isDestroyed(){return this.me}setBoundingVolume(t){this.Je.boundingVolume=t,this.tn.boundingVolume=t,this.en.boundingVolume=t,this.nn.boundingVolume=t}show(t){0==this.sn&&(this.sn=!0),this.Je.sort=t,this.tn.sort=t}hide(){this.sn&&(this.sn=!1)}destroy(){this.Ve?.Xt&&this.Ve?.Xt.forEach((t=>{t._destroy()})),this.Je.vertexArray.getAttribute(1).vertexBuffer.destroy(),this.Je.vertexArray.cn=[],this.Je.vertexArray.destroy(),this.un=void 0,this.Ve=void 0,this.me=!0}}class zl extends Il{fe;_scene;fn;dn;pn;vn;mn=[];yn;Bt;wn;gn;bn;Xt=[];ln;_n;xn=new r.Cartesian2(1,1);sn=!0;en;rn;kn;$n;Sn=!1;_modelMatrix;Mn;En;nn;constructor(t){super(),this.fe=t.scene.context,this.Bt=t.Bt,t.xn&&(this.xn=new r.Cartesian2(t.xn.brightness||1,t.xn.saturate||1)),this.kn=t.kn,this.$n=t.$n,this.Mn=t.Mn,this._scene=t.scene,this.ln=t.ln,this._n=t._n,r.FeatureDetection.supportsWebgl2&&r.FeatureDetection.supportsWebgl2(this._scene),this.gn=new r.PrimitiveCollection,this.gn.destroyPrimitives=!1,this._scene.groundPrimitives.add(this.gn),this.fn=r.ShaderProgram.fromCache({context:this.fe,vertexShaderSource:Ol,fragmentShaderSource:"#version 300 es\nprecision highp int;precision highp float;in vec4 color;in vec3 texCoord;layout(location=0)out vec4 out_FragColor;void main(){float A=dot(texCoord.xy,texCoord.xy);if(A>1.0f){discard;}float B=exp(-A*4.0)*color.a;if(B<0.0001*texCoord.z)discard;out_FragColor=vec4(color.xyz,B);}",attributeLocations:{position:0,pIdx:1}}),this.dn=r.ShaderProgram.fromCache({context:this.fe,vertexShaderSource:Ol,fragmentShaderSource:"#version 300 es\nprecision highp int;precision highp float;in vec4 color;in vec3 texCoord;in vec4 allMap;in vec3 vPosition;in float maxScale;layout(location=0)out vec4 out_FragColor;layout(location=1)out vec4 fragNormal;layout(location=2)out vec4 fragDistance;layout(location=3)out vec4 position;void main(){float A=dot(texCoord.xy,texCoord.xy);if(A>1.0){discard;}float B=exp(-A*4.0)*color.a;out_FragColor=vec4(color.xyz,B);fragNormal=vec4(allMap.xyz,B);fragDistance=vec4(allMap.w,0,0,B);position=vec4(vPosition,1);}",attributeLocations:{position:0,pIdx:1}}),this.pn=r.RenderState.fromCache({depthTest:{enabled:!1,func:r.DepthFunction.ALWAYS},depthMask:!1,blending:{enabled:!0,equationRgb:r.BlendEquation.ADD,equationAlpha:r.BlendEquation.ADD,functionSourceRgb:r.BlendFunction.SOURCE_ALPHA,functionDestinationRgb:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA,functionSourceAlpha:r.BlendFunction.ONE,functionDestinationAlpha:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA}}),this.vn={index:0,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,-1,0,1,1,0,-1,1,0]),context:this.fe}),componentsPerAttribute:3,componentDatatype:r.ComponentDatatype.FLOAT},this.yn=this.Cn(this._scene.context),this.An(),this.On(),this.In()}_destroy(){this._scene.primitives.remove(this.gn),this.gn=void 0,this.mn.forEach((t=>{t.destroy()})),this.mn=[]}Tn(t){if(!t)return void(this._modelMatrix=null);const e=r.Cartesian3.fromDegrees(t[0],t[1],t[2]),n=r.Transforms.eastNorthUpToFixedFrame(e);this._modelMatrix=n}zn(t){this.En=t,this.mn.forEach((e=>{e.setBoundingVolume(t)}))}Rn(t){this.$n=t}Fn(t){this.kn=t}Cn(t){const e=new Uint8Array([255,255,255,255]);return new r.Texture({context:t,source:{width:1,height:1,arrayBufferView:e},pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.UNSIGNED_BYTE})}On(){this.rn=new r.ClearCommand({framebuffer:this.bn,color:new r.Color(0,0,0,0),depth:1,stencil:0,pass:r.Pass.GLOBE}),this.rn.Pn="clearCommand";const t=new r.VertexArray({name:"gaussian",context:this.fe,attributes:[{index:0,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:new Float32Array([-1,-1,-1,1,1,1,-1,-1,1,1,1,-1]),context:this.fe}),componentsPerAttribute:2,componentDatatype:r.ComponentDatatype.FLOAT}]}),e="#version 300 es\n precision mediump float;\n precision mediump int;\n in vec2 position;\n out vec2 vTextCoord;\n out vec2 vFocal;\n uniform vec2 fov;\n uniform vec2 viewport;\n\n void main() {\n float xFov = fov.x;\n float yFov = fov.y;\n vFocal = vec2( \n viewport.x / (2.0 * tan(xFov / 2.0)),\n viewport.y / (2.0 * tan(yFov / 2.0))\n );\n vTextCoord = (position + 1.0) / 2.0;\n gl_Position = vec4(position, 0, 1);\n }\n ",n=r.ShaderProgram.fromCache({context:this._scene.context,vertexShaderSource1:e,vertexShaderSource:new r.ShaderSource({sources:[e]}),fragmentShaderSource:new r.ShaderSource({defines:["LOG_DEPTH_READ_ONLY"],sources:["#version 300 es\n precision mediump float;\n precision mediump int;\n in vec2 vTextCoord;\n in vec2 vFocal;\n uniform sampler2D colorTexture;\n uniform sampler2D normalTexture;\n uniform sampler2D distanceTexture;\n uniform sampler2D positionTexture;\n\n uniform mat4 projectMatrix;\n uniform mat4 u_view;\n uniform vec3 u_cameraPos;\n uniform mat4 u_model;\n uniform vec4 u_color;\n\n // 光照相关\n const float PI = 3.14159265359;\n uniform vec3 u_ambientColor; // 环境光\n uniform vec3 u_lightColor; // 方向光\n uniform vec3 u_lightDirection;\n uniform float u_lightIntensity;\n uniform float u_roughness;\n uniform float u_metallic;\n\n // uniform vec3 u_specularColor; // 高光\n // uniform float u_shininess;\n uniform vec2 fov;\n\n // 法线分布函数(GGX)\n float D_GGX(float NdotH, float roughness) {\n float a = roughness * roughness;\n float a2 = a * a;\n float denom = (NdotH * NdotH * (a2 - 1.0) + 1.0);\n return a2 / (PI * denom * denom);\n }\n\n // 几何遮蔽函数(Schlick-GGX)\n float G_SchlickGGX(float NdotV, float roughness) {\n float r = roughness + 1.0;\n float k = (r * r) / 8.0;\n return NdotV / (NdotV * (1.0 - k) + k);\n }\n\n // 菲涅尔方程(Schlick近似)\n vec3 F_Schlick(float HdotV, vec3 F0) {\n return F0 + (1.0 - F0) * pow(1.0 - HdotV, 5.0);\n }\n\n \n void main() {\n ivec2 size = textureSize(colorTexture, 0);\n ivec2 texelCoord = ivec2(vTextCoord * vec2(size));\n out_FragColor = texture(colorTexture, vTextCoord);\n vec3 normal = texelFetch(normalTexture, texelCoord, 0).xyz;\n float localDistance = texelFetch(distanceTexture, texelCoord, 0).r;\n vec3 position = texelFetch(positionTexture, texelCoord, 0).rgb;\n\n if(u_color.a > 0.0) {\n out_FragColor = u_color;\n }\n\n vec3 realNormal = inverse(mat3(u_model)) * inverse(mat3(u_view)) * normal;\n // if(out_FragColor.a > 0.01) {\n vec2 viewport = vec2(size);\n vec2 pixf = vec2(vTextCoord.x, 1.0 - vTextCoord.y) * viewport;\n vec2 ray = (pixf.xy - viewport / 2.0) / vFocal;\n\n normal.x *= -1.0;\n // float depth = localDistance / abs(dot(normal.xyz, vec3(ray, 1)) + 1.0e-8);\n // vec4 ndcDepth = projectMatrix * vec4(0, 0, -depth, 1);\n \n // float vDepth = (ndcDepth.w - czm_currentFrustum.x) + 1.0;\n // if (vDepth <= 0.9999999 || vDepth > czm_farDepthFromNearPlusOne) {\n // discard;\n // }\n // gl_FragDepth = log2(vDepth) * czm_oneOverLog2FarDepthFromNearPlusOne;\n\n\n\n\n\n // 计算光照影响\n // 计算漫反射项\n // 直接使用顶点法线(已转换到世界空间)\n vec3 N = normalize(realNormal);\n // 基础反射率(非金属默认0.04,金属使用Albedo,此处简化为灰色)\n vec3 albedo = vec3(0.7);\n vec3 F0 = mix(vec3(0.04), albedo, u_metallic);\n // 向量计算\n vec3 V = normalize(position - u_cameraPos); // 视线方向\n vec3 L = normalize(u_lightDirection); // normalize(uLightPos - position); // 光源方向\n vec3 H = normalize(V + L); // 半角向量\n \n // 点积项\n float NdotV = max(dot(N, V), 0.001);\n float NdotL = max(dot(N, L), 0.001);\n float NdotH = max(dot(N, H), 0.00);\n float HdotV = max(dot(H, V), 0.00);\n \n // BRDF计算\n float D = D_GGX(NdotH, u_roughness); // 法线分布\n float G = G_SchlickGGX(NdotV, u_roughness) * G_SchlickGGX(NdotL, u_roughness); // 几何遮蔽\n vec3 F = F_Schlick(HdotV, F0);\n\n // 镜面反射项\n vec3 numerator = D * G * F;\n float denominator = 4.0 * NdotV * NdotL;\n vec3 specular = numerator / max(denominator, 0.001);\n \n // 漫反射项(非金属才有)\n vec3 kD = (1.0 - F) * (1.0 - u_metallic);\n // vec3 kD = mix(1.0 - F, vec3(1.0), u_metallic) * (1.0 - u_metallic);\n\n vec3 diffuse = kD * albedo / PI;\n diffuse = max(diffuse, vec3(0.0)); // 防止负值\n \n // 光照贡献\n vec3 radiance = u_lightColor * NdotL * u_lightIntensity;\n vec3 lightC = (diffuse + specular) * radiance;\n\n\n // // 计算漫反射项\n // vec3 viewDirection = normalize(u_cameraPos - position);\n // vec3 diffuseTerm = u_lightColor * max(dot(realNormal, normalize(-u_lightDirection)), 0.0) * u_lightIntensity;\n\n // // 计算高光项\n // // vec3 halfwayVector = normalize(-u_lightDirection + viewDirection);\n // // float specularFactor = pow(max(dot(realNormal, halfwayVector), 0.0), u_shininess);\n // // vec3 specularTerm = u_specularColor * specularFactor;\n\n // // 计算总光照\n // vec3 totalLighting = u_ambientColor + diffuseTerm;\n\n // 计算最终颜色\n out_FragColor.rgb *= (lightC + u_ambientColor); //totalLighting;\n // out_FragColor.rgb = realNormal;\n }\n "]}),attributeLocations:{position:0}});n.Dn=!0,this.en=new r.DrawCommand({vertexArray:t,shaderProgram:n,renderState:r.RenderState.fromCache({depthMask:!1,depthTest:{enabled:!1},blending:{enabled:!0,equationRgb:r.BlendEquation.ADD,equationAlpha:r.BlendEquation.ADD,functionSourceRgb:r.BlendFunction.SOURCE_ALPHA,functionDestinationRgb:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA,functionSourceAlpha:r.BlendFunction.ONE,functionDestinationAlpha:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA}}),uniformMap:{colorTexture:()=>this.Xt[0],normalTexture:()=>this.Xt[1],distanceTexture:()=>this.Xt[2],positionTexture:()=>this.Xt[3],projectMatrix:()=>this._scene.camera.frustum.projectionMatrix,u_cameraPos:()=>new r.Cartesian3(this._scene.camera.positionWC.x-this.mn[0].Ve._modelMatrix[12],this._scene.camera.positionWC.y-this.mn[0].Ve._modelMatrix[13],this._scene.camera.positionWC.z-this.mn[0].Ve._modelMatrix[14]),u_model:()=>this.mn[0].Ve._modelMatrix,u_color:()=>this.Mn,u_view:()=>{const t=new r.Matrix4;r.Matrix4.multiply(this._scene.camera.viewMatrix,this.mn[0].Ve._modelMatrix,t);const e=new r.Matrix4;return this._scene.camera.viewMatrix.clone(e),e[12]=t[12],e[13]=t[13],e[14]=t[14],e},fov:()=>new r.Cartesian2(this._scene.camera.frustum.fov,this._scene.camera.frustum.fovy),viewport:()=>new r.Cartesian2(this._scene.context.drawingBufferWidth,this._scene.context.drawingBufferHeight),u_ambientColor:()=>this.$n&&this.$n.enable?this.$n.ambientColor:new r.Cartesian3(1,1,1),u_lightColor:()=>this.$n&&this.$n.enable?this.$n.lightColor:new r.Cartesian3(1,1,1),u_lightDirection:()=>this.$n&&this.$n.enable?this.$n.lightDirection:new r.Cartesian3(0,0,1),u_lightIntensity:()=>this.$n&&this.$n.enable?this.$n.lightIntensity:0,u_metallic:()=>this.$n&&this.kn&&this.$n.enable?this.kn.metallic:0,u_roughness:()=>this.$n&&this.kn&&this.$n.enable?this.kn.roughness:1},pass:this._n||r.Pass.GLOBE}),this.en.Pn="color_gaussian_fullScreen";const i=r.ShaderProgram.fromCache({context:this._scene.context,vertexShaderSource:new r.ShaderSource({sources:[e]}),fragmentShaderSource:new r.ShaderSource({defines:["LOG_DEPTH_READ_ONLY"],sources:["#version 300 es\n precision mediump float;\n precision mediump int;\n in vec2 vTextCoord;\n in vec2 vFocal;\n uniform sampler2D normalTexture;\n uniform sampler2D distanceTexture;\n\n uniform mat4 projectMatrix;\n uniform mat4 u_view;\n uniform mat4 u_model;\n \n void main() {\n ivec2 size = textureSize(normalTexture, 0);\n ivec2 texelCoord = ivec2(vTextCoord * vec2(size));\n vec3 normal = texelFetch(normalTexture, texelCoord, 0).xyz;\n float localDistance = texelFetch(distanceTexture, texelCoord, 0).r;\n\n vec3 realNormal = inverse(mat3(u_model)) * inverse(mat3(u_view)) * normal;\n vec2 viewport = vec2(size);\n vec2 pixf = vec2(vTextCoord.x, 1.0 - vTextCoord.y) * viewport;\n vec2 ray = (pixf.xy - viewport / 2.0) / vFocal;\n\n normal.x *= -1.0;\n float depth = localDistance / abs(dot(normal.xyz, vec3(ray, 1)) + 1.0e-8);\n vec4 ndcDepth = projectMatrix * vec4(0, 0, -depth, 1);\n \n float vDepth = (ndcDepth.w - czm_currentFrustum.x) + 1.0;\n if (vDepth <= 0.9999999 || vDepth > czm_farDepthFromNearPlusOne) {\n discard;\n }\n gl_FragDepth = log2(vDepth) * czm_oneOverLog2FarDepthFromNearPlusOne;\n out_FragColor = vec4(vec3(vDepth), 0);\n }"]}),attributeLocations:{position:0}});this.nn=new r.DrawCommand({vertexArray:t,shaderProgram:i,renderState:r.RenderState.fromCache({depthMask:!0,depthTest:{enabled:!0},colorMask:{red:!1,green:!1,blue:!1,alpha:!1}}),uniformMap:{normalTexture:()=>this.Xt[1],distanceTexture:()=>this.Xt[2],projectMatrix:()=>this._scene.camera.frustum.projectionMatrix,u_model:()=>this.mn[0].Ve._modelMatrix,u_view:()=>{const t=new r.Matrix4;r.Matrix4.multiply(this._scene.camera.viewMatrix,this.mn[0].Ve._modelMatrix,t);const e=new r.Matrix4;return this._scene.camera.viewMatrix.clone(e),e[12]=t[12],e[13]=t[13],e[14]=t[14],e},fov:()=>new r.Cartesian2(this._scene.camera.frustum.fov,this._scene.camera.frustum.fovy),viewport:()=>new r.Cartesian2(this._scene.context.drawingBufferWidth,this._scene.context.drawingBufferHeight)},pass:r.Pass.GLOBE}),this.nn.Pn="depth_gaussian_fullScreen"}An(){const{drawingBufferWidth:t,drawingBufferHeight:e}=this._scene.context,n=Math.floor(t/1),i=Math.floor(e/1),s=new r.Texture({context:this._scene.context,width:n,height:i,pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.HALF_FLOAT}),o=new r.Texture({context:this._scene.context,width:n,height:i,pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.HALF_FLOAT}),a=new r.Texture({context:this._scene.context,width:n,height:i,pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.HALF_FLOAT}),u=new r.Texture({context:this._scene.context,width:n,height:i,pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.HALF_FLOAT});this.Xt=[s,o,a,u],this.bn&&this.bn.destroy(),this.bn=new r.Framebuffer({context:this._scene.context,colorTextures:this.ln?this.Xt:[this.Xt[0]]}),this.bn.Nn=[t,e]}In(){const{drawingBufferWidth:t,drawingBufferHeight:e}=this._scene.context;this.mn.length>0&&(this.bn.Nn[0]===t/1&&this.bn.Nn[1]===e/1||(this.An(),this.mn[0].Je.framebuffer=this.bn,this.mn[0].tn.framebuffer=this.bn,this.mn[0].rn.framebuffer=this.bn))}Un(){(this.ln&&1===this.bn._colorTextures.length||!this.ln&&4===this.bn._colorTextures.length)&&(this.An(),this.mn[0].Je.framebuffer=this.bn,this.mn[0].tn.framebuffer=this.bn,this.mn[0].rn.framebuffer=this.bn),this.In()}qn(){this.sn=!1,this.gn.show=!1}_show(){this.sn=!0,this.gn.show=!0}jn(){}Bn(t,e){if(e){const n=e.getAttribute(1).vertexBuffer;n.sizeInBytes<t.byteLength?(n.destroy(),e=new r.VertexArray({name:"gaussian",context:this.fe,attributes:[this.vn,{name:"pIdx",index:1,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:t,context:this.fe}),componentsPerAttribute:1,componentDatatype:r.ComponentDatatype.FLOAT,instanceDivisor:1}]})):n?.copyFromArrayView(t)}else e=new r.VertexArray({name:"gaussian",context:this.fe,attributes:[this.vn,{name:"pIdx",index:1,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:t,context:this.fe}),componentsPerAttribute:1,componentDatatype:r.ComponentDatatype.FLOAT,instanceDivisor:1}]});return e}Ln(t){if(!window.stopUpdate&&this.gn)if(t&&t.oe){this.gn.Ve=t,this.Sn||this.emit("renderfirstframe",null),this.Sn=!0;for(let e=0;e<1;e+=1){let n=t;if(this.mn[e]){const t=this.Bn(n.Jt,this.mn[e].Je.vertexArray);this.mn[e].Je.vertexArray=t,this.mn[e].Je.instanceCount=n.oe,this.mn[e].tn.vertexArray=t,this.mn[e].tn.instanceCount=n.oe,this.mn[e].Ve=n}else{this.mn[e]=new Tl(n,e,this);const i={viewport:()=>new r.Cartesian2(this._scene.canvas.width,this._scene.canvas.height),u_filter:()=>this.xn,u_cameraPos:()=>new r.Cartesian3(this._scene.camera.positionWC.x-this.mn[e].Ve._modelMatrix[12],this._scene.camera.positionWC.y-this.mn[e].Ve._modelMatrix[13],this._scene.camera.positionWC.z-this.mn[e].Ve._modelMatrix[14]),u_normalMatrix:()=>{let t=this.mn[e].Ve._modelMatrix,n=r.Matrix4.getMatrix3(t,new r.Matrix3);return r.Matrix3.inverseTranspose(n,n),n},u_modelMatrix:()=>{let t=this.mn[e].Ve._modelMatrix;return r.Matrix4.getMatrix3(t,new r.Matrix3)},u_view:()=>{const t=new r.Matrix4;r.Matrix4.multiply(this._scene.camera.viewMatrix,this.mn[e].Ve._modelMatrix,t);const n=new r.Matrix4;return this._scene.camera.viewMatrix.clone(n),n[12]=t[12],n[13]=t[13],n[14]=t[14],n},u_mvs:()=>{const t=new r.Matrix4;return r.Matrix4.multiply(this._scene.camera.viewMatrix,this._modelMatrix||this.mn[e].Ve._modelMatrix,t),t},u_txts:()=>{const t=this.mn[e].Ve.Xt,n=new Array(16);return n.fill(this.yn),t.forEach(((t,e)=>{n[e]=t&&t._texture?t._texture:this.yn})),n},u_params:()=>new r.Cartesian4(t.jt?1:0,Math.log2(this.Bt/2),Math.ceil(Math.log2(this.Bt*this.Bt)),this.Bt),u_sltid:()=>this.mn[e].Ve.je||0,u_sltc:()=>this.mn[e].Ve?.Be||r.Color.fromBytes(0,200,255,80)},s=this.Bn(n.Jt);this.mn[e].tn=new r.DrawCommand({vertexArray:s,shaderProgram:this.dn,uniformMap:i,renderState:this.pn,pass:this._n||r.Pass.GLOBE,instanceCount:n.oe,count:6,framebuffer:this.bn,boundingVolume:this.En}),this.mn[e].Je=new r.DrawCommand({vertexArray:s,shaderProgram:this.fn,uniformMap:i,renderState:this.pn,pass:this._n||r.Pass.GLOBE,instanceCount:n.oe,count:6,framebuffer:this.bn,boundingVolume:this.En}),this.mn[e].en=this.en,this.mn[e].rn=this.rn,this.mn[e].nn=this.nn,this.mn[e].Je.Pn="_drawCmd",this.mn[e].tn.Pn="_depthDrawCmd",this.gn.add(this.mn[e])}this.mn[e].show()}for(let t=1;t<this.mn.length;t+=1)this.mn[t].hide();this._scene.requestRender()}else this.gn&&(this.gn.show=!1)}}class Rl{Hn;Oe;Ve;He;Fe;un;Wn;constructor(t){this.Hn=t.viewer,this.Oe=t.url,this.Ve=t.data,this.He=t.deltaCenter,this.Fe=t.enuCenter;const e=this.Hn.scene;this.Wn=new Al({fe:e.context,Ve:this.Ve,He:this.He,Fe:this.Fe||[0,0,0]}),this.un=new zl({ln:!0,scene:e,Bt:this.Wn.textureWidth}),this.Wn.afterSort=t=>{this.un.Ln(t),this.Hn.scene.requestRender()},e.preRender.addEventListener(((t,e)=>{this.Wn.Xe(t)}),this),this.Hn.scene.requestRender()}selectedEntity(t,e){this.Wn.Ke(+t,e)}hide(){this.un.qn()}show(){this.un._show()}setData(t,e){this.Wn.updateData(t,e)}destroy(){this.Wn._destroy(),this.un._destroy()}}const Fl=1e-6,Pl=[0,0,0],Dl=[0,0,0],Nl=[0,0,0],Ul=[0,0,0],ql=[0,0,0],jl=[0,0,0],Bl=[0,0,0],Ll=[0,0,0],Hl=[0,0,0],Wl=[0,0,0],Vl=[0,0,0],Gl=[0,0],Yl=[0,0,0],Kl=[0,0,0],Xl=[0,0,0],Ql=[0,0,0],Zl=[0,0,0],Jl=[0,0,0];function tc(t,e,n,i,r,s){if(Sc(e)<Fl)return;kc(Yl,n,e),kc(Kl,i,e),kc(Xl,r,e),nc(t,e,Gl),Zl[1]=Gl[0],Ql[1]=Gl[1],Jl[1]=Ql[1]-Zl[1];const o=[n,i,r],a=[Yl,Kl,Xl];for(let n=0;n<3;++n){nc(t,o[n],Gl),Zl[0]=Gl[0],Ql[0]=Gl[1],nc(t,a[n],Gl),Zl[2]=Gl[0],Ql[2]=Gl[1],Jl[0]=Ql[0]-Zl[0],Jl[2]=Ql[2]-Zl[2];const i=wc(Jl);i<s.quality&&(xc(s.b0,o[n]),xc(s.b1,e),xc(s.b2,a[n]),s.quality=i)}}const ec=[0,0,0];function nc(t,e,n){const{data:i,offsetIdx:r,strideIdx:s}=t;n[0]=Number.POSITIVE_INFINITY,n[1]=Number.NEGATIVE_INFINITY;for(let t=r;t<i.length;t+=s){const r=i[t]*e[0]+i[t+1]*e[1]+i[t+2]*e[2];n[0]=Math.min(n[0],r),n[1]=Math.max(n[1],r)}}function ic(t,e,n){xc(n.center,t),_c(n.halfSize,e,.5),n.quaternion[0]=0,n.quaternion[1]=0,n.quaternion[2]=0,n.quaternion[3]=1}const rc=[0,0,0],sc=[0,0,0],oc=[0,0,0],ac=[0,0,0],uc=[0,0,0],hc=[0,0,0];function lc(t,e,n){xc(rc,e),Math.abs(e[0])>Math.abs(e[1])&&Math.abs(e[0])>Math.abs(e[2])?rc[0]=0:Math.abs(e[1])>Math.abs(e[2])?rc[1]=0:rc[2]=0,Sc(rc)<Fl&&(rc[0]=rc[1]=rc[2]=1),kc(sc,e,rc),$c(sc,sc),kc(oc,e,sc),$c(oc,oc),cc(t,e,sc,oc,ac,uc),bc(hc,uc,ac),vc(e,sc,oc,ac,uc,hc,n)}function cc(t,e,n,i,r,s){nc(t,e,Gl),r[0]=Gl[0],s[0]=Gl[1],nc(t,n,Gl),r[1]=Gl[0],s[1]=Gl[1],nc(t,i,Gl),r[2]=Gl[0],s[2]=Gl[1]}const fc=[0,0,0],dc=[1,0,0,0,1,0,0,0,1],pc=[0,0,0];function vc(t,e,n,i,r,s,o){dc[0]=t[0],dc[1]=t[1],dc[2]=t[2],dc[3]=e[0],dc[4]=e[1],dc[5]=e[2],dc[6]=n[0],dc[7]=n[1],dc[8]=n[2],function(t,e){const n=e[0]+e[4]+e[8];if(n>0){let i=Math.sqrt(n+1);t[3]=.5*i,i=.5/i,t[0]=(e[5]-e[7])*i,t[1]=(e[6]-e[2])*i,t[2]=(e[1]-e[3])*i}else{let n=0;e[4]>e[0]&&(n=1),e[8]>e[3*n+n]&&(n=2);const i=(n+1)%3,r=(n+2)%3;let s=Math.sqrt(e[3*n+n]-e[3*i+i]-e[3*r+r]+1);t[n]=.5*s,s=.5/s,t[3]=(e[3*i+r]-e[3*r+i])*s,t[i]=(e[3*i+n]+e[3*n+i])*s,t[r]=(e[3*r+n]+e[3*n+r])*s}}(o.quaternion,dc),gc(pc,i,r),_c(pc,pc,.5),_c(o.center,t,pc[0]),_c(fc,e,pc[1]),gc(o.center,o.center,fc),_c(fc,n,pc[2]),gc(o.center,o.center,fc),_c(o.halfSize,s,.5)}class mc{buffer;minProj;maxProj;minVert=new Array(7);maxVert=new Array(7);constructor(t){this.buffer=new ArrayBuffer(448);let e=0;this.minProj=new Float64Array(this.buffer,e,7),e+=56,this.maxProj=new Float64Array(this.buffer,e,7),e+=56;for(let t=0;t<7;++t)this.minVert[t]=new Float64Array(this.buffer,e,3),e+=24;for(let t=0;t<7;++t)this.maxVert[t]=new Float64Array(this.buffer,e,3),e+=24;for(let t=0;t<7;++t)this.minProj[t]=Number.POSITIVE_INFINITY,this.maxProj[t]=Number.NEGATIVE_INFINITY;const n=new Array(7),i=new Array(7),{data:r,offsetIdx:s,strideIdx:o}=t;for(let t=s;t<r.length;t+=o){let e=r[t];e<this.minProj[0]&&(this.minProj[0]=e,n[0]=t),e>this.maxProj[0]&&(this.maxProj[0]=e,i[0]=t),e=r[t+1],e<this.minProj[1]&&(this.minProj[1]=e,n[1]=t),e>this.maxProj[1]&&(this.maxProj[1]=e,i[1]=t),e=r[t+2],e<this.minProj[2]&&(this.minProj[2]=e,n[2]=t),e>this.maxProj[2]&&(this.maxProj[2]=e,i[2]=t),e=r[t]+r[t+1]+r[t+2],e<this.minProj[3]&&(this.minProj[3]=e,n[3]=t),e>this.maxProj[3]&&(this.maxProj[3]=e,i[3]=t),e=r[t]+r[t+1]-r[t+2],e<this.minProj[4]&&(this.minProj[4]=e,n[4]=t),e>this.maxProj[4]&&(this.maxProj[4]=e,i[4]=t),e=r[t]-r[t+1]+r[t+2],e<this.minProj[5]&&(this.minProj[5]=e,n[5]=t),e>this.maxProj[5]&&(this.maxProj[5]=e,i[5]=t),e=r[t]-r[t+1]-r[t+2],e<this.minProj[6]&&(this.minProj[6]=e,n[6]=t),e>this.maxProj[6]&&(this.maxProj[6]=e,i[6]=t)}for(let t=0;t<7;++t){let e=n[t];xc(this.minVert[t],r,e),e=i[t],xc(this.maxVert[t],r,e)}}}class yc{b0=[1,0,0];b1=[0,1,0];b2=[0,0,1];quality=0}function wc(t){return t[0]*t[1]+t[0]*t[2]+t[1]*t[2]}function gc(t,e,n){t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2]}function bc(t,e,n){t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2]}function _c(t,e,n){t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n}function xc(t,e,n=0){t[0]=e[n+0],t[1]=e[n+1],t[2]=e[n+2]}function kc(t,e,n){const i=e[0],r=e[1],s=e[2],o=n[0],a=n[1],u=n[2];t[0]=r*u-s*a,t[1]=s*o-i*u,t[2]=i*a-r*o}function $c(t,e){const n=e[0]*e[0]+e[1]*e[1]+e[2]*e[2];if(n>0){const i=1/Math.sqrt(n);t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i}}function Sc(t){return t[0]*t[0]+t[1]*t[1]+t[2]*t[2]}function Mc(t,e){const n=e[0]-t[0],i=e[1]-t[1],r=e[2]-t[2];return n*n+i*i+r*r}function Ec(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}const Cc=(t,e)=>{const n=10**e;return Math.round(t*n)/n},Ac=(t,e,n=!1)=>{const i=t[0],r=t[1];let s,o,a,u,h=!1;const l=e.length;for(let t=0,c=l-1;t<l;c=t,t+=1){let l=!1;if(s=e[t][0],o=e[t][1],a=e[c][0],u=e[c][1],s===i&&o===r||a===i&&u===r)return!!n;if(o<r==u>=r){const t=(a-s)*(r-o)/(u-o)+s;if(i===t)return!!n;l=i<t}l&&(h=!h)}return h},Oc=(t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[2]>=e[2]&&t[0]<=e[3]&&t[1]<=e[4]&&t[2]<=e[5],Ic=(t,e)=>{var n=e[0],i=e[1],s=e[2],o=t[0],a=t[1],u=t[2];const h=r.Cartesian3.fromDegrees(o,a,u),l=r.Cartesian3.fromDegrees(n,i,s),c=r.Transforms.eastNorthUpToFixedFrame(l);var f=r.Matrix4.inverse(c,new r.Matrix4);return r.Matrix4.multiplyByPoint(f,h,new r.Cartesian3)},Tc=new r.Matrix4,zc=new r.Matrix4,Rc=new r.Cartesian3;function Fc(t,e,n){const[i,s,o]=e;return r.Cartesian3.fromDegrees(i,s,o,void 0,Rc),r.Transforms.eastNorthUpToFixedFrame(Rc,void 0,zc),r.Matrix4.inverseTransformation(zc,Tc),r.Matrix4.multiplyByPoint(Tc,t,n||new r.Cartesian3)}function Pc(t,e,n,i){const s=Dc(t,e,n,i),o=r.Cartographic.fromCartesian(s);return[o.longitude,o.latitude,o.height]}function Dc(t,e,n,i){if(!n){const[t,i,o]=e;var s=r.Cartesian3.fromDegrees(t,i,o);n=r.Transforms.eastNorthUpToFixedFrame(s)}return r.Matrix4.multiplyByPoint(n,t,i||new r.Cartesian3)}function Nc(t){var e=r.Cartographic.fromCartesian(t);return{lng:r.Math.toDegrees(e.longitude),lat:r.Math.toDegrees(e.latitude),height:e.height}}function Uc(t,e){const n=2*Math.PI;let i=(e=(e%n+n)%n)-(t=(t%n+n)%n);return i>Math.PI?i-=n:i<-Math.PI&&(i+=n),i}var qc,jc=new Float32Array(1);function Bc(t){const e=[];for(let n=0,i=t.length;n<i;n+=2)e.push(parseInt(t.substr(n,2),16)/255);return e.push(e.shift()),e}function Lc(t,e){let n,i,r,s,o,a,u,h="ASDFGHJKLQWERTYUIO!sdfghjkleiu3~yr5-P&mq9`%zCN*b=8@^xpVM";for((e=e||"v5")>"v5"?(n=h.length,i=512):(n=27,h=h.substr(0,27),i=333),s=[],o=NaN,a=0,u=t.length;a<u;a++)r=t[a],r=h.indexOf(r),isNaN(o)?o=r*n:(s.push(o+r-i),o=NaN);return s}function Hc(t){if(t.toArray)return t.toArray();{const e=[];let n=t.next();for(;!n.done;)e.push(n.value),n=t.next();return e}}new Int32Array(jc.buffer);class Wc{Vn;Gn;fe;Yn;Kn;Xn=[];Qn=-1;Zn="close";Jn={};ti=0;ei;ii;oi;ai;ui;li;ci;fi=[0,0];di=[];pi=[1/0,1/0,1/0,-1/0,-1/0,-1/0];options={layer:void 0,inPointStyle:{color:"rgba(37,165,247,1)",radius:6,borderWidth:4,borderColor:"rgba(255,255,255,1)"},outPointStyle:{color:"rgba(247,55,37,1)",radius:6,borderWidth:4,borderColor:"rgba(255,255,255,1)"},polygonStyle:{color:"rgba(0,255,255,0.6)",borderWidth:4,borderColor:"rgba(255,255,255,1)"},model:{encoderUrl:"",decoderUrl:"",name:"model",wasmPaths:""}};constructor(t){t.viewer&&(this.Vn=t.viewer.container,this.options.inPointStyle=Object.assign(this.options.inPointStyle,t.inPointStyle),this.options.outPointStyle=Object.assign(this.options.outPointStyle,t.outPointStyle),this.options.polygonStyle=Object.assign(this.options.polygonStyle,t.polygonStyle),this.options.model=Object.assign(this.options.model,t.model),this.options.viewer=t.viewer,this.options.layer=t.layer,this.options.layer&&(this.mi(),this.yi()))}show(){this.Gn.style.visibility="visible",this.Yn.style.visibility="visible"}hide(){this.Gn.style.visibility="hidden",this.Yn.style.visibility="hidden"}open(){this.Zn="open",this.Gn.style.visibility="visible",this.Yn.style.visibility="visible",this.Gn.style.pointerEvents="all",this.Gn.addEventListener("mousedown",this.wi),this.Gn.addEventListener("mouseup",this.gi),this.Vn.addEventListener("contextmenu",this.wi)}createMask(){"open"!==this.Zn&&"adding"!==this.Zn||(this.Zn="adding",this.Kn.clearRect(0,0,this.Yn.width,this.Yn.height),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.Gn.style.pointerEvents=this.Yn.style.pointerEvents="all",this.Qn++,this.Xn[this.Qn]=[])}async embeddings(){await this._i(),void 0===this.oi&&await this.ei,this.ci=await this.oi}maskCompleted(){this.Kn.clearRect(0,0,this.Yn.width,this.Yn.height),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.Gn.style.pointerEvents=this.Yn.style.pointerEvents="none",this.xi()}highLight(t){if(!this.options.viewer)return;if(!this.ui||0===this.ui.length)return;let e=0;for(let t=0;t<this.ui.length;t++){const{centers:n,rgbas:i,sigmas:r}=this.ui[t];n&&i&&r&&(e+=n.byteLength/3*8)}const n=new ArrayBuffer(e),i=new DataView(n);let r=0;const s=[0,0,0];for(let t=0;t<this.ui.length;t++){const{centers:e,rgbas:n,sigmas:o,modelMatrix:a,count:u,indices:h}=this.ui[t];if(0===t&&(s[0]=a[12],s[1]=a[13],s[2]=a[14]),e&&n&&o){const t=new Float32Array(e),s=new Uint8Array(n),a=new Uint32Array(o);for(let e=0;e<t.length/3;e++){const n=r+e,o=t[3*e],u=t[3*e+1],h=t[3*e+2];this.pi[0]=Math.min(o,this.pi[0]),this.pi[1]=Math.min(u,this.pi[1]),this.pi[2]=Math.min(h,this.pi[2]),this.pi[3]=Math.max(o,this.pi[3]),this.pi[4]=Math.max(u,this.pi[4]),this.pi[5]=Math.max(h,this.pi[5]);const l=s[4*e],c=s[4*e+1],f=s[4*e+2],d=s[4*e+3],p=32*n;i.setFloat32(p,o,!0),i.setFloat32(p+4,u,!0),i.setFloat32(p+8,h,!0),i.setUint8(p+12,1),i.setUint8(p+15,1),i.setUint32(p+16,a[3*e],!0),i.setUint32(p+20,a[3*e+1],!0),i.setUint32(p+24,a[3*e+2],!0),i.setUint8(p+28,l),i.setUint8(p+29,c),i.setUint8(p+30,f),i.setUint8(p+31,d)}r+=u||0}}this.li=new Rl({viewer:this.options.viewer,deltaCenter:s,enuCenter:this.options.layer?.getEnuCenter(),data:n}),this.li.selectedEntity(-1,t)}cancelMask(){this.Zn="open",this.ti=0,this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.Xn[this.Qn]=[],this.Qn--}close(){this.Zn="close",this.ti=0,this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.Kn.clearRect(0,0,this.Yn.width,this.Yn.height),this.Xn=[],this.pi=[1/0,1/0,1/0,-1/0,-1/0,-1/0],this.Qn=-1,this.Gn.style.visibility=this.Yn.style.visibility="hidden",this.Gn.style.pointerEvents=this.Yn.style.pointerEvents="none",this.Vn.removeEventListener("contextmenu",this.wi),this.Gn.removeEventListener("mousedown",this.wi),this.Gn.removeEventListener("mouseup",this.gi)}removePoint(){"adding"===this.Zn&&this.Xn[this.Qn].length>0&&(this.Xn[this.Qn].pop(),this.ki(),this.$i())}getSingleData(){return this.ui}getSingleModel(){return this.li}lock(){this.Zn="locking",this.Gn.style.pointerEvents="all";var t=this.options.viewer.scene.screenSpaceCameraController;this.Jn={enableTranslate:t.enableTranslate,enableZoom:t.enableZoom,enableRotate:t.enableRotate,enableTilt:t.enableTilt,enableLook:t.enableLook,inertiaSpin:t.inertiaSpin,inertiaTranslate:t.inertiaTranslate,inertiaZoom:t.inertiaZoom},t.enableTranslate=!1,t.enableZoom=!1,t.enableRotate=!1,t.enableTilt=!1,t.enableLook=!1,t.inertiaSpin=0,t.inertiaTranslate=0,t.inertiaZoom=0}unlock(){this.Zn="open",this.Gn.style.pointerEvents="none";var t=this.options.viewer.scene.screenSpaceCameraController;t.enableTranslate=this.Jn.enableTranslate,t.enableZoom=this.Jn.enableZoom,t.enableRotate=this.Jn.enableRotate,t.enableTilt=this.Jn.enableTilt,t.enableLook=this.Jn.enableLook,t.inertiaSpin=this.Jn.inertiaSpin,t.inertiaTranslate=this.Jn.inertiaTranslate,t.inertiaZoom=this.Jn.inertiaZoom}Si(t){const e=this.options.layer?.getEnuCenter();if(!e)return;const n=[];for(let i=0;i<t.length;i++){const{rotation:s,scale:o,center:a}=t[i],u=new r.Cartesian3(2*o[0],2*o[1],2*o[2]),h=Dc(new r.Cartesian3(a[0],a[1],a[2]),e),l=new r.HeadingPitchRoll(s[0],s[1],s[2]),c=r.Transforms.headingPitchRollQuaternion(h,l),f=this.options.viewer?.entities.add({name:"single boxs",position:h,orientation:c,box:{dimensions:u,material:new r.Color(1,0,1,1),outline:!0,outlineWidth:5}});n.push(f)}return n}mi(){const t=document.createElement("canvas"),e=document.createElement("canvas"),n=this.Vn?.getBoundingClientRect();n&&(t.width=e.width=n.width*window.devicePixelRatio,t.height=e.height=n.height*window.devicePixelRatio,t.style.cssText=e.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n ",this.Vn.appendChild(e),this.Vn.appendChild(t),this.Gn=t,this.Yn=e,this.fe=t.getContext("2d")||void 0,this.Kn=e.getContext("2d")||void 0,this.In())}async $i(){const t=[],e=[];this.Xn[this.Qn].forEach((n=>{e.push(n.isIn?1:0),t.push(...n.point)})),0!==e.length&&(await this.Mi(t,e),await this.Ei())}async yi(){const t=this.options.model;yl.env.wasm.wasmPaths=t.wasmPaths||"../../onnx/",yl.env.wasm.numThreads=10;const e=await caches.open("onnx");await e.match(t.encoderUrl),await e.match(t.decoderUrl);const n={executionProviders:["webgpu"],enableMemPattern:!1,enableCpuMemArena:!1,extra:{session:{disable_prepacking:"1",use_device_allocator_for_initializers:"1",use_ort_model_bytes_directly:"1",use_ort_model_bytes_for_initializers:"1"}}},i=await this.Ci(t.encoderUrl),r=await this.Ci(t.decoderUrl);this.ei=await yl.InferenceSession.create(i,n),this.ii=await yl.InferenceSession.create(r,n)}async Ci(t){try{const e=await caches.open("onnx");let n=await e.match(t);if(null==n&&(await e.add(t),n=await e.match(t)),n)return await n.arrayBuffer()}catch(e){return await fetch(t).then((t=>t.arrayBuffer()))}}async Mi(t,e){if(t.length>0){const n=this.ii,i=this.Ai(t,e),r=(await n.run(i)).masks;this.ai=r.toImageData()}}Ai(t,e){const n=new yl.Tensor(new Float32Array(65536),[1,1,256,256]),i=new yl.Tensor(new Float32Array([0]),[1]),r=new yl.Tensor(new Float32Array([1024,1024]),[2]),s=new yl.Tensor(new Float32Array(t),[1,t.length/2,2]),o=new yl.Tensor(new Float32Array(e),[1,e.length]);return{image_embeddings:new yl.Tensor(this.ci.image_embeddings.type,Float32Array.from(this.ci.image_embeddings.data),this.ci.image_embeddings.dims),point_coords:s,point_labels:o,mask_input:n,has_mask_input:i,orig_im_size:r}}async _i(){this.oi=void 0;const t=document.createElement("canvas");t.width=1024,t.height=1024;const e=t.getContext("2d");if(e&&this.options.viewer?.canvas){e.drawImage(this.options.viewer?.canvas,0,0,t.width,t.height);const n=e.getImageData(0,0,1024,1024),i=await yl.Tensor.fromImage(n,{resizedWidth:1024,resizedHeight:1024}),r=await this.ei;this.oi=r.run({input_image:i}),this.oi.then((()=>{}))}}gi=t=>{const e=t;if(this.fi[0]!==e.clientX||this.fi[1]!==e.clientY)return;const n=this.Gn?.getBoundingClientRect();if(n){const t=Math.trunc(e.clientX-n.left)*window.devicePixelRatio,i=Math.trunc(e.clientY-n.top)*window.devicePixelRatio;0===e.button?this.Oi([t,i],!0):2===e.button&&this.Oi([t,i],!1)}};wi=t=>{const e=t;e.preventDefault(),this.fi=[e.clientX,e.clientY]};Oi(t,e){void 0===this.Xn[this.Qn]&&(this.Xn[this.Qn]=[]),this.Xn[this.Qn].length>5||("adding"===this.Zn&&this.Xn[this.Qn].push({isIn:e,point:[Math.trunc(t[0]/this.Gn.width*1024),Math.trunc(t[1]/this.Gn.height*1024)]}),this.ki(),this.$i())}ki(){this.fe?.clearRect(0,0,this.Gn.width,this.Gn.height);for(let t=0;t<this.Xn[this.Qn].length;t++){const e=this.Xn[this.Qn][t],n=e.isIn?this.options.inPointStyle:this.options.outPointStyle;this.fe.strokeStyle=n.borderColor,this.fe.lineWidth=n.borderWidth*window.devicePixelRatio,this.fe.fillStyle=n.color,this.fe.beginPath(),this.fe.arc(e.point[0]/1024*this.Gn.width,e.point[1]/1024*this.Gn.height,n.radius*window.devicePixelRatio,0,2*Math.PI,!1),this.fe.closePath(),this.fe.stroke(),this.fe.fill()}}async Ei(){const t=this.ai,e=t.data,n=this.options.polygonStyle.color.slice(5,-1).split(",");this.Kn.clearRect(0,0,this.Yn.width,this.Yn.height);for(let t=0;t<e.length;t+=4)0!==e[t]?(e[t]=+n[0],e[t+1]=+n[1],e[t+2]=+n[2],e[t+3]=255*+n[3]):e[t+3]=0;this.Kn.drawImage(await createImageBitmap(t),0,0,this.Yn.width,this.Yn.height)}xi(){if(!this.options.layer)return;const t=this.options.viewer.scene.camera.viewMatrix,e=this.options.viewer.scene.camera.frustum.projectionMatrix,n=new r.Matrix4;r.Matrix4.multiply(e,t,n),this.di=[];let i=!1;if(this.ui&&0!==this.ui.length||0!==this.ti||(i=!0,this.ui=this.options.layer.Ii().map((t=>({tileNum:t.Ti,modelMatrix:t._modelMatrix,centers:t.Gt,rgbas:t.zi,sigmas:t.Ri,indices:[]})))),this.ui){const{data:t,width:e,height:s}=this.ai,o=[];for(let a=0;a<this.ui.length;a++){const u=this.ui[a];if(u.centers&&u.centers.byteLength>0&&u.rgbas&&u.sigmas){const a=[],h=[];let l=new Uint32Array(u.centers.byteLength/4);const c=[],f=new Float32Array(u.centers),d=new Uint8Array(u.rgbas),p=new Uint32Array(u.sigmas),v=new r.Matrix4;r.Matrix4.multiply(n,u.modelMatrix,v);const m=f.length,y=u.indices;let w=0;for(let n=0;n<m;n++){const o=f[3*n],u=f[3*n+1],m=f[3*n+2],g=new r.Cartesian3(o,u,m);r.Matrix4.multiplyByPoint(v,new r.Cartesian3(o,u,m),g),g.x=Math.trunc((g.x/g.z+1)/2*e),g.y=s-Math.trunc((g.y/g.z+1)/2*s),g.x>0&&g.x<e&&g.y<s&&g.y>0&&t[4*(e*g.y+g.x)+3]>0&&(i?c.push(n):y&&c.push(y[n]),a.push(o,u,m),this.di.push([o,u,m]),h.push(d[4*n],d[4*n+1],d[4*n+2],d[4*n+3]),l[w]=p[3*n],l[w+1]=p[3*n+1],l[w+2]=p[3*n+2],w+=3)}l=l.slice(0,w),a.length>0&&o.push({centers:new Float32Array(a).buffer,rgbas:new Uint8Array(h).buffer,sigmas:l.buffer,tileNum:u.tileNum,modelMatrix:u.modelMatrix,count:a.length/3,indices:c})}}this.ui=o}}Fi(t){const e={center:new Float64Array([0,0,0]),halfSize:new Float32Array([0,0,0]),quaternion:new Float32Array([0,0,0,1])};return function(t,e){const{data:n,strideIdx:i}=t,r=n.length/i;if(r<=0)return;const s=new mc(t);gc(Pl,s.minProj,s.maxProj),_c(Pl,Pl,.5),bc(Dl,s.maxProj,s.minProj);const o=wc(Dl),a=new yc;a.quality=o,r<14&&(t={data:new Float64Array(s.buffer,112,42),size:3,offsetIdx:0,strideIdx:3});const u=[0,0,0],h=[0,0,0],l=[0,0,0],c=[0,0,0],f=[0,0,0],d=[0,0,0],p=[0,0,0];switch(function(t,e,n,i,r,s,o,a,u,h){if(function(t,e,n){let i=Mc(t.maxVert[0],t.minVert[0]),r=0;for(let e=1;e<7;++e){const n=Mc(t.maxVert[e],t.minVert[e]);n>i&&(i=n,r=e)}xc(e,t.minVert[r]),xc(n,t.maxVert[r])}(t,i,r),Mc(i,r)<Fl)return 1;bc(o,i,r),$c(o,o);const l=function(t,e,n,i){const{data:r,offsetIdx:s,strideIdx:o}=t;let a=Number.NEGATIVE_INFINITY,u=0;for(let t=s;t<r.length;t+=o){Vl[0]=r[t]-e[0],Vl[1]=r[t+1]-e[1],Vl[2]=r[t+2]-e[2];const i=n[0]*Vl[0]+n[1]*Vl[1]+n[2]*Vl[2],s=n[0]*n[0]+n[1]*n[1]+n[2]*n[2],o=Vl[0]*Vl[0]+Vl[1]*Vl[1]+Vl[2]*Vl[2]-i*i/s;o>a&&(a=o,u=t)}return xc(i,r,u),a}(e,i,o,s);return l<Fl?2:(bc(a,r,s),$c(a,a),bc(u,s,i),$c(u,u),kc(n,a,o),$c(n,n),tc(e,n,o,a,u,h),0)}(s,t,p,u,h,l,c,f,d,a)){case 1:return void ic(Pl,Dl,e);case 2:return void lc(t,c,e)}!function(t,e,n,i,r,s,o,a,u){(function(t,e,n,i,r,s,o){!function(t,e,n,i,r){const{data:s,offsetIdx:o,strideIdx:a}=t;xc(i,s,o),xc(r,i),n[0]=Ec(ec,e),n[1]=n[0];for(let t=o+a;t<s.length;t+=a){const o=s[t]*e[0]+s[t+1]*e[1]+s[t+2]*e[2];o<n[0]&&(n[0]=o,xc(i,s,t)),o>n[1]&&(n[1]=o,xc(r,s,t))}}(t,e,Gl,o,s);const a=Ec(n,e);Gl[1]-Fl<=a&&(s[0]=-1/0),Gl[0]+Fl>=a&&(o[0]=-1/0)})(t,e,n,0,0,Nl,Ul),void 0!==Nl[0]&&(bc(ql,Nl,n),$c(ql,ql),bc(jl,Nl,i),$c(jl,jl),bc(Bl,Nl,r),$c(Bl,Bl),kc(Ll,jl,s),$c(Ll,Ll),kc(Hl,Bl,o),$c(Hl,Hl),kc(Wl,ql,a),$c(Wl,Wl),tc(t,Ll,s,jl,ql,u),tc(t,Hl,o,Bl,jl,u),tc(t,Wl,a,ql,Bl,u)),void 0!==Ul[0]&&(bc(ql,Ul,n),$c(ql,ql),bc(jl,Ul,i),$c(jl,jl),bc(Bl,Ul,r),$c(Bl,Bl),kc(Ll,jl,s),$c(Ll,Ll),kc(Hl,Bl,o),$c(Hl,Hl),kc(Wl,ql,a),$c(Wl,Wl),tc(t,Ll,s,jl,ql,u),tc(t,Hl,o,Bl,jl,u),tc(t,Wl,a,ql,Bl,u))}(t,p,u,h,l,c,f,d,a),cc(t,a.b0,a.b1,a.b2,ac,uc);const v=[0,0,0];bc(v,uc,ac),a.quality=wc(v),a.quality<o?vc(a.b0,a.b1,a.b2,ac,uc,v,e):ic(Pl,Dl,e)}({data:t,size:3,offsetIdx:0,strideIdx:3},e),e}In(){window.addEventListener("resize",(()=>{const t=this.Vn?.getBoundingClientRect();t&&this.Gn&&this.Yn&&(this.Gn.width=this.Yn.width=t.width*window.devicePixelRatio,this.Gn.height=this.Yn.height=t.height*window.devicePixelRatio,this.Gn.style.cssText=this.Yn.style.cssText="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n ")}))}}class Vc{Hn;Ve;Pi=[];Di;Ni;Ui;qi;ji;constructor(t){const e=t.viewer;this.Hn=e,this.Ve=t.data;const n=t.style.materialColor?t.style.materialColor:"rgba(255 165 0 0.5)",i=void 0===t.style.outline||t.style.outline;let s=t.style.outlineColor?t.style.outlineColor:"rgba(0, 0, 0, 0)";const o=t.style.outlineWidth?t.style.outlineWidth:1;!1===i&&(s="rgba(0, 0, 0, 0)"),this.Ui={materialColor:n,outline:i,outlineColor:s,outlineWidth:o};let a=[],u=[],h=0;for(let t of this.Ve){const e=r.Cartesian3.fromDegreesArrayHeights(t),i=new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(e),perPositionHeight:!0}),o=new r.GeometryInstance({id:"polygon_"+h,geometry:i,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(r.Color.fromCssColorString(n))}});a.push(o);const l=new r.PolygonOutlineGeometry({polygonHierarchy:new r.PolygonHierarchy(e),perPositionHeight:!0});let c=new r.GeometryInstance({id:"polygonOutline_"+h,geometry:l,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(r.Color.fromCssColorString(s))}});u.push(c),h++}let l=new r.Primitive({geometryInstances:a,appearance:new r.PerInstanceColorAppearance({flat:!0,renderState:{depthTest:{enabled:!1}}})});this.Pi.push(l);const c=e.scene.primitives.add(l);this.qi=c;let f=new r.Primitive({geometryInstances:u,appearance:new r.PerInstanceColorAppearance({flat:!0})});this.Pi.push(f);const d=e.scene.primitives.add(f);this.ji=d}show(t){"all"===t.id?this.Pi.forEach((t=>{t.show=!0})):this.Pi.forEach((e=>{e.id===t.id&&(e.show=!0)}))}hide(t){"all"===t.id?this.Pi.forEach((t=>{t.show=!1})):this.Pi.forEach((e=>{e.id===t.id&&(e.show=!1)}))}styleChange(t){const e=t.style.materialColor?t.style.materialColor:"rgba(255 165 0 0.5)",n=void 0===t.style.outline||t.style.outline;let i=t.style.outlineColor?t.style.outlineColor:"rgba(0, 0, 0, 0)";const s=t.style.outlineWidth?t.style.outlineWidth:1;!1===n&&(i="rgba(0, 0, 0, 0)"),this.Ui={materialColor:e,outline:n,outlineColor:i,outlineWidth:s};const o=this.qi._instanceIds;for(let e of o){const n=e,i="polygonOutline_"+e.split("_")[1];this.qi.getGeometryInstanceAttributes(n).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(t.style.materialColor)),this.ji.getGeometryInstanceAttributes(i).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(t.style.outlineColor))}}resetHighlight(){if(this.Di){const{materialColor:t,outline:e,outlineColor:n,outlineWidth:i}=this.Ui;this.qi.getGeometryInstanceAttributes(this.Di).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(t)),this.ji.getGeometryInstanceAttributes(this.Ni).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(n))}}highlight(t){var e=this.Hn.scene.pick(t.position);let n,i,s,o=r.defined(e)?e.id:void 0;if(void 0!==o){if(o.startsWith("polygon_")?(n=o,i="polygonOutline_"+o.split("_")[1],s="polygon"):o.startsWith("polygonOutline_")&&(i=o,n="polygon_"+o.split("_")[1],s="polygonOutline"),this.Di){const{materialColor:t,outline:e,outlineColor:n,outlineWidth:i}=this.Ui;this.qi.getGeometryInstanceAttributes(this.Di).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(t)),this.ji.getGeometryInstanceAttributes(this.Ni).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(n))}if(r.defined(e)&&(this.Di=n,this.Ni=i,"polygon"===s)){const e=this.qi.getGeometryInstanceAttributes(n);let s=t.style.materialColor?t.style.materialColor:null;if(s&&(e.color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(s))),t.style.outline){const e=this.ji.getGeometryInstanceAttributes(i);s=t.style.outlineColor?t.style.outlineColor:null,s&&(e.color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString(s)))}else this.ji.getGeometryInstanceAttributes(i).color=r.ColorGeometryInstanceAttribute.toValue(r.Color.fromCssColorString("rgba(0, 0, 0, 0)"))}}}}class Gc{Bi;Li=new Map;Hi=0;Wi=30;Vi=null;Gi=.8;Yi=2;Ki=300;Xi=0;constructor(t){this.Bi=t.Bi,this.Wi=t.Hi||30}Qi(t){return{Zi:t,Ji:(new Date).getTime(),er:0}}nr(t,e){let n=this.Li.get(t);return n?(e||(n.Ji=(new Date).getTime(),n.er+=1),n.Zi):null}ir(t,e){this.Li.forEach(((n,i)=>{t.call(e,n.Zi,i)}))}rr(t,e){if(this.Li.has(t)?this.Li.get(t).Zi=e:(this.Hi+=1,this.Li.set(t,this.Qi(e))),this.Hi>this.Wi&&this.sr(),this.Hi>this.Wi-1)return!0}ar(t){return this.Li.has(t)}ur(t){if(!this.ar(t))return null;this.Hi-=1;let e=this.Li.get(t);return this.Li.delete(t),e.Zi}xe(){this.hr(),this.Li.clear(),this.Hi=0}_destroy(){this.ir(((t,e)=>{this.Bi?this.Bi(e,t)&&this.ur(e):this.ur(e)}),this)}hr(){this.Vi&&clearTimeout(this.Vi)}sr(){if(this.Hi>this.Wi*this.Yi)this.hr(),this.lr();else{if((new Date).getTime()-this.Xi<10)return;this.hr();let t=this;this.Vi=setTimeout((function(){t.Vi=null,t.lr()}),this.Ki),this.Xi=(new Date).getTime()}}lr(){let t=Math.round(this.Wi*this.Gi);if(this.Hi<t)return;let e,n=this.cr(this.Hi-t);for(let t=0,i=n.length;t<i;t+=1)e=n[t],this.Bi?this.Bi(e,this.Li.get(e).Zi)&&this.ur(e):this.ur(e)}dr(t,e){let n=this.Li.get(t),i=this.Li.get(e),r=n.Ji-i.Ji;return 0!==r?r:n.er-i.er}cr(t){const e=Hc(this.Li.keys());return this.pr(e,t,this.dr)}pr(t,e,n){if(e<=0)return[];let i,r,s,o=0,a=t.length-1;for(;o<a;){for(i=o,r=a,s=t[e];i<=e&&r>=e;){for(;i<=e&&n.call(this,t[i],s)<0;)i+=1;for(;r>=e&&n.call(this,t[r],s)>0;)r-=1;let o=t[i];t[i]=t[r],t[r]=o,i+=1,r-=1}r<e&&(o=i),i>e&&(a=r)}return t.slice(0,e)}}function Yc(){const t=(t=0,e=0,n=0,i=1)=>[t,e,n,i],e=(t,e,n)=>{const i=e[0],r=e[1],s=e[2],o=e[3],a=n[0],u=n[1],h=n[2],l=n[3];return t[0]=i*l+o*a+r*h-s*u,t[1]=r*l+o*u+s*a-i*h,t[2]=s*l+o*h+i*u-r*a,t[3]=o*l-i*a-r*u-s*h,t},n=(t,e,n,i,r="zyx")=>{let s=.5*Math.PI/180;e*=s,n*=s,i*=s;let o=Math.sin(e),a=Math.cos(e),u=Math.sin(n),h=Math.cos(n),l=Math.sin(i),c=Math.cos(i);switch(r){case"xyz":t[0]=o*h*c+a*u*l,t[1]=a*u*c-o*h*l,t[2]=a*h*l+o*u*c,t[3]=a*h*c-o*u*l;break;case"xzy":t[0]=o*h*c-a*u*l,t[1]=a*u*c-o*h*l,t[2]=a*h*l+o*u*c,t[3]=a*h*c+o*u*l;break;case"yxz":t[0]=o*h*c+a*u*l,t[1]=a*u*c-o*h*l,t[2]=a*h*l-o*u*c,t[3]=a*h*c+o*u*l;break;case"yzx":t[0]=o*h*c+a*u*l,t[1]=a*u*c+o*h*l,t[2]=a*h*l-o*u*c,t[3]=a*h*c-o*u*l;break;case"zxy":t[0]=o*h*c-a*u*l,t[1]=a*u*c+o*h*l,t[2]=a*h*l+o*u*c,t[3]=a*h*c-o*u*l;break;case"zyx":t[0]=o*h*c-a*u*l,t[1]=a*u*c+o*h*l,t[2]=a*h*l-o*u*c,t[3]=a*h*c+o*u*l;break;default:throw new Error("Unknown angle order "+r)}return t};function i(i,r,s=0){const o=t();n(o,0,0,90+s,"xyz");const a=t();n(a,0,90-i[1],0,"xyz");const u=t();n(u,0,0,i[0],"xyz");const h=t();e(h,u,a),e(h,h,o);const l=t();n(l,0,0,-90,"xyz");const c=t();n(c,0,-(90-r[1]),0,"xyz");const f=t();n(f,0,0,-r[0],"xyz");const d=t();e(d,l,c),e(d,d,f);const p=t();return e(p,d,h),p}function r(t,e,n){const i=e[0],r=e[1],s=e[2],o=n[3]*i+n[7]*r+n[11]*s+n[15]||1;return t[0]=(n[0]*i+n[4]*r+n[8]*s+n[12])/o,t[1]=(n[1]*i+n[5]*r+n[9]*s+n[13])/o,t[2]=(n[2]*i+n[6]*r+n[10]*s+n[14])/o,t}var s=new Float32Array(1),o=new Int32Array(s.buffer);let a={};function u(t){s[0]=t;var e,n=o[0],i=n>>23&255,r=8388607&n;return 0==i?e=0:i<113?(e=0,r|=8388608,16777216&(r>>=113-i)&&(e=1,r=0)):i<142?e=i-112:(e=31,r=0),(n>>31&1)<<15|e<<10|r>>13}function h(t,e){return(u(t)|u(e)<<16)>>>0}const l=(t,e,n=!1)=>{const i=t[0],r=t[1];let s,o,a,u,h=!1;const l=e.length;for(let t=0,c=l-1;t<l;c=t,t+=1){let l=!1;if(s=e[t][0],o=e[t][1],a=e[c][0],u=e[c][1],s===i&&o===r||a===i&&u===r)return!!n;if(o<r==u>=r){const t=(a-s)*(r-o)/(u-o)+s;if(i===t)return!!n;l=i<t}l&&(h=!h)}return h},c=(t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[2]>=e[2]&&t[0]<=e[3]&&t[1]<=e[4]&&t[2]<=e[5];function f(t,e){return!(t[3]<e[0]||e[3]<t[0]||t[4]<e[1]||e[4]<t[1]||t[5]<e[2]||e[5]<t[2])}self.onmessage=n=>{if(n.data.vr){const s=function(n,s){const{te:o,vr:a,ee:u,oe:d,Vt:p,Bt:v,mr:m,jt:y,yr:w,wr:g=1/0}=n,b=w||d,_=new Float32Array(3*b),x=new Uint8Array(4*b),k=new Uint32Array(3*b);let $=2;y&&($=6);const S=4*$,M=v||4096,E=Math.floor(M/$),C=E*M,A=Math.ceil(b/E),O=Math.ceil(A/M),I=[],T=[],z=[];for(let t=0;t<O;t+=1){const e=t==O-1?A-M*(O-1):M;I[t]=new Uint32Array(M*e*4),T[t]=new Uint8Array(I[t].buffer),z[t]=new Float32Array(I[t].buffer)}const R={x:1/0,y:1/0,z:1/0},F={x:-1/0,y:-1/0,z:-1/0};let P=0;return a.forEach((o=>{o.gr?function(o){const{Kt:a,He:u,_r:d,kr:p,$r:v=1,Sr:m=0,Mr:w,Fe:g,te:b}=o;let k;p&&(k=i(g,n.Fe,m));let $=[];s&&($=s.filter(((t,e)=>(t.Er=e+1,f(t.Mr,w)))));const A=new Uint32Array(d),O=A[0],D=new Float32Array(A.buffer,8,18),N=D[0],U=D[1],q=D[2],j=D[6],B=D[7],L=D[8],H=0==D[9],W=1==D[10],V=0==D[11],G=D[12],Y=D[13],K=D[14],X=D[15],Q=D[16],Z=D[17];let J,tt,et,nt,it,rt,st,ot,at;V?(J=tt=2047,et=1023,nt=Math.ceil(48*O/32),it=Math.ceil(32*O/32),rt=new Uint16Array(A.buffer,80,3*O),st=new Uint32Array(A.buffer,80+4*nt,O),ot=11,at=10):(J=tt=et=1023,nt=Math.ceil(24*O/32),it=Math.ceil(16*O/32),rt=new Uint8Array(A.buffer,80,3*O),st=new Uint16Array(A.buffer,80+4*nt,O),ot=at=10);const ut=2**(ot+at),ht=2**at,lt=[0,0,0],ct=t=>{const e=t/ut|0,n=(t-e*ut)/ht|0,i=t-e*ut-n*ht;return lt[0]=e,lt[1]=n,lt[2]=i,lt},ft=nt+it,dt=W?20:4,pt=a*dt,vt=new Uint32Array(A.buffer,80+4*ft,pt),mt=new Uint8Array(A.buffer,80+4*ft,4*pt),yt=G/J,wt=Y/tt,gt=K/et,bt=[0,0,0];let _t,xt,kt,$t,St,Mt,Et,Ct,At,Ot,It,Tt,zt,Rt,Ft,Pt,Dt,Nt,Ut,qt,jt,Bt,Lt,Ht,Wt,Vt=0;for(let n=0;n<O;n+=1){_t=rt[3*n],xt=rt[3*n+1],kt=rt[3*n+2];const i=st[n];$t=_t*G+N,St=xt*Y+U,Mt=kt*K+q;for(let n=0;n<i;n++){Et=Math.floor(P/C),It=Et*C,Ct=I[Et],At=T[Et],Ot=z[Et];const n=Vt*dt,i=vt[n];[Tt,zt,Rt]=ct(i),Tt=$t+Tt*yt+u[0],zt=St+zt*wt+u[1],Rt=Mt+Rt*gt+u[2];const s=4*(n+2);Ut=(mt[s+4]-128)/128,qt=(mt[s+5]-128)/128,jt=(mt[s+6]-128)/128,Bt=(mt[s+7]-128)/128;let o=vt[n+1];if([Lt,Ht,Wt]=ct(o),Lt=j+Lt*X,Ht=B+Ht*Q,Wt=L+Wt*Z,H&&(Lt=Math.exp(Lt),Ht=Math.exp(Ht),Wt=Math.exp(Wt)),p){[Tt,zt,Rt]=r(bt,[Tt,zt,Rt],p);const n=t(qt,jt,Bt,Ut),i=t();e(i,k,n),Ut=i[3],qt=i[0],jt=i[1],Bt=i[2],Lt*=v,Ht*=v,Wt*=v}if(Ft=mt[s+0],Pt=mt[s+1],Dt=mt[s+2],Nt=mt[s+3],Vt+=1,Nt<13)continue;_[3*P]=Tt,_[3*P+1]=zt,_[3*P+2]=Rt,R.x=Math.min(R.x,Tt),R.y=Math.min(R.y,zt),R.z=Math.min(R.z,Rt),F.x=Math.max(F.x,Tt),F.y=Math.max(F.y,zt),F.z=Math.max(F.z,Rt);const a=P-It,f=Math.floor(a/E)*M*4+a%E*S;Ot[f+0]=Tt,Ot[f+1]=zt,Ot[f+2]=Rt,At[4*(f+7)+0]=Ft,At[4*(f+7)+1]=Pt,At[4*(f+7)+2]=Dt,At[4*(f+7)+3]=Nt,x[4*P]=Ft,x[4*P+1]=Pt,x[4*P+2]=Dt,x[4*P+3]=Nt,Ct[f+5]=h(Lt,Ht),Ct[f+6]=h(Wt,0),At[4*(f+4)+0]=128*Ut+128,At[4*(f+4)+1]=128*qt+128,At[4*(f+4)+2]=128*jt+128,At[4*(f+4)+3]=128*Bt+128,At[4*(f+3)+3]=Math.ceil(10*Math.max(Lt*v,Ht*v,Wt*v));for(let t=0,e=$.length;t<e;t+=1)if(c([Tt,zt,Rt],$[t].Mr)&&l([Tt,zt],$[t].Cr)){At[4*(f+3)]=$[t].Er;break}if(y)for(let t=0;t<16;t+=1)Ct[f+8+t]=vt[n+4+t];P+=1}}}(o):m?o.Ar.red?function(o){const{Kt:a,He:u,_r:d,Mr:p,kr:v,$r:m=1,Sr:y=0,Fe:b,Zt:k,Ar:$}=o;let A;v&&(A=i(b,n.Fe,y));let O=[];s&&(O=s.filter(((t,e)=>(t.Er=e+1,f(t.Mr,p)))));const D=new DataView(d),N=[0,0,0],U=d.byteLength/a;let q=1;w&&(q=Math.ceil(a/w));for(let n=0;n<a;n+=q){const i=Math.floor(P/C),s=i*C;var j=I[i],B=T[i],L=z[i];const o=U*n;let a=D[$.x](o+k.x,!0)+u[0],f=D[$.y](o+k.y,!0)+u[1],d=D[$.z](o+k.z,!0)+(u[2]||0);if(d>g)continue;const p=P-s,y=Math.floor(p/E)*M*4+p%E*S,w=D[$.red](o+k.red,!0),b=D[$.green](o+k.green,!0),q=D[$.blue](o+k.blue,!0),H=255;x[4*P]=w,x[4*P+1]=b,x[4*P+2]=q,x[4*P+3]=H,B[4*(y+7)+0]=w,B[4*(y+7)+1]=b,B[4*(y+7)+2]=q,B[4*(y+7)+3]=H;const W=[.01,.01,.01],V=[1,0,0,0];if(v){[a,f,d]=r(N,[a,f,d],v);const n=t(V[1],V[2],V[3],V[0]),i=t();e(i,A,n),V[0]=i[3],V[1]=i[0],V[2]=i[1],V[3]=i[2],W[0]*=m,W[1]*=m,W[2]*=m}R.x=Math.min(R.x,a),R.y=Math.min(R.y,f),R.z=Math.min(R.z,d),F.x=Math.max(F.x,a),F.y=Math.max(F.y,f),F.z=Math.max(F.z,d),L[y+0]=a,L[y+1]=f,L[y+2]=d,_[3*P]=a,_[3*P+1]=f,_[3*P+2]=d,j[y+5]=h(W[0],W[1]),j[y+6]=h(W[2],0),B[4*(y+4)+0]=128*V[0]+128,B[4*(y+4)+1]=128*V[1]+128,B[4*(y+4)+2]=128*V[2]+128,B[4*(y+4)+3]=128*V[3]+128,B[4*(y+3)+3]=Math.ceil(Math.max(W[0],W[1],W[2]));for(let t=0,e=O.length;t<e;t+=1)if(c([a,f,d],O[t].Mr)&&l([a,f],O[t].Cr)){B[4*(y+3)]=O[t].Er;break}P+=1}}(o):function(o){const{Kt:a,He:u,_r:d,Mr:p,kr:v,$r:m=1,Sr:w=0,Fe:b,Zt:k,Ar:$}=o;let A;v&&(A=i(b,n.Fe,w));let O=[];s&&(O=s.filter(((t,e)=>(t.Er=e+1,f(t.Mr,p)))));const D=new Float32Array(d),N=[0,0,0],U=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],q=2047,j=1023,B=new Float32Array(1),L=new Uint32Array(B.buffer);for(let n=0;n<a;n++){const i=Math.floor(P/C),s=i*C;var H=I[i],W=T[i],V=z[i];const o=62*n;let a=D[o+0]+u[0],f=D[o+1]+u[1],d=D[o+2]+(u[2]||0);if(d>g)continue;const p=P-s,w=Math.floor(p/E)*M*4+p%E*S,b=.28209479177387814,k=Math.max(0,Math.min(255,255*(.5+b*D[o+6]))),$=Math.max(0,Math.min(255,255*(.5+b*D[o+7]))),G=Math.max(0,Math.min(255,255*(.5+b*D[o+8]))),Y=1/(1+Math.exp(-D[o+54]))*255;if(Y<13)continue;x[4*P]=k,x[4*P+1]=$,x[4*P+2]=G,x[4*P+3]=Y,W[4*(w+7)+0]=k,W[4*(w+7)+1]=$,W[4*(w+7)+2]=G,W[4*(w+7)+3]=Y;const K=[Math.exp(D[o+55]),Math.exp(D[o+56]),Math.exp(D[o+57])],X=[D[o+58],D[o+59],D[o+60],D[o+61]],Q=Math.sqrt(X[0]**2+X[1]**2+X[2]**2+X[3]**2);if(X[0]/=Q,X[1]/=Q,X[2]/=Q,X[3]/=Q,v){[a,f,d]=r(N,[a,f,d],v);const n=t(X[1],X[2],X[3],X[0]),i=t();e(i,A,n),X[0]=i[3],X[1]=i[0],X[2]=i[1],X[3]=i[2],K[0]*=m,K[1]*=m,K[2]*=m}R.x=Math.min(R.x,a),R.y=Math.min(R.y,f),R.z=Math.min(R.z,d),F.x=Math.max(F.x,a),F.y=Math.max(F.y,f),F.z=Math.max(F.z,d),V[w+0]=a,V[w+1]=f,V[w+2]=d,_[3*P]=a,_[3*P+1]=f,_[3*P+2]=d,H[w+5]=h(K[0],K[1]),H[w+6]=h(K[2],0),W[4*(w+4)+0]=128*X[0]+128,W[4*(w+4)+1]=128*X[1]+128,W[4*(w+4)+2]=128*X[2]+128,W[4*(w+4)+3]=128*X[3]+128,W[4*(w+3)+3]=Math.ceil(Math.max(K[0],K[1],K[2]));for(let t=0,e=O.length;t<e;t+=1)if(c([a,f,d],O[t].Mr)&&l([a,f],O[t].Cr)){W[4*(w+3)]=O[t].Er;break}if(y){for(let t=0;t<45;t+=1)U[t]=D[o+9+t];const t=(t,e,n)=>{const i=Math.floor(t*q+.5),r=Math.floor(e*j+.5),s=Math.floor(n*q+.5);return(i<0?0:i>q?q:i)<<21|(r<0?0:r>j?j:r)<<11|(s<0?0:s>q?q:s)};let e=Math.abs(U[0]);for(let t=1;t<45;++t){const n=Math.abs(U[t]);n>e&&(e=n)}if(0===e)continue;for(let t=0;t<45;++t)U[t]=U[t]/e*.5+.5;B[0]=e,H[w+8]=L[0],H[w+9]=t(U[0],U[15],U[30]),H[w+10]=t(U[1],U[16],U[31]),H[w+11]=t(U[2],U[17],U[32]),H[w+12]=t(U[3],U[18],U[33]),H[w+13]=t(U[4],U[19],U[34]),H[w+14]=t(U[5],U[20],U[35]),H[w+15]=t(U[6],U[21],U[36]),H[w+16]=t(U[7],U[22],U[37]),H[w+17]=t(U[8],U[23],U[38]),H[w+18]=t(U[9],U[24],U[39]),H[w+19]=t(U[10],U[25],U[40]),H[w+20]=t(U[11],U[26],U[41]),H[w+21]=t(U[12],U[27],U[42]),H[w+22]=t(U[13],U[28],U[43]),H[w+23]=t(U[14],U[29],U[44])}P+=1}}(o):function(o){const{Kt:a,He:u,_r:d,Mr:p,kr:v,$r:m=1,Sr:y=0,Fe:w}=o;let b;v&&(b=i(w,n.Fe,y));let k=[];s&&(k=s.filter(((t,e)=>(t.Er=e+1,f(t.Mr,p)))));const $=new Float32Array(d),A=new Uint8Array(d),O=[0,0,0];["rgb(173,221,142)","rgb(120,198,121)","rgb(65,171,93)","rgb(35,132,67)","rgb(0,104,55)","rgb(0,69,41)"].map((t=>t.slice(4,-1).split(",").map((t=>+t)))),["rgb(189,189,189)","rgb(150,150,150)","rgb(115,115,115)","rgb(82,82,82)","rgb(37,37,37)","rgb(0,0,0)"].map((t=>t.slice(4,-1).split(",").map((t=>+t)))),["rgb(254,217,118)","rgb(254,178,76)","rgb(252,78,42)","rgb(227,26,28)","rgb(189,0,38)","rgb(128,0,38)"].map((t=>t.slice(4,-1).split(",").map((t=>+t)))),["rgb(218,218,235)","rgb(158,154,200)","rgb(128,125,186)","rgb(106,81,163)","rgb(84,39,143)","rgb(63,0,125)"].map((t=>t.slice(4,-1).split(",").map((t=>+t))));const D=["rgb(255,247,251)","rgb(236,226,240)","rgb(208,209,230)","rgb(166,189,219)","rgb(103,169,207)","rgb(54,144,192)","rgb(2,129,138)","rgb(1,108,89)","rgb(1,70,54)"].reverse().map((t=>t.slice(4,-1).split(",").map((t=>+t))));D[0],D[1],D[2],D[3],D[4],D[5];for(let n=0;n<a;n++){const i=Math.floor(P/C),s=i*C;var N=I[i],U=T[i],q=z[i];let o=$[8*n+0]+u[0],a=$[8*n+1]+u[1],f=$[8*n+2]+(u[2]||0);if(f>g)continue;const d=P-s,p=Math.floor(d/E)*M*4+d%E*S;let y=A[24+32*n],w=A[25+32*n],D=A[26+32*n],j=A[27+32*n];if(j<13)continue;x[4*P]=y,x[4*P+1]=w,x[4*P+2]=D,x[4*P+3]=j,U[4*(p+7)+0]=y,U[4*(p+7)+1]=w,U[4*(p+7)+2]=D,U[4*(p+7)+3]=j;const B=[$[3+8*n],$[4+8*n],$[5+8*n]],L=[(A[28+32*n]-128)/128,(A[29+32*n]-128)/128,(A[30+32*n]-128)/128,(A[31+32*n]-128)/128];if(v){[o,a,f]=r(O,[o,a,f],v);const n=t(L[1],L[2],L[3],L[0]),i=t();e(i,b,n),L[0]=i[3],L[1]=i[0],L[2]=i[1],L[3]=i[2],B[0]*=m,B[1]*=m,B[2]*=m}R.x=Math.min(R.x,o),R.y=Math.min(R.y,a),R.z=Math.min(R.z,f),F.x=Math.max(F.x,o),F.y=Math.max(F.y,a),F.z=Math.max(F.z,f),q[p+0]=o,q[p+1]=a,q[p+2]=f,_[3*P]=o,_[3*P+1]=a,_[3*P+2]=f,N[p+5]=h(B[0],B[1]),N[p+6]=h(B[2],0),U[4*(p+4)+0]=128*L[0]+128,U[4*(p+4)+1]=128*L[1]+128,U[4*(p+4)+2]=128*L[2]+128,U[4*(p+4)+3]=128*L[3]+128,U[4*(p+3)+3]=Math.ceil(Math.max(B[0],B[1],B[2]));for(let t=0,e=k.length;t<e;t+=1)if(c([o,a,f],k[t].Mr)&&l([o,a],k[t].Cr)){U[4*(p+3)]=k[t].Er;break}P+=1}}(o)})),R.x-=.5,R.y-=.5,R.z-=.5,F.x+=.5,F.y+=.5,F.z+=.5,{layerId:u,hasSH:y,key:p,uri:o,centers:_.buffer.slice(0,12*P),rgbas:x.buffer.slice(0,16*P),sigmas:k.buffer.slice(0,12*P),boundMax:Object.values(F),boundMin:Object.values(R),texdatas:I.map((t=>t.buffer)),vertexCount:P}}(n.data,a[n.data.ee]);self.postMessage(s,[s.centers,...s.texdatas,s.rgbas,s.sigmas])}else n.data.Or&&(a[n.data.ee]=n.data.Or)}}class Kc{Ir=[];Tr=[];zr=0;constructor(t){for(let e=0;e<t;e+=1)this.Ir.push(new Worker(URL.createObjectURL(new Blob(["(",Yc.toString(),")(self)"],{type:"application/javascript"}))))}postMessage(t,e){t.broadcast?this.Ir.forEach((n=>{n.postMessage(t,e)})):this.Ir[this.zr++%this.Ir.length].postMessage(t,e)}tryPost(){if(this.Tr.length){const t=this.Ir.find((t=>!t.isBusy));if(t){t.isBusy=!0;const e=this.Tr.shift();t.postMessage(e[0],e[1])}}}set onmessage(t){this.Ir.forEach((e=>{e.onmessage=t?e=>{t(e)}:null}))}}class Xc{Rr;Fr;Pr=null;Dr;Nr=1;MAX_STORAGE_BYTES=21474836480;Ur=!0;constructor(t,e,n=[],i=20){this.Rr=t,this.Fr=e,this.Dr=n.sort(((t,e)=>t.version-e.version)),this.MAX_STORAGE_BYTES=1073741824*i}async open(){return new Promise(((t,e)=>{const n=indexedDB.open(this.Rr);n.onerror=()=>e(n.error),n.onsuccess=async()=>{this.Pr=n.result,this.Nr=this.Pr.version,this.qr(this.Pr)?(this.Pr=this.Pr,t(this.Pr)):(this.Pr.close(),t(await this.jr())),t(this.Pr)},n.onupgradeneeded=t=>{this.Pr=n.result,this.jr()}}))}jr(){return new Promise(((t,e)=>{const n=this.Nr+1,i=indexedDB.open(this.Rr,n);i.onerror=()=>e(i.error),i.onsuccess=()=>{this.Pr=i.result},i.onupgradeneeded=t=>{this.Pr=i.result;const e=this.Pr.createObjectStore(this.Fr,{keyPath:"id"});e.indexNames.contains("created_at")||e.createIndex("created_at","metadata.createdAt",{unique:!1}),e.indexNames.contains("last_accessed")||e.createIndex("last_accessed","metadata.lastAccessed",{unique:!1}),e.indexNames.contains("uri")||e.createIndex("uri","metadata.uri",{unique:!0})}}))}qr(t){try{const e=t.transaction(this.Fr,"readonly").objectStore(this.Fr);return["created_at","last_accessed","uri"].every((t=>{try{return e.index(t),!0}catch{return!1}}))}catch(t){return!1}}async store(t,e,n){if(this.Br())return await this.Lr(),this.Hr({id:t,buffers:e,metadata:{createdAt:Date.now(),lastAccessed:Date.now(),...n}})}async Hr(t){return await this.Wr(),new Promise(((e,n)=>{const i=this.Pr.transaction(this.Fr,"readwrite").objectStore(this.Fr).put(t);i.onsuccess=()=>e(),i.onerror=()=>n(i.error)}))}async get(t){return this.Br()?(performance.now(),await this.Wr(),new Promise(((e,n)=>{const i=this.Pr.transaction(this.Fr,"readonly").objectStore(this.Fr).get(t);i.onsuccess=async()=>{const n=i.result;e(n??null),n&&await this.Vr(t)},i.onerror=()=>n(i.error)}))):null}async getMultiple(t){return this.Br()?(performance.now(),await this.Wr(),new Promise(((e,n)=>{const i=this.Pr.transaction(this.Fr,"readonly").objectStore(this.Fr),r=new Map;let s=t.length;t.forEach((n=>{const o=i.get(n);o.onsuccess=async()=>{const i=o.result;r.set(n,i??null),s-=1,0===s&&(e(r),this.Gr(t))},o.onerror=()=>{s-=1,r.set(n,null),0===s&&e(r)}}))}))):new Map}async has(t){return!!this.Br()&&(await this.Wr(),new Promise(((e,n)=>{const i=this.Pr.transaction(this.Fr,"readonly").objectStore(this.Fr).count(t);i.onsuccess=()=>e(i.result>0),i.onerror=()=>n(i.error)})))}async delete(t){if(this.Br())return await this.Wr(),new Promise(((e,n)=>{const i=this.Pr.transaction(this.Fr,"readwrite").objectStore(this.Fr).delete(t);i.onsuccess=()=>e(),i.onerror=()=>n(i.error)}))}async clear(){return await this.Wr(),new Promise(((t,e)=>{const n=this.Pr.transaction(this.Fr,"readwrite").objectStore(this.Fr).clear();n.onsuccess=()=>t(),n.onerror=()=>e(n.error)}))}async Wr(){this.Pr&&this.Pr.version===this.Nr||await this.open()}Br(){return!(this.Pr&&!this.Pr.objectStoreNames.contains("tiles")||!this.Pr)}close(){this.Pr&&(this.Pr.close(),this.Pr=null)}async Lr(){if(!this.Pr)return;if(!this.Ur)return;const{usage:t}=await navigator.storage.estimate();if(null!=t&&t>this.MAX_STORAGE_BYTES){const e=this.Pr.transaction(this.Fr,"readwrite").objectStore(this.Fr),n=e.index("last_accessed").openCursor();let i=10;this.Ur=!1,await new Promise(((r,s)=>{n.onsuccess=async()=>{const s=n.result;if(i>0&&s&&t>this.MAX_STORAGE_BYTES){const t=s.value;await e.delete(t.id),i--,i<=0&&(this.Ur=!0),s.continue()}else r()},n.onerror=()=>s(n.error)}))}}async Vr(t){if(!this.Pr)return;const e=this.Pr.transaction(this.Fr,"readwrite").objectStore(this.Fr),n=await new Promise(((n,i)=>{const r=e.get(t);r.onsuccess=()=>n(r.result||null),r.onerror=()=>i(r.error)}));n&&(n.metadata=n.metadata||{},n.metadata.lastAccessed=Date.now(),e.put(n))}async Gr(t){if(!this.Pr||0===t.length)return;const e=this.Pr.transaction(this.Fr,"readwrite"),n=e.objectStore(this.Fr);for(const e of t){const t=await new Promise(((t,i)=>{const r=n.get(e);r.onsuccess=()=>t(r.result||null),r.onerror=()=>i(r.error)}));t&&(t.metadata=t.metadata||{},t.metadata.lastAccessed=Date.now(),n.put(t))}return new Promise(((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error)}))}}!function(t){t[t.init=0]="init",t[t.loading=1]="loading",t[t.failed=2]="failed",t[t.loaded=3]="loaded",t[t.parsed=4]="parsed",t[t.destroyed=5]="destroyed"}(qc||(qc={}));class Qc extends Il{Oe;Te=Ml();Li;fe;_scene;Yr=null;ze=0;Re;Kr="";Xr=new Map;Qr=[];Zr;Jr="splat";ts=0;es=0;Bt;Pe=!0;Or;ns;rs;ss;us;hs=1;Pr;qe={Jt:new Int32Array(0),ne:[],_modelMatrix:r.Matrix4.IDENTITY.clone(),Xt:[],oe:0,je:0,Be:void 0,Le:[],jt:!1};ls;Ue;cs;fs;ds=!1;ps;vs;ys;ws=!1;constructor(t){super(),this.rs=new Kc(t.Ir||2),this.Oe=t.Oe,this.Zr=this.Oe.substring(0,this.Oe.lastIndexOf("/")+1);const e=this.Zr.match(/\[\d(,\d+)+\]/g);let n,i;if(e&&e[0]){const t=JSON.parse(e[0]);n=e[0],i=t}if(this.ns=new Zc(n,i),this.ns.gs=this.gs.bind(this),this.ns.bs=this.bs.bind(this),this.ns._s=this._s.bind(this),this.ns.xs=this.xs.bind(this),this.ys=t.ys,this.fe=t.fe,this._scene=t._scene,this.cs=t.cs,this.ps=t.ps,this.fs=Math.max(1e-5,Math.min(2,t.fs||1)),this.Bt=Math.min(4096,this.fe._gl.getParameter(this.fe._gl.MAX_TEXTURE_SIZE)),this.Ue=new Cl(this.fe,this.Bt),this.Li=new Gc({Hi:t.ks,Bi:(t,e)=>!(this.es===e.$s||this.qe&&-1!==this.qe.ne.indexOf(t)||this.Qr.find((e=>e.Oe==t))||(this.Ue.Ae(e),this.Ss(e),0))}),null!=t.Ms&&t.Ms>0&&(this.Pr=new Xc("AMapYunJing","tiles",[{version:1,migrate:(t,e)=>{}}],t.Ms),this.Pr.open()),this.Or=t.Or,this.vs=t.vs,t.Es){if(this.Jr=t.Es.type||"splat",this.Yr=t.Es.root,this.Yr.limitBounds){const t=this.Yr.limitBounds;this.Yr.limitBounds=[{height:t.minz,extrudedHeight:t.maxz-t.minz,path:t.polygon}]}this.ns.Jr=this.Jr}else this.Cs(t).then((()=>{if(t.Or.length){const e=this.Yr.enuCenter;t.Or.forEach((t=>{let n=1/0,i=1/0,r=-1/0,s=-1/0;t.Cr=t.polygon.map((t=>{const{x:o,y:a,z:u}=Ic([t[0],t[1],0],e);return n=Math.min(n,o),r=Math.max(r,o),i=Math.min(i,a),s=Math.max(s,a),[o,a]})),t.Mr=[n,i,t.height,r,s,t.extrudedHeight]})),this.rs.postMessage({broadcast:!0,ee:this.Te,Or:t.Or})}}));const r=t=>{t.data.ee==this.Te&&this.We(t.data)};this.rs.onmessage=t=>{t.data.layerId==this.Te&&this.Ye(t.data)},gl.addEventListener("message",r),this.ls=()=>{this.rs.onmessage=null,gl.removeEventListener("message",r)}}As(t){this.vs=t}Ss(t){t.Os=qc.destroyed,t._r=void 0,t.Gt=void 0,t.Xt=[]}_destroy(){this.fe=null,this.Or=[],this.Zr="",this.Oe="",this.ls(),this.ls=void 0,this.qe=void 0,this.Yr=null,this.es=0,this.Li._destroy(),this.Ue._destroy(),this.Qr=[],this.Xr=new Map,this.ns.clear()}Is(){if(this.Yr)return this.Yr}We(t){const{ne:e,Gt:n,Jt:i,se:s,oe:o,re:a,jt:u,ie:h}=t;let l=r.Matrix4.IDENTITY.clone();const c=[];e.forEach(((t,e)=>{const i=this.Li.nr(h[e],!0);i&&(i.Ts=!0,i.Gt=n[e],c[e]=i.Kt,l=i._modelMatrix)})),this.qe={Jt:new Int32Array(i.buffer,4*s),ne:e,jt:u,_modelMatrix:l,Xt:this.Ue.Me(a),Le:c,oe:o,je:this.qe?.je||0,Be:this.qe?.Be},this.Pe=!0,this.ss&&this.ss(this.qe)}zs(){return this.Pr}async Ye(t,e=!1){const{texdatas:n,boundMax:i,boundMin:r,layerId:s,key:o,uri:a,centers:u,rgbas:h,sigmas:l,vertexCount:c}=t,f=this.Bt,d=this.Li.nr(a,!0);d&&(!e&&this.Pr&&await this.Pr.store(a,n,{uri:a,key:o,layerId:s,boundMax:i,boundMin:r,centers:u,vertexCount:c}),d.oe=c,d.Kt=c,d.Xt=[],d.Gt=u,d.Lt=i,d.Ht=r,n.forEach(((t,e)=>{const n=new Float32Array(t),i=t.byteLength/16/f,r={width:f,height:i,arrayBufferView:n},s=o+"_"+e,a=Math.floor(this.Bt/(d.jt?6:2)),u=Math.ceil(Math.sqrt(this.Bt*a/(this.Yr?.avgCount||15e4))),h=this.Ue.Ee(d.Ie,2**(5-d.Yt)*u*240,i,d.Yt);h.ye(r,s,d.Ie),d.Xt.push(h)})),d.Os=qc.parsed,this.us&&this.us())}async Cs(t){if(!this.Oe)return;let e=this.Oe;this.ns.Rs&&this.ns.Fs&&(e=e.replace(this.ns.Fs,this.ns.Rs[0]));const n=await fetch(e,{cache:"default",mode:"cors",credentials:"omit"});if(!document.getElementById("yunjinglogo")){const t=document.createElement("img");t.id="yunjinglogo",t.style.cssText="position: absolute; top: 5px; left: 5px;",t.width=200,t.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAATkAAABFCAYAAAAxdpH/AAAAAXNSR0IArs4c6QAAHk1JREFUeF7tXXn8ftWc/3w+1zLWmVTCCDFlLJWxlAlTUShbRpYwibJFmLFvY2+yZC0UqWQiZI0K2UJobClLlhYlskSFNJ7zdt6P8zyve8/3Ps89d3ue5/vrnn9+r9/3Oevn3vs+53yW90clsQAwEbm7c+6+qrq9iNxaRG6oqldP7OLOqvqNsroA9hKRYxP7mVsNwF9E5DIR+RmA75rZF0TkBFW9qIv+hz4GCQwSWF8S0KrpAriuiDwZwFNV9WZV9ef8vhCQmwGiIxH5pKq+RlW/1GINQ9NBAoME1pkE5oIcgIcDeIOq3riDdS0N5PJzB/AhVT1AVX/ewZqGLgYJDBJYcQmUghyAaznn3m5me3c4/5UAOa4HwG9U9VGqenKH6xu6GiQwSGAFJbAG5ABcH8AnVPXuHc93ZUAuAN1IVfdT1aM6XufQ3SCBQQIrJIECyAG4JoBPqeq/9TDHlQK5AHROVfdS1ff3sN6hy0ECgwRWQAIFkBuNRoeZ2RN6mtfKgVwAuj/5a+u/qup3elr30O0ggUECS5TAFOQA3F9EPt7jXFYS5ALQnamqd1LVK3tc/9D1IIFBAkuQwBjkAFzDW1K/r6q37HEOKwtyYc3PUtWDe1z/0PUggUECS5DABOQeLyKH9zz+UkEOwI9EZAtVvVrZOgH8yhshbqGqf+xZDkP3gwQGCbSUAIDNReRxAHYSkX8UkT8COMPMPiAiNJy6yRBjkHPOfUdVt2k5blXzpYAcgLNU9VAR+aGInFIxyX29w/O7qhYy/D5IYJDAciQAgJj1XADPp8+rmX1CRM4TkWuLyPYAHicivwsuYj/hLBXA7UXkuwuY8kJBzoeK/VBVXyEin2U4moj8WUQ+Om+dAD5jZrsuQBZJQwC4oYjsXFL5A/mdKqmzdVQJwK18KN6doylfpqqfXEfLGKbagwRGo9EhqrqTqu6pqj+IhwBwNefci30Y5xPpBqeqPybIPVNEXtfDfOIuFwJyAH7ir6SvFJFjRGQT59wBZvZi59xLzey/K0DuSlXdaFWurOEo/rmSOV9zlYwkADIRubmIbM2YZobPtXmfANDCf1i+DwBnmxnjpYfSQAIAqG+/d9T066r6zQbdlTYBwJj2f4l+pEvaT7sYI0RgvVpV7yIi2wKYfs/c9J1zF5kZQfDLPob9RQAe7DfG7XQ0Gh1nZg/rYhIVffQKcgDO82QBrxKRo1T1/3kKcs69ycwer6qXO+c+rqq0IFeVHVT1tKpK0QdIkoJP12mTUhfAP6jqtiW71aldn+Scc+dkWfbYaF13dM49NBqfa72OiHBuPGlSN3IzVb0m6zGaxL9omwB4uog8OGWdJeu7sapuFc2Frj5fb9JfaLMr34uSsXp5di3mmdTUP5ezsix7SlLlvz2Xh4jIB6P6L/DP7X9S+6iqNxqNDjSz50f1eOI6vqpt1e8kCOFGp6rPUNUTAqkHD2gTlzcSiOwOgAZEbri/B/BNVT2I8PctVb1D1SAd/N4LyAG4IDyod05ONwA2FREqIB832UWccz9PjMF9bN0oCFqnw3W4AzEtp4vA2FLQywLYx5/QjqwzownIjUajt5jZU+u07blu6el3vT47AKeZ2Q6pMtsAQO6uAI5V1Vup8gKKvXji9yxDBXWOv7kxZHMPVT0VwBMB7E6QS/34U+U5q16nIOcXcJGqvprXGlW9YjIogM0AkHHkOao6NjQAoPXlgsQFPLfudWu9fijRSYm0VAPIJb4ky67WN8iNRqO30Um+5jp5Aufpflr8RnkuT1V1+qFuPMuyZ0X97O+c2yHLskeHb5ogR2akyW3h70RkD686eYWq0ovitwBuB+AkgtyvVXXjOpNoWLcTkANwsapSh3horDvjFRXAZ1X1cFV9cw74HlhldMit6aWq+rI6axxArvBSj3Vnw0muzhtUv27fIOecO1lVYx1e/Yk2aAHgeDPbMwK55znnbppl2fh2EE5y9IQgT+T1VJUqErqOvGTCWwngJmP/3/UCcoE55PUi8mbq2GLZBYA7BcDpWZbRjJzfTV7q5fKSRHk3AbmrATgusf+VrOZN7+dnWfafkdxItfXG3N9ISEq91h9opheRiwFcaGbnBBedMzzpwfjE7NUI+wHYreFiuRMXFNhe18Jn/qmG/YmqPlxVOf9CCY7w65FQ9XQzu2+qPOpeV1cQ5Pbl+zQBv/x1lW4lzrmDVHU3xt17vR3fTb6DdwLw/lUBuf28Q987yh6YV2Bf4i2ebxIR8tpdOqPOpgB4Nb1cVXdWVbqLTEsNowPb1Aa51BdtqJcmgcG6mianOrU2AJC7LYAv+FvaTYJhsaCTC4YJGuR+pKrUJRPknuuc23qpIAdgi+DTsrf3aaMbQv70dSkAKq9fN0HmGQDHYyoBbmOalstozp1zF1I4iS/FAHKJguqr2gBy3Uu2LsgBIAs4WcGXUS6d3Aiiw8pXveX0SG9APKzM8BB0cLSo8gbxtRCqus9SQI4CdM69UFVpySzkiOC1xF8932pmpCr/zTwJT3Rw3ieOFpcdy1wMeC8XkQtrPKlOQA7Azb0qgIrRO9TIg1Fjms2qAvijP+0y7wUVy6Un49Seg/f59YOP3K25a/JZZFn2qGjD2sU5x41sc6/vTKHcb+VC0uUaU2WxSvVofHPO0RF+WoIyfpfouZwO4Nv5v5nZ27v0netSLp4GbgcAzNeyo4jQo+Fued17OL09RkQ28rc3Em5cz8z2WCjIUUnonKNvDn3XOMn8yY2xZ6R64t364irh0E2ERgbvKnI7VX2MNy3T+XdNAfAAEflYVX+531uDnD9W7wzgoxRyjXEXWhXAT1X1nn6jYUhMaQGwa3AWn/xOjCLnIENoNvKWbdLiXzsPXBMXkkmD0Wj0GjN79kIXFwZLWeMy5tX3mN7Vgj6GDGNsUtb4tXlrJyOG7hl19j5VPbvJAD5OnP59sbHzVarKXCxzS3ALeSUjGrxD8IfpTpJvAOBGHuTfxo03vN+/WxjI8aMXkft45zyaeqcFwBUA3mlmB6Zm1ALAKyqtqFs75w6Ozc1R/3WMDmzaCuQAXA/Aj2NTetXDW8bvPqLi87GfUSS7xn5y7KfBBtOHGKjHYRD3Vab0AHJ08D0wEuAD6JTbRKjOOYZcFpy9RSQ5iocGCN72gsPvCWZGN5XrOOe2p8M/gPea2TMnBsqFgVwsDABX+ivdkWZGBP9ZqrACwH2GkQCBxXj3eTuAc+5j3qTM01xqaQty9OMpPVWmTmDB9baisrZszDbOwOyvgez7WvrMNfY14DL73dBBLmygVHPt7pzjBnYTM/uTiJwhIkxURdCbloWDHACGXB1jZjxy0vUguYQrKgFum3Ba2k5VL5nXQU2jA7tqC3KMp1vjZ+ece58PQVlahjBVveOMEw03iRPbghxd0EXkV/5a80UzG4eCOee+p6q3yfcNgE6a/xtcUcY/BWbmqeMpabG8+T8mcOWL/IhJX2GTPKTwMs9e4/2uSsH9XYBccP+5aQAUumYUQvScc4eYGUGldgkOu5tFDfcXkYmLzzk+uP4ztTue0WBhIAdgxLAMM3s5mQHqLiAA3Cm8ogKg9YWU5d+b108Do0MXIEd/PF6Rp4W+e2a2Xd01d1k/5O+gi03Mpzfz2gHgnl7HdkA0j21ictWw4TDmlyA3LTOuJYxEeW0kn4LMZjiDEgS/kgO5y8yMRo+8nKkvrLXGLmW8Kn0BoEqIRqB8oU7toOj50MAXJ3KiquWSVfOTayPb3kHOMwU4OuQFcPt+k8mGKyoBjic4Jp8hu0ClMaEhpXvbk1wZyPF0Q4vQUos3+pBlpWDNFpFaupWySIayuFcudAbIMedt4QTmT4GdgFwY88+xUavuGpf6kHoavK4LyQByCQ8iXF94P36Zqjbmq/O+chvTDy7HxkGuKFIpVZb446ls8LcKfYAcGTSeHEJQEqfRebW7ll2jReT+3r+QxINJZZ2C3AN9Do/S/CUAjqKxKGnxK1aJV3DvlnNEyrQGkOswdjWAG2mNCBbfSnkAs+qEKypj6CYhPmQWYXhOwWw8q31DxXdbkFvDhdZGBgtoSz++5ExlHYDcmlwaXZ3kSJjovdy5oSRfyRcY1tj5o6ReLMuyWJ1QOk5dkBuNRu/pKTVppRxIsJFl2ZMqKyZW6Oy6GsDtpABubXi/xlPPX1HD/0nRTuc/xk0mlQZGhy5OcvTTIXEnfclWugRq+K1TNw0upibIMTnSP+eF4KMZyHrDEL5pHCn9CunTNKkX5kVDzbQ45zbPp8v09Ne8lhZO9ABoXCnjsJt5Wh1Arjs+uVV92TsBOVKjhOj/qWK4zYLzbiIB4JhkhpbUgml43hjesZiOqk2sma1OcmG++/hEG0eoKon8VrIE480uqnp6nQnWBLkTVTU5iLzOPGrWpcN4qZFqALlqkCN5q4hws6IDeGkiqJrPI1+dhA90IftBijNwk3HaghzDg0htwn87KUEHR9AcE3nS5cTTGZPVtdYYDY0OrU9yudPIjt7R+XmBDroQ3dGJoJp3wrC5LwRDUKl/3Lyu64AcALp8vLf5VNu39KSJXzcz0nKXlgHkZoMcg94ZHuZvT8/uOzQRwM98mOF/qWrMXtz6JWgEcgC+Ek5unfmyBEC7QTgV5ml2nuKjB+jdXKsE/vdavHBhgNYnuVoTXWeV64AclzYajY4wswL11aKWDOCXIenJmoQnuc2Ip5NCPK13PSIfIenC84VO3qX+hItaT8k4vLInqW/q6uTC9/gcESEx7UJK8Jy4r1dLdZpKoBbI0d8rgFvnDzvWwVGqzrnDsyxjjFrt4pxj7CjJMuuWAeTmSKwuyIWP5REAGDhN7v1FXOEvCyFrZLD5Zd0XwDlHSn2ySY8LfTwZpke22bp9rUr9JiAXy2ERa+kjY14SyAFgHgieihgilWTZrCOQEjcRvlhf8jzt92qalarFA2oMcoGV48E+jy39+Ao00HXksaC6tBWdY2ZHe73ZV1PHbAJyqX2vQj0f98iMYPHJ7xs+TjNOkbgK002eQ12QA3AtJmyOByAWeDXEzJNx6oTC9ZcpA2+Ub8Nrq5mR5qmzMhfk6OTplecv997Tx/cBbmGXpB/cVAcX/sb7Obnhau/CoX1TowObNwK54L5AZob4mtPZw+qjIyKdV/jS95CZzirLVQDk6LpAFotpcc69NssyXt3WbWkAcvQdLFBxMdxOVZlyspODTri98VufknbQ+m5m01N0FwIvBTkidQC347pOfRehNnVwn2Zc5eTvgQuMFMbfaLpAf62+n09O3IghoQXI0cjQWXq3pmtv0Y60S2U5XgtdpoKc3/EfxMQjLebTaVMzI8VXJZXPjBSdM+N7O51kj511BHK1MoSlLCd281okyPHkxqxVP0mZaJM6AcWZeHZqZAinikf53aKVRa6F0aHxSc45d27I99hEHEtv45w7LsuyaQD8rAmlgtx6SWQTbbrMdfeLvKohWPdvUJZXpO+HBoAeBrG/Ja/OBXr/lHl0BHI/B1DwX0wZe16dkOmeeXzHZWEgFwYjFRIDeMkWMpeht+5CYzeRXHtmx+aJqFVxzn3ER1s8qGEnta+rABgPemXZeNQxiAjD2jo54jdc06QZKebvqqr0eyoUMsSaWZz9fM1wGzjIMai9wKzhiUO/bGYkjVx4cc4xLDJ2bqY7VW2vhi5AbhECWCjI5ZD1dz7gmYR5b8nnN226YABlbiJEcMbhMVjcNe170q6F0YFdNAG50uTSge+OcZO1d962MpjVPjCnkiufls5pmRVkH/ezgYPc07zDK5MmTQv9xLIsI33WwgsAZk9jhrp8oV8q9eS1ygByCbGrAM7zKd1eJCLMYt0IiABsFIwMUx0cn5RPSkGmUJ4wxqnE2hR+xC0D4TsDORGhz8/JEZjwNEXLa2WugzZyCG0ZOsVokZgiuowpZU1y6bLxa4AcnUiX4h9XNu+Q46D0tD2p75wjnfYeUXuGnH2+g2dRuwufz4AW3UJECoCT66QinAw6gFwCyOWExWw49IBmfoXkEk5wDLaPTfHMrk3a4qac9IU5tDQ6sK8uQY4ca6cFIL+Gc4678P5l18VkQdasGDYncvgxEe+4hLwNTNA9LV2f5GpOc+nVPZFj5nMPcEOgc/BETgz232hZJ/Fgsf9tlCuE3wt1hLUOGl2AHAB++//e5cNiREqkA73IzFIz6yVNRZlohPzocW1V3ZLhVLN6CddLGifOrBppzhWVTpa8zn2yqo/U373j5ou9w+n4OA+AyY/n8c4xbq5wyjEzZuGuNR8mKBaRsivpGOTopUEiyBnB46lLa1vv+d5UPyZNHEBurSiZiNjTTv1fBPynmFkhw1Xbh1C3/Qxet2092NRi5e0I5L5qZlMG57prKavvnLso7yvXi05u3kTJDOutOwRBvgBrSmD7ZZ4GnlBKg+EDwBXcRHIdPU9VOw0byRsdnHPHxunxungwcR8JINfGpaWTKZMuPFzZaCF7ps+p2ftJjgYmESGPXlzezHSIIb9q7DRNn8mpczIA8uDFQMMPYw2P2oy6tJa+s0qInlH4WX6zLzAWe4p2ps2ME7hUddXp7wCoIiqkF6RMPTC8vc5AHYEc01nSAk+WoVonyRlz3Z6HkCjb24VmNqZd76pU6oWCF/8jvQWRCWcKyurJJAD8wRMPHhwSQV+W+zuP/oxDWwOSzrn3Zln2yK4WMunHOUfnwomQmLEnVtx2PSRPRnNPcqPR6G1m1hk/VosF7OOB7ugFgtw2IlLGVbcZ0046584gnX20ngLfXNlcPdNvaQSCP7kzT8Ch+f6YYNjMblslM+ccDV9MSpwvpNhPjgapGqPJ7wDIKF3QCTrnjsmybO86/TUAOVLJ87peiRF15lFVlxEVZlbQ2Ve1qfo9eQHMESAiT/M8Xrz2TPUW0QvFgGjmN+Aue53g6LsmHCbc7RnSwQw7nZUSo8NOddlLmkwmAeSY22KvSFb0q3usiFzeZMyKNjdnshjmSC0DkAWCHNk/ykDiugws7wHkKM+p7pFrTwkTogsQE+yo6jRjfKCi2tgb26a8dz08p8ouma8BAD0cps+SfIVm9k+VjXMV6oIcmzrnaIWfyeBSZ/zUus65l2dZRsNYZyUZ5CYj8vrpnGMYEI/M8Uc0rhZi23g94k5eKIEZgiFbyWkIU1frlZi7i8iYyjswGlBp3CpLfMrYTUDOOfeOLMvIItxLcc4xJO/2SwY5qjtOKVlgRsV5DyD3MBE5LtpMfm1mm84TsrdYFpLkhPeH+TzrpLLs5TkGsGEc992iAW6sqr9IHbQJyNG6G/IbL4QePsTIM9qp042/NsjlwO6WzjkmhH5oKjlk0Asx6P5LqQ+nTr3I6HC2mTHYuvfSBORC3op717WSpSxmToLr8VVwgSe5NbpIXoHMbOzF3wPIEZQKhiaGCZrZGsNaBIQv9GSQcd4Qcpu9IUXefdcZjUYHmhkTPOfLQ/wh4kOpYzcBuQD2WzrnmGGNagW6P7EQYNfElwI4X0QujudURm4AgCSmJACgbu83wU3n0FTqqNR1sx6tfvf32bHbkDpuB+Dp+SDbORN4oqoeXmeCderm/ZwAnNZQaXy2qp5dZ9wEkHuXmfEqVSi0JPV0Xd1EVW9QsoaxwnqBIMf8q++PAOW3ZkaDRB8gt7OIFFybQqjg1SsSkNMwFhs37twmfrrO+1NVN39DmdStSxrQFORK3tkbAuA1dovouf6BOXbLbmghNULc1cLkm0S1VPUQUn4n0aaZxUfulKbJdSKjQ3K7qGLnfnJeL7SviFRa+JpOuEY75nM4c4EgR+X40dHHcIGZbd4TyDEs7Zsl8qBubSYXnHPukhLfRfLHFfLI1pBzp1V9MvZbiUghV7G3JJ9kZrGhZOa4XYAcgM047oS1OxpspqfEVQnkPmRmvdEQ8QGISLKOYs5b2AfIUXlMi2Clla/TryPXWd6dxl/h1jC+9uEMPMPa+UMzGye3mXFdpe8l3ZbGBcDeAZSnq+FVJ8uygiEn1CUP2XklMtxKVUup3gHwKlumA6KDeuuETF08TwB3CW4bBRmY2e1S+28LciHR+FHedWe8QUUbF5NMUc9Ov9M15SoDcs65I7MsK4T50Ms8hf4m5UGWHelT2pXU6Rzkwgd4UwAMibtHw3k1ahYMMMf4DeBJjD0Onv2fi+fRE8i9QEQKPHUAvmZm9H0rBTn/MX2RmbuavBf0AJjh9nCPWXrgOW1I9fUIVS2coBo9hBaNPEkGr4d8b+4VAcu5nvC0cGXMbQzUtU/0Z5M/M1KhYJTx7PR0nB87iOcKHfTHDvIcm6GJAB49KzAgWKHp9H7WrGXOALm9VZXvZe9lYddV59wbsyxjwPG4eBeHLYOLycEkKWxrqp/hNNlEgL2AXG7d2/qX7TYLogFnrCZjH2nl5imHbCmMzaTvVaEAOMPMOLe5JTV2lZ2MRqPXm9n0mYfn/gkzox541kmOPzFp0Ue8M27pyWDGBD9IklXnHEOzNonqEKziD3xaxTlHPeyWJTKhUvwiLqVKLj38TqDiKfPvVTUGLH4/MxP0eFDcimkdoznR5a3QDzfA2KlXVZnXeGzQmOGjOO3W/36ZqjLd4xfnrd85x3pT95zQt2NeZoJkidxP7dKNhCB3oTcGdBorNmPBLws+dBTetYNhYOxiAoDH3ae2sbrOCK5u8u7RkhR7vs/tp8rw0GQSXbaZERoUg9ynzOw+VePWBLk1/oE+f+oRWZbtF0COscz3rhoz8ffdPMnDSd6QxtCs2Pm8cAUu+aimoYCJY61CtZnRGAQ5EWkaC76nt6QeXwVypM5nHKsnNPh2lTCcc7w57FRVb/I7QyDNbM/U+lX1CHLUFXXqYTxj0KlJfjQaHW1mBY9tHmkBvMfMCDK1dWsdGR049ceo6rurBJf/fUMAOZ+j9gkh6fPcpdcBOefcqZ77LOZim56UATxeRLqytk+iOWjNpVV3Wpxzh83LyB5vunWe/TLqBuZuWidLM3X1CXI8/TGbmZlx40jyQaUqyfvcnZAaPdE5yI1GozW7bU8Pbl8yYQBg9q1p3F24rzN+bUxyGe74jJogf12St3nQHTTKB1GyVlI+fa2ODNY7yJG+xyeZvl+KHqwmyOVD7CYinW4iQT9IQoTKE2TC83gR81SMRqNXkeo82oQ+Z2Z0TJ5ZAGxK1lvqAxPGWlqVkDGPiZIunDWJPkDOq4P+oqofZhytz2NCEthaxUdtPMNvJq9Jyd/aOcj5cJY1RIG1Zp9emcfP80IWrmmkBB2K/dGUTCbHRi/mmZ6R+IAULi+vzKYpvRZzSNm0fTLoKwK1zhXpyxoD8zWon4jb+JwJOy479pFzcs4xCqSMTYOp945ibs3UrGij0eiNjHaJ1npWHG8YTkd02yg4nIc8qGP6qbCp0UfzOQD28eGAayx3qc8BAK/B+wNgnPWRUbtfpmSACnHaD/T0VPRpZNjh2J9vmSUcAriBMx0oT6kE4rmbP4BbMiVjk3n7WxQNVONvic/Eh2CSJYhMxOTao36ycQFwCxHh86HhiXHw1y8xkHDcE5umIi2bHJ2B29zf6yyYuTcP8h8VFzp5wUlTTreSh8cgN6nDQH4zI3/dvJ2rjKmhztwm8znRzBgaNpRBAvzYqCyPcywsUjI0eFw6yzVjkRNZz2ONd1nnHInr6IvTWwmKyqnJm9Y8xuMxTs0zA9PnqXCSy0/E0+BcHiif31R24pjBhd9kLf+hqu9p0nBoM0hgkMBqSmAMcvSDEZGF+KyE8Wjm305Vzw3/nwtyuZMfUyXyCltI5OGcO7/MSbGOyL2ukBxlWyyLBbbOXIe6gwQGCaRLYAJypH4mawX9t3otIUh/F+/ceGoOvJJALlefPlHkiju/Q6PDUzwN81t7XfzQ+SCBQQILl8BUKQxg55BkxnqexX4xq2vVdbVsPiEJNZkjvk+laMs507udVtUka27LsYbmgwQGCSxQAgXLF/M9UMnf1/hx1EPTk1x+fuFk2JhFJXht8+r8g77WPfQ7SGCQwPIkUAC54LdEi+c47KbLMs8Xq8lJrou5Bd+fPbzRZUy0OZRBAoMENjwJrCHNDHTL1HmR8LDLwtNSIYdkFye5phP0NO5/9sHXDDz+YNM+hnaDBAYJrL4ESpmBeaIjKZ9P9vyM1FCMhKXOJMlb9EmOZJWq+jDPrPDlhHkPVQYJDBJYxxKYS38OYFcAh6gqHYbblqWDXIi7e7eZ0TI7k0Sx7UKH9oMEBgmsjgQqczwwk5GIkLiQ/mmVVDxzlrY0kGO4VoiHY+xcraS8q/OohpkMEhgk0EQClSCX7xQAmUh387FlTFPG0x1J9QiClYWkfz6DfFkOTjojPwTAYZWdpFdgHOkFgSONXFekbP59evOh5iCBQQIbigT+CsiVwM0XmXL2AAAAAElFTkSuQmCC",document.getElementsByClassName("cesium-viewer")[0].appendChild(t)}let i;try{i=await n.json()}catch(t){return}if(i){if("2.0"==i.v&&(i=this.Ps(i)),this.Jr=i.type||"splat",this.ns.Jr=this.Jr,this.Yr=i.root,this.Yr.limitBounds){const t=this.Yr.limitBounds;this.Yr.limitBounds=[{height:t.minz,extrudedHeight:t.maxz-t.minz,path:t.polygon}]}else i.limitBounds&&(this.Yr.limitBounds=i.limitBounds);if(t.Ds){const e=Math.floor(1073741824*t.Ds/44/(this.Yr.avgCount||15e4));this.Li.Wi=e}this._scene.requestRender(),this.emit("configloaded",null)}}Ps(t){t.type=t.t,delete t.t,t.root.enuCenter=t.root.ec,delete t.root.ec;const e=(n,i)=>{n.geometricError=t.e[i],delete n.e,n.c&&(n.content=n.c,delete n.c,n.content.u&&(n.content.uri=n.content.u+"."+t.type,delete n.content.u),n.content.c&&(n.content.coord=n.content.c,delete n.content.c),void 0!==t.r[i]&&(n.content.rank=t.r[i])),n.r&&(n.refine=n.r),n.s&&(n.children=n.s,delete n.s,n.children.forEach((t=>{e(t,i+1)}))),n.bbox=[n.b[0],n.b[1],t.root.minZ,n.b[2],n.b[3],t.root.maxZ],delete n.b};return e(t.root,0),delete t.e,delete t.r,t}Ns(t,e,n,i,r,s,o,a,u){let h=Math.max(t-o,0,o-i),l=Math.max(e-a,0,a-r),c=Math.max(n-u,0,u-s);return Math.sqrt(h*h+l*l+c*c)}Us(t,e,n){const i=e.bbox;return this.Ns(i[0],i[1],i[2],i[3],i[4],n||i[5],t.x,t.y,t.z)}qs(t,e,n,i,s,o){let a=e;const{enuCenter:u=s,bbox:h,rotate:l,scale:c,depth_Test:f,content:d={},geometricError:p}=t,[v,m,y]=u,w=r.Cartesian3.fromDegrees(v,m,y),g=i?e:r.Transforms.eastNorthUpToFixedFrame(w),b=Dc(new r.Cartesian3((h[0]+h[3])/2,(h[1]+h[4])/2,(h[2]+h[5])/2),u,g);let _=!1,x=r.Matrix4.IDENTITY.clone();if(i||(_=!0,x=r.Matrix4.multiply(n,g,x)),l){_=!0;const t=r.Math.toRadians(l),e=r.Matrix4.fromRotationTranslation(r.Matrix3.fromRotationZ(t));x=r.Matrix4.multiply(x,e,x)}if(c&&1!==c){_=!0;const t=r.Matrix4.fromScale(new r.Cartesian3(c,c,c),new r.Matrix4);x=r.Matrix4.multiply(x,t,x)}return{js:p,Mr:[h[0],h[1],h[2],h[3],h[4],h[5]],jt:!1,sn:!0,ln:f,Ti:d.coord,Ie:b,Oe:this.Zr+d.uri,Yt:d.rank,Fe:w,Bs:u,_modelMatrix:a,kr:_?x:void 0,$r:c,Sr:l,Os:qc.init,ts:this.ts,te:o}}Ls(t,e){return t.map((t=>{const n=new r.Cartesian3(t.x,t.y,t.z),i=t.w,s=r.Matrix4.multiplyByPointAsVector(e,n,new r.Cartesian3),o=r.Cartesian3.multiplyByScalar(n,-i,new r.Cartesian3),a=r.Matrix4.multiplyByPoint(e,o,new r.Cartesian3),u=-r.Cartesian3.dot(s,a);return new r.Cartesian4(s.x,s.y,s.z,u)}))}async Hs(t){if(!this.Yr)return this.Qr=[],this.Qr;this.es=(new Date).getTime(),this.ts+=1;const e=this.Yr,n=new Map,i=[],s=t.camera,o=s.frustum.computeCullingVolume(s.positionWC,s.directionWC,s.upWC).planes;let a=this.Yr.enuCenter;const u=a[0],h=a[1],l=a[2],c=r.Cartesian3.fromDegrees(u,h,l),f=r.Transforms.eastNorthUpToFixedFrame(c),d=r.Matrix4.inverse(f,new r.Matrix4),p=this.Ls(o,d);let v=Fc(s.positionWC,a);const m=this.ps;let y=!1;const w=(t,u=0)=>{let h=!1,l=!1,c=!1;const{enuCenter:y=a,bbox:g,geometricError:b,content:_={},prism:x}=t,k=y[0]===a[0]&&y[1]===a[1]&&y[2]===a[2];let $=p,S=v,M=f;if(!k){const t=r.Cartesian3.fromDegrees(y[0],y[1],y[2]);M=r.Transforms.eastNorthUpToFixedFrame(t);const e=r.Matrix4.inverse(M,new r.Matrix4);S=Fc(s.positionWC,y),$=this.Ls(o,e)}const E=new r.Cartesian3(g[0]-m,g[1]-m,g[2]-m),C=new r.Cartesian3(g[3]+m,g[4]+m,g[5]+m),A=new r.AxisAlignedBoundingBox(E,C);if(h=new r.CullingVolume($).computeVisibility(A)!==r.Intersect.OUTSIDE,h){let r,s;if(x){const t=x[0],e=x[1],n=[];for(let t=2;t<x.length;t+=2)n.push([x[t],x[t+1]]);r=v.z>=t&&v.z<=e&&Ac([v.x,v.y],n,!0)?0:1/0}else r=this.Us(S,t,e.maxZ);if((0==r||r<=b*this.vs[_.uri?u:0]/this.fs)&&(l=!0),l){if(_.uri){const e=_.uri;s=this.Li.nr(e,!1),s||(s=this.qs(t,f,d,k,a,_.uri),s.Ws=!!x,this.Li.rr(e,s)),s.$s=this.es,n.has(e)?s.Vs=Math.min(s.Vs,r):(n.set(e,s),s.Vs=r)}if(t.children&&t.children.length){let e=!0,n=!1,r=!1;t.children.forEach((t=>{const[i,s,o]=w(t,_.uri?u+1:0);i&&(r=!0,o||(e=!1),"ADD"==t.refine&&(n=!0))})),e=r&&e,!e||n||"ALWAYS"==t.refine?s&&s.Os==qc.parsed&&(c=!0,-1==i.indexOf(s)&&i.unshift(s)):c=!0}else s&&s.Os==qc.parsed&&(c=!0,-1==i.indexOf(s)&&i.unshift(s))}}return[h,l,c]};w(e),this.Pr&&await this.Gs(n),this.Qr=i.filter((t=>(y=t.Ws||!1,t.sn&&t.oe))),y&&this.Qr.length>1&&(this.Qr=[this.Qr[this.Qr.length-1]]),this.Xr=n;const g=r.Cartographic.fromCartesian(s.positionWC);return this.Ys([180*g.longitude/Math.PI,180*g.latitude/Math.PI,g.height],this.cs),this.Qr}Qe(t,e){let n=t[2]*e[2]+t[6]*e[6]+t[10]*e[10];const i=(t[2]**2+t[6]**2+t[10]**2)**.5,r=(e[2]**2+e[6]**2+e[10]**2)**.5;return Math.abs(n/i/r-1)>.01}async Gs(t){if(!this.Pr)return;const e=Hc(t.values()).filter((t=>t.Os==qc.init)),n=e.map((t=>t.te)).filter((t=>void 0!==t));if(0===n.length)return;const i=await this.Pr.getMultiple(n);for(const t of e){const e=t.te;if(e&&t.Os===qc.init){const n=i.get(e);n&&(t.Os=qc.loading,this.Ye({texdatas:n.buffers,...n.metadata},!0))}}}Ks(t){let e=this.Qr;if(!e.length)return;e.sort(((t,e)=>t.Yt==e.Yt?t.Vs>e.Vs?-1:1:t.Yt<e.Yt?-1:1));const n=e[e.length-1].Yt,i=this.ys;if(i&&n-e[0].Yt>=i){const t=n-i;e=e.filter((e=>e.Yt>t))}const s=t.camera.viewMatrix,o=t.camera.frustum.projectionMatrix,a=(new Date).getTime();let u=!1;if(0==this.Pe||this.qe&&this.qe.Jt.buffer.detached)return;const h=e.map((t=>t.Oe)).sort().join("|");if(this.ze?((0==this.ns.Tr.length||a-this.ze>400)&&this.Kr!==h||this.Qe(this.Re,s))&&(u=!0):u=!0,u){this.ze=a,this.Re=s.clone(),this.Kr=h,this.Pe=!1;const t=[this.qe.Jt.buffer],n={ee:this.Te,Ze:s,Jt:this.qe.Jt,Bt:this.Bt,qt:e.map((e=>{t.push(e.Gt);const n=new r.Matrix4;return r.Matrix4.multiply(s,e._modelMatrix,n),r.Matrix4.multiply(o,n,n),{Yt:e.Yt||0,Vt:e.Oe,te:e.te,Gt:e.Gt,Wt:n,jt:e.jt,Lt:e.Lt,Ht:e.Ht,Kt:e.oe,Xt:e.Xt?.map((t=>({Zt:t.Zt,_id:t._id})))}}))};gl.busy=!0,gl.postMessage(n,t)}}Xs(){if(this.Qr.length)return this.qe}async Qs(){const t=Hc(this.Xr.values()).filter((t=>t.Os==qc.init));t.sort(((t,e)=>t.Yt==e.Yt?t.Vs<e.Vs?-1:1:t.Yt<e.Yt?-1:1));let e=t;if(this.Pr){const n=t.map((t=>t.te)),i=await Promise.all(n.map((t=>this.Pr.has(t))));e=t.filter(((t,e)=>!i[e]))}this.ns.loads(e)}Zs(t,e){const n=t+"."+this.Jr,i=this.Li.nr(n,!1);i&&(i.sn=e)}Js(t){const{x:e,y:n,z:i}=Ic(t,this.Yr?.enuCenter);for(let t=0,r=this.Or.length;t<r;t+=1)if(Oc([e,n,i],this.Or[t].Mr)&&Ac([e,n],this.Or[t].Cr))return this.Or[t];return null}Ke(t,e){if(t){for(let n=0,i=this.Or.length;n<i;n+=1)if(this.Or[n].id==t){this.qe.je=n+1,this.qe.Be=e?.fillColor||void 0;break}}else this.qe.je=0}eo(){return this.Qr}gs(t,e){const n=t,i=this.Li.nr(n,!0);if(i){if(e||this.Xr.has(n))return i.Os=qc.loading,!0;this.Li.ur(n)}return!1}bs(t){const e=this.Li.nr(t.uri,!0);e&&(e.Os=qc.failed)}xs(){this.emit("preloadComplete",null)}_s(t){const e=this.Li.nr(t.uri,!0);e&&(e.oe=t.totalVertexCount,e.Kt=t.totalVertexCount,e._r=t.data,e.Os=qc.loaded,e.jt=t.hasSH,this.rs.postMessage({vr:[{Mr:e.Mr,_r:e._r.buffer,He:[0,0,0],Kt:t.totalVertexCount,gr:t.isCompressed,kr:e.kr,$r:e.$r,Sr:e.Sr,Fe:e.Bs,Zt:t.offsets,Ar:t.types,Vt:e.Oe,te:e.te}],wr:this.Yr?.clipZ,mr:t.isPly,jt:t.hasSH,Fe:this.Is()?.enuCenter,Bt:this.Bt,oe:t.totalVertexCount,yr:t.isPly&&t.types.red&&t.totalVertexCount>15e6?5e6:0,Vt:e.Oe,ee:this.Te,Ti:e.Ti,te:e.te},[e._r.buffer]))}Ys(t,e=1e3){if(this.Yr){this.ds=!0;let n=this.Yr.enuCenter;t=t||n;const i=n[0],s=n[1],o=n[2],a=r.Cartesian3.fromDegrees(i,s,o),u=r.Transforms.eastNorthUpToFixedFrame(a),h=r.Matrix4.inverse(u,new r.Matrix4),l=Ic(t,n),c=new Map,f=i=>{for(let r=0,s=i.length;r<s;r+=1){const s=i[r],{enuCenter:o=n,content:a={}}=s,d=o[0]===n[0]&&o[1]===n[1]&&o[2]===n[2],p=d?l:Ic(t,o);if(this.Us(p,s)<=e){if(a.uri){const t=this.Zr+a.uri,e=a.uri;if(e&&!this.Li.nr(e,!0)){const i=a.rank,r=this.qs(s,u,h,d,n,e);r.Ws=!!s.prism;const o=this.Li.rr(e,r);if(c.get(i)||c.set(i,[]),c.get(i)?.push({url:t,uri:e}),o)return o}}if(s.children&&f(s.children))return!0}}},d=this.Yr;f([d]),Hc(c.keys()).forEach((t=>{const e=c.get(t);for(let t=0,n=e.length;t<n;t+=1)this.ns.io(e[t])}))}}}class Zc{ro=12;Tr=[];so=[];oo=[];rr=new Set;ao=0;Jr="";zr=0;uo=0;gs;bs;_s;xs;Fs;Rs;ho=[];constructor(t,e){this.Fs=t,this.Rs=e,this.ro=6*(this.Rs?.length||1)}clear(){this.Tr=[],this.so=[],this.rr.clear(),this.ao=0}loads(t){t.forEach((t=>{if(this.rr.has(t.Oe)){const e=this.Tr.indexOf(t.Oe);this.Tr.splice(e,1),this.so.splice(e,1)}else this.rr.add(t.Oe);this.Tr.push(t.Oe),this.so.push(t.te)})),t.length,this.co()}io(t){this.rr.has(t.url)||(this.oo.push(t.url),this.ho.push(t.uri),this.rr.add(t.url),this.co())}async co(){if(this.ao<this.ro&&(this.Tr.length||this.oo.length)){this.ao++;const t=this.Jr;let e=this.Tr.shift(),n=this.so.shift(),i=!1;if(e||(e=this.oo.shift(),n=this.ho.shift(),i=!0),this.rr.delete(e),!this.gs(n,i))return this.ao--,void this.co();let r=e;this.Rs&&this.Fs&&(r=e.replace(this.Fs,this.Rs[this.zr%this.Rs.length]),this.zr+=1);const s=await fetch(r,{cache:"default",mode:"cors",credentials:"omit"});if(200!==s.status&&304!==s.status)return this.bs({url:e,uri:n,message:s.status}),this.ao--,void this.co();const o=parseInt(s.headers.get("content-length"));if(!o)return this.bs({url:e,uri:n,message:"empty"}),this.ao--,void this.co();const a=await s.arrayBuffer();let u,h=new Uint8Array(a),l=!1,c=!1;const f={},d={};let p=!1;if("bin"==t||e.endsWith("bin"))u=new Uint32Array(a,0,2)[1],l=!0,p=1==new Float32Array(a,8,18)[10];else if("splat"==t||e.endsWith("splat"))u=o/32;else if("ply"==t||e.endsWith(".ply")){c=!0;const t=h,e=(new TextDecoder).decode(t.slice(0,10240)),n="end_header\n",i=e.indexOf(n);u=parseInt(/element vertex (\d+)\n/.exec(e)[1]);const r={double:"getFloat64",int:"getInt32",uint:"getUint32",float:"getFloat32",short:"getInt16",ushort:"getUint16",uchar:"getUint8"};let s=0;for(let t of e.slice(0,i).split("\n").filter((t=>t.startsWith("property ")))){const[e,n,i]=t.split(" "),o=r[n]||"getInt8";f[i]=o,d[i]=s,s+=parseInt(o.replace(/[^\d]/g,""))/8}p=!!f.f_rest_44;const o=i+n.length;h=t.slice(o)}this._s({url:e,data:h,isCompressed:l,isPly:c,totalVertexCount:u,offsets:d,types:f,hasSH:p,uri:n}),this.ao--,this.co()}else this.Tr.length||this.ao||this.xs&&(this.xs(),this.uo)}}class Jc{fo;do="单体化图层";po=!1;vo;mo;yo;_show=!0;wo;Hn;bo;_o;qt;xo;ko;$o;So;Mo;Eo;ve=0;constructor(t){this.bo=t,this.Eo=t.cb,this.Hn=t.viewer,this.qt=t.tiles,this._o=t.api_url,this.ko={},this.xo=[],this.So={},this.Mo=[],this.$o=new Gc({Hi:500,Bi:this.onDrop}),this.vo=new r.Event,this.mo=new r.Event,this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this.init()}init(){this.Eo&&this.Eo(this.fo)}initMonomer(t,e,n){const i=e.points,r=e.indexes,s=e.tile_code;for(let e=0;e<r.length;e+=3){const o=r[e],a=r[e+1],u=r[e+2];void 0===t[s]&&(t[s]=[]),t[s].push({monomer_id:n,tile_code:s,points:[i[o],i[a],i[u]]})}}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}onDrop=(t,e)=>{delete this.ko[t],this.So=[],this.Mo=[],this.xo=[],this.ve=0,this.fo.removeAll();for(let t in this.ko)this.xo=this.xo.concat(this.ko[t]);let n=this.ve;for(let t of this.xo)this.So[n]=t,this.initMonomer(this.Mo,t,n),n++;return!0};updateData(t){for(let e of t)this.$o.ar(e)||(this.$o.rr(e,"1"),fetch(this._o+e+"_triangle.json").then((t=>t.json())).then((t=>{this.ko[e]=t,this.xo=[];for(let t in this.ko)this.xo=this.xo.concat(this.ko[t]);let n=this.ve;for(let t of this.xo)t.tile_code=e,this.So[n]=t,this.initMonomer(this.Mo,t,n),n++})).catch((t=>{})));return!0}update(){return!0}pick(t,e){let n=!1,i="",s=[];for(let t of e)void 0!==this.Mo[t]&&(s=s.concat(this.Mo[t]));const o=[];for(let e of s){const s=r.Cartesian3.fromDegrees(e.points[0][0],e.points[0][1],e.points[0][2]),a=r.Cartesian3.fromDegrees(e.points[1][0],e.points[1][1],e.points[1][2]),u=r.Cartesian3.fromDegrees(e.points[2][0],e.points[2][1],e.points[2][2]),h=r.IntersectionTests.rayTriangle(t,s,a,u);h&&(n=!0,i=e.monomer_id,o.push({monomer_id:i,res:h}))}const a=t.origin;let u=1e6;for(let t of o){const e=r.Cartesian3.distance(a,t.res);e<u&&(u=e,i=t.monomer_id)}return n?this.So[i]:null}}class tf{Hn;Co;me=!1;constructor(t){const e=t.viewer;this.Hn=e,this.Co=new Jc(t),e.dataSources.add(this.Co)}setVisibility(t,e){this.Co&&(this.Co.show=e)}hide(){this.Co&&(this.Co.entities.show=!1)}show(){this.Co&&(this.Co.entities.show=!0)}destory(){this.Co&&(this.Co.entities.removeAll(),this.Hn?.dataSources.remove(this.Co),this.Co=void 0),this.me=!0,this.Hn=void 0}getEntities(){return this.Co?.entities}pick(t,e){return this.Co?.pick(t,e)}update(t){return this.Co?.updateData(t)}}function ef(t){if(!t)throw new Error("geojson is required");switch(t.type){case"Feature":return nf(t);case"FeatureCollection":return function(t){const e={type:"FeatureCollection"};return Object.keys(t).forEach((n=>{switch(n){case"type":case"features":return;default:e[n]=t[n]}})),e.features=t.features.map((t=>nf(t))),e}(t);case"Point":case"LineString":case"Polygon":case"MultiPoint":case"MultiLineString":case"MultiPolygon":case"GeometryCollection":return sf(t);default:throw new Error("unknown GeoJSON type")}}function nf(t){const e={type:"Feature"};return Object.keys(t).forEach((n=>{switch(n){case"type":case"properties":case"geometry":return;default:e[n]=t[n]}})),e.properties=rf(t.properties),null==t.geometry?e.geometry=null:e.geometry=sf(t.geometry),e}function rf(t){const e={};return t?(Object.keys(t).forEach((n=>{const i=t[n];"object"==typeof i?null===i?e[n]=null:Array.isArray(i)?e[n]=i.map((t=>t)):e[n]=rf(i):e[n]=i})),e):e}function sf(t){const e={type:t.type};return t.bbox&&(e.bbox=t.bbox),"GeometryCollection"===t.type?(e.geometries=t.geometries.map((t=>sf(t))),e):(e.coordinates=of(t.coordinates),e)}function of(t){const e=t;return"object"!=typeof e[0]?e.slice():e.map((t=>of(t)))}var af=6371008.8,uf={centimeters:637100880,centimetres:637100880,degrees:360/(2*Math.PI),feet:20902260.511392,inches:39.37*af,kilometers:6371.0088,kilometres:6371.0088,meters:af,metres:af,miles:3958.761333810546,millimeters:6371008800,millimetres:6371008800,nauticalmiles:af/1852,radians:1,yards:6967335.223679999};function hf(t,e,n={}){const i={type:"Feature"};return(0===n.id||n.id)&&(i.id=n.id),n.bbox&&(i.bbox=n.bbox),i.properties=e||{},i.geometry=t,i}function lf(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!vf(t[0])||!vf(t[1]))throw new Error("coordinates must contain numbers");return hf({type:"Point",coordinates:t},e,n)}function cf(t,e={}){const n={type:"FeatureCollection"};return e.id&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.features=t,n}function ff(t,e="kilometers"){const n=uf[e];if(!n)throw new Error(e+" units is invalid");return t*n}function df(t,e="kilometers"){const n=uf[e];if(!n)throw new Error(e+" units is invalid");return t/n}function pf(t){return t%360*Math.PI/180}function vf(t){return!isNaN(t)&&null!==t&&!Array.isArray(t)}function mf(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function yf(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function wf(t,e,n={}){var i=mf(t),r=mf(e),s=pf(r[1]-i[1]),o=pf(r[0]-i[0]),a=pf(i[1]),u=pf(r[1]),h=Math.pow(Math.sin(s/2),2)+Math.pow(Math.sin(o/2),2)*Math.cos(a)*Math.cos(u);return ff(2*Math.atan2(Math.sqrt(h),Math.sqrt(1-h)),n.units)}function gf(t,e,n,i,r){bf(t,e,n||0,i||t.length-1,r||xf)}function bf(t,e,n,i,r){for(;i>n;){if(i-n>600){var s=i-n+1,o=e-n+1,a=Math.log(s),u=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*u*(s-u)/s)*(o-s/2<0?-1:1);bf(t,e,Math.max(n,Math.floor(e-o*u/s+h)),Math.min(i,Math.floor(e+(s-o)*u/s+h)),r)}var l=t[e],c=n,f=i;for(_f(t,n,e),r(t[i],l)>0&&_f(t,n,i);c<f;){for(_f(t,c,f),c++,f--;r(t[c],l)<0;)c++;for(;r(t[f],l)>0;)f--}0===r(t[n],l)?_f(t,n,f):_f(t,++f,i),f<=e&&(n=f+1),e<=f&&(i=f-1)}}function _f(t,e,n){var i=t[e];t[e]=t[n],t[n]=i}function xf(t,e){return t<e?-1:t>e?1:0}function kf(t,e,n){if(!n)return e.indexOf(t);for(let i=0;i<e.length;i++)if(n(t,e[i]))return i;return-1}function $f(t,e){Sf(t,0,t.children.length,e,t)}function Sf(t,e,n,i,r){r||(r=Ff(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let s=e;s<n;s++){const e=t.children[s];Mf(r,t.leaf?i(e):e)}return r}function Mf(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Ef(t,e){return t.minX-e.minX}function Cf(t,e){return t.minY-e.minY}function Af(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Of(t){return t.maxX-t.minX+(t.maxY-t.minY)}function If(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function Tf(t,e){const n=Math.max(t.minX,e.minX),i=Math.max(t.minY,e.minY),r=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,r-n)*Math.max(0,s-i)}function zf(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Rf(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function Ff(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Pf(t,e,n,i,r){const s=[e,n];for(;s.length;){if((n=s.pop())-(e=s.pop())<=i)continue;const o=e+Math.ceil((n-e)/i/2)*i;gf(t,o,e,n,r),s.push(e,o,o,n)}}var Df=class{constructor(t=9){this.Ao=Math.max(4,t),this.Oo=Math.max(2,Math.ceil(.4*this.Ao)),this.clear()}all(){return this.Io(this.data,[])}search(t){let e=this.data;const n=[];if(!Rf(t,e))return n;const i=this.toBBox,r=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],a=e.leaf?i(o):o;Rf(t,a)&&(e.leaf?n.push(o):zf(t,a)?this.Io(o,n):r.push(o))}e=r.pop()}return n}collides(t){let e=this.data;if(!Rf(t,e))return!1;const n=[];for(;e;){for(let i=0;i<e.children.length;i++){const r=e.children[i],s=e.leaf?this.toBBox(r):r;if(Rf(t,s)){if(e.leaf||zf(t,s))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this.Oo){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this.To(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this.zo(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this.Ro(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this.Ro(t,this.data.height-1),this}clear(){return this.data=Ff([]),this}remove(t,e){if(!t)return this;let n=this.data;const i=this.toBBox(t),r=[],s=[];let o,a,u;for(;n||r.length;){if(n||(n=r.pop(),a=r[r.length-1],o=s.pop(),u=!0),n.leaf){const i=kf(t,n.children,e);if(-1!==i)return n.children.splice(i,1),r.push(n),this.Fo(r),this}u||n.leaf||!zf(n,i)?a?(o++,n=a.children[o],u=!1):n=null:(r.push(n),s.push(o),o=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}Io(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}To(t,e,n,i){const r=n-e+1;let s,o=this.Ao;if(r<=o)return s=Ff(t.slice(e,n+1)),$f(s,this.toBBox),s;i||(i=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,i-1))),s=Ff([]),s.leaf=!1,s.height=i;const a=Math.ceil(r/o),u=a*Math.ceil(Math.sqrt(o));Pf(t,e,n,u,this.compareMinX);for(let r=e;r<=n;r+=u){const e=Math.min(r+u-1,n);Pf(t,r,e,a,this.compareMinY);for(let n=r;n<=e;n+=a){const r=Math.min(n+a-1,e);s.children.push(this.To(t,n,r,i-1))}}return $f(s,this.toBBox),s}Po(t,e,n,i){for(;i.push(e),!e.leaf&&i.length-1!==n;){let n,i=1/0,r=1/0;for(let s=0;s<e.children.length;s++){const o=e.children[s],a=Af(o),u=If(t,o)-a;u<r?(r=u,i=a<i?a:i,n=o):u===r&&a<i&&(i=a,n=o)}e=n||e.children[0]}return e}Ro(t,e,n){const i=n?t:this.toBBox(t),r=[],s=this.Po(i,this.data,e,r);for(s.children.push(t),Mf(s,i);e>=0&&r[e].children.length>this.Ao;)this.Do(r,e),e--;this.No(i,r,e)}Do(t,e){const n=t[e],i=n.children.length,r=this.Oo;this.Uo(n,r,i);const s=this.qo(n,r,i),o=Ff(n.children.splice(s,n.children.length-s));o.height=n.height,o.leaf=n.leaf,$f(n,this.toBBox),$f(o,this.toBBox),e?t[e-1].children.push(o):this.zo(n,o)}zo(t,e){this.data=Ff([t,e]),this.data.height=t.height+1,this.data.leaf=!1,$f(this.data,this.toBBox)}qo(t,e,n){let i,r=1/0,s=1/0;for(let o=e;o<=n-e;o++){const e=Sf(t,0,o,this.toBBox),a=Sf(t,o,n,this.toBBox),u=Tf(e,a),h=Af(e)+Af(a);u<r?(r=u,i=o,s=h<s?h:s):u===r&&h<s&&(s=h,i=o)}return i||n-e}Uo(t,e,n){const i=t.leaf?this.compareMinX:Ef,r=t.leaf?this.compareMinY:Cf;this.jo(t,e,n,i)<this.jo(t,e,n,r)&&t.children.sort(i)}jo(t,e,n,i){t.children.sort(i);const r=this.toBBox,s=Sf(t,0,e,r),o=Sf(t,n-e,n,r);let a=Of(s)+Of(o);for(let i=e;i<n-e;i++){const e=t.children[i];Mf(s,t.leaf?r(e):e),a+=Of(s)}for(let i=n-e-1;i>=e;i--){const e=t.children[i];Mf(o,t.leaf?r(e):e),a+=Of(o)}return a}No(t,e,n){for(let i=n;i>=0;i--)Mf(e[i],t)}Fo(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():$f(t[n],this.toBBox)}};function Nf(t,e,n){if(null!==t)for(var i,r,s,o,a,u,h,l,c=0,f=0,d=t.type,p="FeatureCollection"===d,v="Feature"===d,m=p?t.features.length:1,y=0;y<m;y++){a=(l=!!(h=p?t.features[y].geometry:v?t.geometry:t)&&"GeometryCollection"===h.type)?h.geometries.length:1;for(var w=0;w<a;w++){var g=0,b=0;if(null!==(o=l?h.geometries[w]:h)){u=o.coordinates;var _=o.type;switch(c=0,_){case null:break;case"Point":if(!1===e(u,f,y,g,b))return!1;f++,g++;break;case"LineString":case"MultiPoint":for(i=0;i<u.length;i++){if(!1===e(u[i],f,y,g,b))return!1;f++,"MultiPoint"===_&&g++}"LineString"===_&&g++;break;case"Polygon":case"MultiLineString":for(i=0;i<u.length;i++){for(r=0;r<u[i].length-c;r++){if(!1===e(u[i][r],f,y,g,b))return!1;f++}"MultiLineString"===_&&g++,"Polygon"===_&&b++}"Polygon"===_&&g++;break;case"MultiPolygon":for(i=0;i<u.length;i++){for(b=0,r=0;r<u[i].length;r++){for(s=0;s<u[i][r].length-c;s++){if(!1===e(u[i][r][s],f,y,g,b))return!1;f++}b++}g++}break;case"GeometryCollection":for(i=0;i<o.geometries.length;i++)if(!1===Nf(o.geometries[i],e))return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Uf(t,e){if("Feature"===t.type)e(t,0);else if("FeatureCollection"===t.type)for(var n=0;n<t.features.length&&!1!==e(t.features[n],n);n++);}function qf(t,e){var n,i,r,s,o,a,u,h,l,c,f=0,d="FeatureCollection"===t.type,p="Feature"===t.type,v=d?t.features.length:1;for(n=0;n<v;n++){for(a=d?t.features[n].geometry:p?t.geometry:t,h=d?t.features[n].properties:p?t.properties:{},l=d?t.features[n].bbox:p?t.bbox:void 0,c=d?t.features[n].id:p?t.id:void 0,o=(u=!!a&&"GeometryCollection"===a.type)?a.geometries.length:1,r=0;r<o;r++)if(null!==(s=u?a.geometries[r]:a))switch(s.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":if(!1===e(s,f,h,l,c))return!1;break;case"GeometryCollection":for(i=0;i<s.geometries.length;i++)if(!1===e(s.geometries[i],f,h,l,c))return!1;break;default:throw new Error("Unknown Geometry Type")}else if(!1===e(null,f,h,l,c))return!1;f++}}var jf="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Bf(t){return t&&t.Bo&&{}.hasOwnProperty.call(t,"default")?t.default:t}var Lf,Hf={exports:{}},Wf=(Lf||(Lf=1,Hf.exports=function(){function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function e(t,e,n){return e=u(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,l()?Reflect.construct(e,n||[],u(t).constructor):e.apply(t,n))}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e,n){if(l())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,e);var r=new(t.bind.apply(t,i));return n&&c(r,n.prototype),r}function r(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,p(i.key),i)}}function s(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=v(t))||e){n&&(t=n);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,o=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return o=t.done,t},e:function(t){a=!0,s=t},f:function(){try{o||null==n.return||n.return()}finally{if(a)throw s}}}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,n){var i=function(t,e){for(;!{}.hasOwnProperty.call(t,e)&&null!==(t=u(t)););return t}(t,e);if(i){var r=Object.getOwnPropertyDescriptor(i,e);return r.get?r.get.call(arguments.length<3?t:n):r.value}},a.apply(null,arguments)}function u(t){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},u(t)}function h(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}function l(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(l=function(){return!!t})()}function c(t,e){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},c(t,e)}function f(t,e,n,i){var r=a(u(1&i?t.prototype:t),e,n);return 2&i&&"function"==typeof r?function(t){return r.apply(n,t)}:r}function d(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||v(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function v(e,n){if(e){if("string"==typeof e)return t(e,n);var i={}.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?t(e,n):void 0}}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return i(t,arguments,u(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)},m(t)}var y=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getEndCapStyle",value:function(){return this.Lo}},{key:"isSingleSided",value:function(){return this.Ho}},{key:"setQuadrantSegments",value:function(e){this.Wo=e,0===this.Wo&&(this.Vo=t.JOIN_BEVEL),this.Wo<0&&(this.Vo=t.JOIN_MITRE,this.Go=Math.abs(this.Wo)),e<=0&&(this.Wo=1),this.Vo!==t.JOIN_ROUND&&(this.Wo=t.DEFAULT_QUADRANT_SEGMENTS)}},{key:"getJoinStyle",value:function(){return this.Vo}},{key:"setJoinStyle",value:function(t){this.Vo=t}},{key:"setSimplifyFactor",value:function(t){this.Yo=t<0?0:t}},{key:"getSimplifyFactor",value:function(){return this.Yo}},{key:"getQuadrantSegments",value:function(){return this.Wo}},{key:"setEndCapStyle",value:function(t){this.Lo=t}},{key:"getMitreLimit",value:function(){return this.Go}},{key:"setMitreLimit",value:function(t){this.Go=t}},{key:"setSingleSided",value:function(t){this.Ho=t}}],[{key:"constructor_",value:function(){if(this.Wo=t.DEFAULT_QUADRANT_SEGMENTS,this.Lo=t.CAP_ROUND,this.Vo=t.JOIN_ROUND,this.Go=t.DEFAULT_MITRE_LIMIT,this.Ho=!1,this.Yo=t.DEFAULT_SIMPLIFY_FACTOR,0===arguments.length);else if(1===arguments.length){var e=arguments[0];this.setQuadrantSegments(e)}else if(2===arguments.length){var n=arguments[0],i=arguments[1];this.setQuadrantSegments(n),this.setEndCapStyle(i)}else if(4===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2],a=arguments[3];this.setQuadrantSegments(r),this.setEndCapStyle(s),this.setJoinStyle(o),this.setMitreLimit(a)}}},{key:"bufferDistanceError",value:function(t){var e=Math.PI/2/t;return 1-Math.cos(e/2)}}])}();y.CAP_ROUND=1,y.CAP_FLAT=2,y.CAP_SQUARE=3,y.JOIN_ROUND=1,y.JOIN_MITRE=2,y.JOIN_BEVEL=3,y.DEFAULT_QUADRANT_SEGMENTS=8,y.DEFAULT_MITRE_LIMIT=5,y.DEFAULT_SIMPLIFY_FACTOR=.01;var w=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({Exception:i})[0],r}return h(i,t),s(i,[{key:"toString",value:function(){return this.message}}])}(m(Error)),g=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({IllegalArgumentException:i})[0],r}return h(i,t),s(i)}(w),b=s((function t(){n(this,t)}),[{key:"filter",value:function(t){}}]);function _(){}function x(){}function k(){}var $,S,M,E,C,A,O,I=s((function t(){n(this,t)}),null,[{key:"equalsWithTolerance",value:function(t,e,n){return Math.abs(t-e)<=n}}]),T=s((function t(e,i){n(this,t),this.low=i||0,this.high=e||0}),null,[{key:"toBinaryString",value:function(t){var e,n="";for(e=2147483648;e>0;e>>>=1)n+=(t.high&e)===e?"1":"0";for(e=2147483648;e>0;e>>>=1)n+=(t.low&e)===e?"1":"0";return n}}]);function z(){}function R(){}z.NaN=NaN,z.isNaN=function(t){return Number.isNaN(t)},z.isInfinite=function(t){return!Number.isFinite(t)},z.MAX_VALUE=Number.MAX_VALUE,z.POSITIVE_INFINITY=Number.POSITIVE_INFINITY,z.NEGATIVE_INFINITY=Number.NEGATIVE_INFINITY,"function"==typeof Float64Array&&"function"==typeof Int32Array?(C=2146435072,A=new Float64Array(1),O=new Int32Array(A.buffer),z.doubleToLongBits=function(t){A[0]=t;var e=0|O[0],n=0|O[1];return(n&C)===C&&1048575&n&&0!==e&&(e=0,n=2146959360),new T(n,e)},z.longBitsToDouble=function(t){return O[0]=t.low,O[1]=t.high,A[0]}):($=Math.log2,S=Math.floor,M=Math.pow,E=function(){for(var t=53;t>0;t--){var e=M(2,t)-1;if(S($(e))+1===t)return e}return 0}(),z.doubleToLongBits=function(t){var e,n,i,r,s,o,a,u,h;if(t<0||1/t===Number.NEGATIVE_INFINITY?(o=1<<31,t=-t):o=0,0===t)return new T(u=o,h=0);if(t===1/0)return new T(u=2146435072|o,h=0);if(t!=t)return new T(u=2146959360,h=0);if(r=0,h=0,(e=S(t))>1)if(e<=E)(r=S($(e)))<=20?(h=0,u=e<<20-r&1048575):(h=e%(n=M(2,i=r-20))<<32-i,u=e/n&1048575);else for(i=e,h=0;0!==(i=S(n=i/2));)r++,h>>>=1,h|=(1&u)<<31,u>>>=1,n!==i&&(u|=524288);if(a=r+1023,s=0===e,e=t-e,r<52&&0!==e)for(i=0;;){if((n=2*e)>=1?(e=n-1,s?(a--,s=!1):(i<<=1,i|=1,r++)):(e=n,s?0==--a&&(r++,s=!1):(i<<=1,r++)),20===r)u|=i,i=0;else if(52===r){h|=i;break}if(1===n){r<20?u|=i<<20-r:r<52&&(h|=i<<52-r);break}}return u|=a<<20,new T(u|=o,h)},z.longBitsToDouble=function(t){var e,n,i,r,s=t.high,o=t.low,a=s&1<<31?-1:1;for(i=((2146435072&s)>>20)-1023,r=0,n=1<<19,e=1;e<=20;e++)s&n&&(r+=M(2,-e)),n>>>=1;for(n=1<<31,e=21;e<=52;e++)o&n&&(r+=M(2,-e)),n>>>=1;if(-1023===i){if(0===r)return 0*a;i=-1022}else{if(1024===i)return 0===r?a/0:NaN;r+=1}return a*r*M(2,i)});var F=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({RuntimeException:i})[0],r}return h(i,t),s(i)}(w),P=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,null,[{key:"constructor_",value:function(){if(0===arguments.length)F.constructor_.call(this);else if(1===arguments.length){var t=arguments[0];F.constructor_.call(this,t)}}}])}(F),D=function(){function t(){n(this,t)}return s(t,null,[{key:"shouldNeverReachHere",value:function(){if(0===arguments.length)t.shouldNeverReachHere(null);else if(1===arguments.length){var e=arguments[0];throw new P("Should never reach here"+(null!==e?": "+e:""))}}},{key:"isTrue",value:function(){if(1===arguments.length){var e=arguments[0];t.isTrue(e,null)}else if(2===arguments.length){var n=arguments[1];if(!arguments[0])throw null===n?new P:new P(n)}}},{key:"equals",value:function(){if(2===arguments.length){var e=arguments[0],n=arguments[1];t.equals(e,n,null)}else if(3===arguments.length){var i=arguments[0],r=arguments[1],s=arguments[2];if(!r.equals(i))throw new P("Expected "+i+" but encountered "+r+(null!==s?": "+s:""))}}}])}(),N=new ArrayBuffer(8),U=new Float64Array(N),q=new Int32Array(N),j=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getM",value:function(){return z.NaN}},{key:"setOrdinate",value:function(e,n){switch(e){case t.X:this.x=n;break;case t.Y:this.y=n;break;case t.Z:this.setZ(n);break;default:throw new g("Invalid ordinate index: "+e)}}},{key:"equals2D",value:function(){if(1===arguments.length){var t=arguments[0];return this.x===t.x&&this.y===t.y}if(2===arguments.length){var e=arguments[0],n=arguments[1];return!!I.equalsWithTolerance(this.x,e.x,n)&&!!I.equalsWithTolerance(this.y,e.y,n)}}},{key:"setM",value:function(e){throw new g("Invalid ordinate index: "+t.M)}},{key:"getZ",value:function(){return this.z}},{key:"getOrdinate",value:function(e){switch(e){case t.X:return this.x;case t.Y:return this.y;case t.Z:return this.getZ()}throw new g("Invalid ordinate index: "+e)}},{key:"equals3D",value:function(t){return this.x===t.x&&this.y===t.y&&(this.getZ()===t.getZ()||z.isNaN(this.getZ())&&z.isNaN(t.getZ()))}},{key:"equals",value:function(e){return e instanceof t&&this.equals2D(e)}},{key:"equalInZ",value:function(t,e){return I.equalsWithTolerance(this.getZ(),t.getZ(),e)}},{key:"setX",value:function(t){this.x=t}},{key:"compareTo",value:function(t){var e=t;return this.x<e.x?-1:this.x>e.x?1:this.y<e.y?-1:this.y>e.y?1:0}},{key:"getX",value:function(){return this.x}},{key:"setZ",value:function(t){this.z=t}},{key:"clone",value:function(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return D.shouldNeverReachHere("this shouldn't happen because this class is Cloneable"),null;throw t}}},{key:"copy",value:function(){return new t(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+")"}},{key:"distance3D",value:function(t){var e=this.x-t.x,n=this.y-t.y,i=this.getZ()-t.getZ();return Math.sqrt(e*e+n*n+i*i)}},{key:"getY",value:function(){return this.y}},{key:"setY",value:function(t){this.y=t}},{key:"distance",value:function(t){var e=this.x-t.x,n=this.y-t.y;return Math.sqrt(e*e+n*n)}},{key:"hashCode",value:function(){var e=17;return 37*(e=37*e+t.hashCode(this.x))+t.hashCode(this.y)}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}},{key:"interfaces_",get:function(){return[_,x,k]}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.z=null,0===arguments.length)t.constructor_.call(this,0,0);else if(1===arguments.length){var e=arguments[0];t.constructor_.call(this,e.x,e.y,e.getZ())}else if(2===arguments.length){var n=arguments[0],i=arguments[1];t.constructor_.call(this,n,i,t.NULL_ORDINATE)}else if(3===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2];this.x=r,this.y=s,this.z=o}}},{key:"hashCode",value:function(t){return U[0]=t,q[0]^q[1]}}])}(),B=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"compare",value:function(e,n){var i=t.compare(e.x,n.x);if(0!==i)return i;var r=t.compare(e.y,n.y);return 0!==r?r:this.Ko<=2?0:t.compare(e.getZ(),n.getZ())}},{key:"interfaces_",get:function(){return[R]}}],[{key:"constructor_",value:function(){if(this.Ko=2,0===arguments.length)t.constructor_.call(this,2);else if(1===arguments.length){var e=arguments[0];if(2!==e&&3!==e)throw new g("only 2 or 3 dimensions may be specified");this.Ko=e}}},{key:"compare",value:function(t,e){return t<e?-1:t>e?1:z.isNaN(t)?z.isNaN(e)?0:-1:z.isNaN(e)?1:0}}])}();j.DimensionalComparator=B,j.NULL_ORDINATE=z.NaN,j.X=0,j.Y=1,j.Z=2,j.M=3;var L=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getArea",value:function(){return this.getWidth()*this.getHeight()}},{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this.isNull()?n.isNull():this.Xo===n.getMaxX()&&this.Qo===n.getMaxY()&&this.Zo===n.getMinX()&&this.Jo===n.getMinY()}},{key:"intersection",value:function(e){if(this.isNull()||e.isNull()||!this.intersects(e))return new t;var n=this.Zo>e.Zo?this.Zo:e.Zo,i=this.Jo>e.Jo?this.Jo:e.Jo;return new t(n,this.Xo<e.Xo?this.Xo:e.Xo,i,this.Qo<e.Qo?this.Qo:e.Qo)}},{key:"isNull",value:function(){return this.Xo<this.Zo}},{key:"getMaxX",value:function(){return this.Xo}},{key:"covers",value:function(){if(1===arguments.length){if(arguments[0]instanceof j){var e=arguments[0];return this.covers(e.x,e.y)}if(arguments[0]instanceof t){var n=arguments[0];return!this.isNull()&&!n.isNull()&&n.getMinX()>=this.Zo&&n.getMaxX()<=this.Xo&&n.getMinY()>=this.Jo&&n.getMaxY()<=this.Qo}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];return!this.isNull()&&i>=this.Zo&&i<=this.Xo&&r>=this.Jo&&r<=this.Qo}}},{key:"intersects",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return!this.isNull()&&!e.isNull()&&!(e.Zo>this.Xo||e.Xo<this.Zo||e.Jo>this.Qo||e.Qo<this.Jo)}if(arguments[0]instanceof j){var n=arguments[0];return this.intersects(n.x,n.y)}}else if(2===arguments.length){if(arguments[0]instanceof j&&arguments[1]instanceof j){var i=arguments[0],r=arguments[1];return!(this.isNull()||(i.x<r.x?i.x:r.x)>this.Xo||(i.x>r.x?i.x:r.x)<this.Zo||(i.y<r.y?i.y:r.y)>this.Qo||(i.y>r.y?i.y:r.y)<this.Jo)}if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var s=arguments[0],o=arguments[1];return!this.isNull()&&!(s>this.Xo||s<this.Zo||o>this.Qo||o<this.Jo)}}}},{key:"getMinY",value:function(){return this.Jo}},{key:"getDiameter",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return Math.sqrt(t*t+e*e)}},{key:"getMinX",value:function(){return this.Zo}},{key:"expandToInclude",value:function(){if(1===arguments.length){if(arguments[0]instanceof j){var e=arguments[0];this.expandToInclude(e.x,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];if(n.isNull())return null;this.isNull()?(this.Zo=n.getMinX(),this.Xo=n.getMaxX(),this.Jo=n.getMinY(),this.Qo=n.getMaxY()):(n.Zo<this.Zo&&(this.Zo=n.Zo),n.Xo>this.Xo&&(this.Xo=n.Xo),n.Jo<this.Jo&&(this.Jo=n.Jo),n.Qo>this.Qo&&(this.Qo=n.Qo))}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.isNull()?(this.Zo=i,this.Xo=i,this.Jo=r,this.Qo=r):(i<this.Zo&&(this.Zo=i),i>this.Xo&&(this.Xo=i),r<this.Jo&&(this.Jo=r),r>this.Qo&&(this.Qo=r))}}},{key:"minExtent",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return t<e?t:e}},{key:"getWidth",value:function(){return this.isNull()?0:this.Xo-this.Zo}},{key:"compareTo",value:function(t){var e=t;return this.isNull()?e.isNull()?0:-1:e.isNull()?1:this.Zo<e.Zo?-1:this.Zo>e.Zo?1:this.Jo<e.Jo?-1:this.Jo>e.Jo?1:this.Xo<e.Xo?-1:this.Xo>e.Xo?1:this.Qo<e.Qo?-1:this.Qo>e.Qo?1:0}},{key:"translate",value:function(t,e){if(this.isNull())return null;this.init(this.getMinX()+t,this.getMaxX()+t,this.getMinY()+e,this.getMaxY()+e)}},{key:"copy",value:function(){return new t(this)}},{key:"toString",value:function(){return"Env["+this.Zo+" : "+this.Xo+", "+this.Jo+" : "+this.Qo+"]"}},{key:"setToNull",value:function(){this.Zo=0,this.Xo=-1,this.Jo=0,this.Qo=-1}},{key:"disjoint",value:function(t){return!(!this.isNull()&&!t.isNull())||t.Zo>this.Xo||t.Xo<this.Zo||t.Jo>this.Qo||t.Qo<this.Jo}},{key:"getHeight",value:function(){return this.isNull()?0:this.Qo-this.Jo}},{key:"maxExtent",value:function(){if(this.isNull())return 0;var t=this.getWidth(),e=this.getHeight();return t>e?t:e}},{key:"expandBy",value:function(){if(1===arguments.length){var t=arguments[0];this.expandBy(t,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];if(this.isNull())return null;this.Zo-=e,this.Xo+=e,this.Jo-=n,this.Qo+=n,(this.Zo>this.Xo||this.Jo>this.Qo)&&this.setToNull()}}},{key:"contains",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.covers(e)}if(arguments[0]instanceof j){var n=arguments[0];return this.covers(n)}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];return this.covers(i,r)}}},{key:"centre",value:function(){return this.isNull()?null:new j((this.getMinX()+this.getMaxX())/2,(this.getMinY()+this.getMaxY())/2)}},{key:"init",value:function(){if(0===arguments.length)this.setToNull();else if(1===arguments.length){if(arguments[0]instanceof j){var e=arguments[0];this.init(e.x,e.x,e.y,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];this.Zo=n.Zo,this.Xo=n.Xo,this.Jo=n.Jo,this.Qo=n.Qo}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.init(i.x,r.x,i.y,r.y)}else if(4===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2],u=arguments[3];s<o?(this.Zo=s,this.Xo=o):(this.Zo=o,this.Xo=s),a<u?(this.Jo=a,this.Qo=u):(this.Jo=u,this.Qo=a)}}},{key:"getMaxY",value:function(){return this.Qo}},{key:"distance",value:function(t){if(this.intersects(t))return 0;var e=0;this.Xo<t.Zo?e=t.Zo-this.Xo:this.Zo>t.Xo&&(e=this.Zo-t.Xo);var n=0;return this.Qo<t.Jo?n=t.Jo-this.Qo:this.Jo>t.Qo&&(n=this.Jo-t.Qo),0===e?n:0===n?e:Math.sqrt(e*e+n*n)}},{key:"hashCode",value:function(){var t=17;return 37*(t=37*(t=37*(t=37*t+j.hashCode(this.Zo))+j.hashCode(this.Xo))+j.hashCode(this.Jo))+j.hashCode(this.Qo)}},{key:"interfaces_",get:function(){return[_,k]}}],[{key:"constructor_",value:function(){if(this.Zo=null,this.Xo=null,this.Jo=null,this.Qo=null,0===arguments.length)this.init();else if(1===arguments.length){if(arguments[0]instanceof j){var e=arguments[0];this.init(e.x,e.x,e.y,e.y)}else if(arguments[0]instanceof t){var n=arguments[0];this.init(n)}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.init(i.x,r.x,i.y,r.y)}else if(4===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2],u=arguments[3];this.init(s,o,a,u)}}},{key:"intersects",value:function(){if(3===arguments.length){var t=arguments[0],e=arguments[1],n=arguments[2];return n.x>=(t.x<e.x?t.x:e.x)&&n.x<=(t.x>e.x?t.x:e.x)&&n.y>=(t.y<e.y?t.y:e.y)&&n.y<=(t.y>e.y?t.y:e.y)}if(4===arguments.length){var i=arguments[0],r=arguments[1],s=arguments[2],o=arguments[3],a=Math.min(s.x,o.x),u=Math.max(s.x,o.x),h=Math.min(i.x,r.x),l=Math.max(i.x,r.x);return!(h>u||l<a||(a=Math.min(s.y,o.y),u=Math.max(s.y,o.y),h=Math.min(i.y,r.y),l=Math.max(i.y,r.y),h>u||l<a))}}}])}(),H=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"isGeometryCollection",value:function(){return this.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION}},{key:"getFactory",value:function(){return this._a}},{key:"getGeometryN",value:function(t){return this}},{key:"getArea",value:function(){return 0}},{key:"isRectangle",value:function(){return!1}},{key:"equalsExact",value:function(t){return this===t||this.equalsExact(t,0)}},{key:"geometryChanged",value:function(){this.apply(t.geometryChangedFilter)}},{key:"geometryChangedAction",value:function(){this.tu=null}},{key:"equalsNorm",value:function(t){return null!==t&&this.norm().equalsExact(t.norm())}},{key:"getLength",value:function(){return 0}},{key:"getNumGeometries",value:function(){return 1}},{key:"compareTo",value:function(){var t;if(1===arguments.length){var e=arguments[0];return t=e,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(e)}if(2===arguments.length){var n=arguments[0],i=arguments[1];return t=n,this.getTypeCode()!==t.getTypeCode()?this.getTypeCode()-t.getTypeCode():this.isEmpty()&&t.isEmpty()?0:this.isEmpty()?-1:t.isEmpty()?1:this.compareToSameClass(n,i)}}},{key:"getUserData",value:function(){return this.eu}},{key:"getSRID",value:function(){return this.nu}},{key:"getEnvelope",value:function(){return this.getFactory().toGeometry(this.getEnvelopeInternal())}},{key:"checkNotGeometryCollection",value:function(e){if(e.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION)throw new g("This method does not support GeometryCollection arguments")}},{key:"equal",value:function(t,e,n){return 0===n?t.equals(e):t.distance(e)<=n}},{key:"norm",value:function(){var t=this.copy();return t.normalize(),t}},{key:"reverse",value:function(){var t=this.reverseInternal();return null!=this.envelope&&(t.envelope=this.envelope.copy()),t.setSRID(this.getSRID()),t}},{key:"copy",value:function(){var t=this.copyInternal();return t.envelope=null==this.tu?null:this.tu.copy(),t.nu=this.nu,t.eu=this.eu,t}},{key:"getPrecisionModel",value:function(){return this._a.getPrecisionModel()}},{key:"getEnvelopeInternal",value:function(){return null===this.tu&&(this.tu=this.computeEnvelopeInternal()),new L(this.tu)}},{key:"setSRID",value:function(t){this.nu=t}},{key:"setUserData",value:function(t){this.eu=t}},{key:"compare",value:function(t,e){for(var n=t.iterator(),i=e.iterator();n.hasNext()&&i.hasNext();){var r=n.next(),s=i.next(),o=r.compareTo(s);if(0!==o)return o}return n.hasNext()?1:i.hasNext()?-1:0}},{key:"hashCode",value:function(){return this.getEnvelopeInternal().hashCode()}},{key:"isEquivalentClass",value:function(t){return this.getClass()===t.getClass()}},{key:"isGeometryCollectionOrDerived",value:function(){return this.getTypeCode()===t.TYPECODE_GEOMETRYCOLLECTION||this.getTypeCode()===t.TYPECODE_MULTIPOINT||this.getTypeCode()===t.TYPECODE_MULTILINESTRING||this.getTypeCode()===t.TYPECODE_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[x,_,k]}},{key:"getClass",value:function(){return t}}],[{key:"hasNonEmptyElements",value:function(t){for(var e=0;e<t.length;e++)if(!t[e].isEmpty())return!0;return!1}},{key:"hasNullElements",value:function(t){for(var e=0;e<t.length;e++)if(null===t[e])return!0;return!1}}])}();H.constructor_=function(t){t&&(this.tu=null,this.eu=null,this._a=t,this.nu=t.getSRID())},H.TYPECODE_POINT=0,H.TYPECODE_MULTIPOINT=1,H.TYPECODE_LINESTRING=2,H.TYPECODE_LINEARRING=3,H.TYPECODE_MULTILINESTRING=4,H.TYPECODE_POLYGON=5,H.TYPECODE_MULTIPOLYGON=6,H.TYPECODE_GEOMETRYCOLLECTION=7,H.TYPENAME_POINT="Point",H.TYPENAME_MULTIPOINT="MultiPoint",H.TYPENAME_LINESTRING="LineString",H.TYPENAME_LINEARRING="LinearRing",H.TYPENAME_MULTILINESTRING="MultiLineString",H.TYPENAME_POLYGON="Polygon",H.TYPENAME_MULTIPOLYGON="MultiPolygon",H.TYPENAME_GEOMETRYCOLLECTION="GeometryCollection",H.geometryChangedFilter={get interfaces_(){return[b]},filter:function(t){t.geometryChangedAction()}};var W=function(){function t(){n(this,t)}return s(t,null,[{key:"toLocationSymbol",value:function(e){switch(e){case t.EXTERIOR:return"e";case t.BOUNDARY:return"b";case t.INTERIOR:return"i";case t.NONE:return"-"}throw new g("Unknown location value: "+e)}}])}();W.INTERIOR=0,W.BOUNDARY=1,W.EXTERIOR=2,W.NONE=-1;var V=s((function t(){n(this,t)}),[{key:"add",value:function(){}},{key:"addAll",value:function(){}},{key:"isEmpty",value:function(){}},{key:"iterator",value:function(){}},{key:"size",value:function(){}},{key:"toArray",value:function(){}},{key:"remove",value:function(){}}]),G=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({NoSuchElementException:i})[0],r}return h(i,t),s(i)}(w),Y=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({UnsupportedOperationException:i})[0],r}return h(i,t),s(i)}(w),K=function(t){function i(){return n(this,i),e(this,i,arguments)}return h(i,t),s(i,[{key:"contains",value:function(){}}])}(V),X=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).map=new Map,t instanceof V&&r.addAll(t),r}return h(i,t),s(i,[{key:"contains",value:function(t){var e=t.hashCode?t.hashCode():t;return!!this.map.has(e)}},{key:"add",value:function(t){var e=t.hashCode?t.hashCode():t;return!this.map.has(e)&&!!this.map.set(e,t)}},{key:"addAll",value:function(t){var e,n=o(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.add(i)}}catch(t){n.e(t)}finally{n.f()}return!0}},{key:"remove",value:function(){throw new Y}},{key:"size",value:function(){return this.map.size}},{key:"isEmpty",value:function(){return 0===this.map.size}},{key:"toArray",value:function(){return Array.from(this.map.values())}},{key:"iterator",value:function(){return new Q(this.map)}},{key:Symbol.iterator,value:function(){return this.map}}])}(K),Q=s((function t(e){n(this,t),this.iterator=e.values();var i=this.iterator.next(),r=i.done,s=i.value;this.done=r,this.value=s}),[{key:"next",value:function(){if(this.done)throw new G;var t=this.value,e=this.iterator.next(),n=e.done,i=e.value;return this.done=n,this.value=i,t}},{key:"hasNext",value:function(){return!this.done}},{key:"remove",value:function(){throw new Y}}]),Z=function(){function t(){n(this,t)}return s(t,null,[{key:"opposite",value:function(e){return e===t.LEFT?t.RIGHT:e===t.RIGHT?t.LEFT:e}}])}();Z.ON=0,Z.LEFT=1,Z.RIGHT=2;var J=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({EmptyStackException:i})[0],r}return h(i,t),s(i)}(w),tt=function(t){function i(t){var r;return n(this,i),(r=e(this,i,[t])).name=Object.keys({IndexOutOfBoundsException:i})[0],r}return h(i,t),s(i)}(w),et=function(t){function i(){return n(this,i),e(this,i,arguments)}return h(i,t),s(i,[{key:"get",value:function(){}},{key:"set",value:function(){}},{key:"isEmpty",value:function(){}}])}(V),nt=function(t){function i(){var t;return n(this,i),(t=e(this,i)).array=[],t}return h(i,t),s(i,[{key:"add",value:function(t){return this.array.push(t),!0}},{key:"get",value:function(t){if(t<0||t>=this.size())throw new tt;return this.array[t]}},{key:"push",value:function(t){return this.array.push(t),t}},{key:"pop",value:function(){if(0===this.array.length)throw new J;return this.array.pop()}},{key:"peek",value:function(){if(0===this.array.length)throw new J;return this.array[this.array.length-1]}},{key:"empty",value:function(){return 0===this.array.length}},{key:"isEmpty",value:function(){return this.empty()}},{key:"search",value:function(t){return this.array.indexOf(t)}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}}])}(et);function it(t,e){return t.interfaces_&&t.interfaces_.indexOf(e)>-1}var rt=s((function t(e){n(this,t),this.str=e}),[{key:"append",value:function(t){this.str+=t}},{key:"setCharAt",value:function(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}},{key:"toString",value:function(){return this.str}}]),st=function(){function t(e){n(this,t),this.value=e}return s(t,[{key:"intValue",value:function(){return this.value}},{key:"compareTo",value:function(t){return this.value<t?-1:this.value>t?1:0}}],[{key:"compare",value:function(t,e){return t<e?-1:t>e?1:0}},{key:"isNan",value:function(t){return Number.isNaN(t)}},{key:"valueOf",value:function(e){return new t(e)}}])}(),ot=s((function t(){n(this,t)}),null,[{key:"isWhitespace",value:function(t){return t<=32&&t>=0||127===t}},{key:"toUpperCase",value:function(t){return t.toUpperCase()}}]),at=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"le",value:function(t){return this.iu<t.iu||this.iu===t.iu&&this.ru<=t.ru}},{key:"extractSignificantDigits",value:function(e,n){var i=this.abs(),r=t.magnitude(i.iu),s=t.TEN.pow(r);(i=i.divide(s)).gt(t.TEN)?(i=i.divide(t.TEN),r+=1):i.lt(t.ONE)&&(i=i.multiply(t.TEN),r-=1);for(var o=r+1,a=new rt,u=t.MAX_PRINT_DIGITS-1,h=0;h<=u;h++){e&&h===o&&a.append(".");var l=Math.trunc(i.iu);if(l<0)break;var c=!1,f=0;l>9?(c=!0,f="9"):f="0"+l,a.append(f),i=i.subtract(t.valueOf(l)).multiply(t.TEN),c&&i.selfAdd(t.TEN);var d=!0,p=t.magnitude(i.iu);if(p<0&&Math.abs(p)>=u-h&&(d=!1),!d)break}return n[0]=r,a.toString()}},{key:"sqr",value:function(){return this.multiply(this)}},{key:"doubleValue",value:function(){return this.iu+this.ru}},{key:"subtract",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.add(e.negate())}if("number"==typeof arguments[0]){var n=arguments[0];return this.add(-n)}}},{key:"equals",value:function(){if(1===arguments.length&&arguments[0]instanceof t){var e=arguments[0];return this.iu===e.iu&&this.ru===e.ru}}},{key:"isZero",value:function(){return 0===this.iu&&0===this.ru}},{key:"selfSubtract",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.isNaN()?this:this.selfAdd(-e.iu,-e.ru)}if("number"==typeof arguments[0]){var n=arguments[0];return this.isNaN()?this:this.selfAdd(-n,0)}}},{key:"getSpecialNumberString",value:function(){return this.isZero()?"0.0":this.isNaN()?"NaN ":null}},{key:"min",value:function(t){return this.le(t)?this:t}},{key:"selfDivide",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfDivide(e.iu,e.ru)}if("number"==typeof arguments[0]){var n=arguments[0];return this.selfDivide(n,0)}}else if(2===arguments.length){var i,r,s,o,a=arguments[0],u=arguments[1],h=null,l=null,c=null,f=null;return s=this.iu/a,f=(h=(c=t.SPLIT*s)-(h=c-s))*(l=(f=t.SPLIT*a)-(l=f-a))-(o=s*a)+h*(r=a-l)+(i=s-h)*l+i*r,f=s+(c=(this.iu-o-f+this.ru-s*u)/a),this.iu=f,this.ru=s-f+c,this}}},{key:"dump",value:function(){return"DD<"+this.iu+", "+this.ru+">"}},{key:"divide",value:function(){if(arguments[0]instanceof t){var e,n,i,r,s=arguments[0],o=null,a=null,u=null,h=null;return e=(i=this.iu/s.iu)-(o=(u=t.SPLIT*i)-(o=u-i)),h=o*(a=(h=t.SPLIT*s.iu)-(a=h-s.iu))-(r=i*s.iu)+o*(n=s.iu-a)+e*a+e*n,new t(h=i+(u=(this.iu-r-h+this.ru-i*s.ru)/s.iu),i-h+u)}if("number"==typeof arguments[0]){var l=arguments[0];return z.isNaN(l)?t.createNaN():t.copy(this).selfDivide(l,0)}}},{key:"ge",value:function(t){return this.iu>t.iu||this.iu===t.iu&&this.ru>=t.ru}},{key:"pow",value:function(e){if(0===e)return t.valueOf(1);var n=new t(this),i=t.valueOf(1),r=Math.abs(e);if(r>1)for(;r>0;)r%2==1&&i.selfMultiply(n),(r/=2)>0&&(n=n.sqr());else i=n;return e<0?i.reciprocal():i}},{key:"ceil",value:function(){if(this.isNaN())return t.NaN;var e=Math.ceil(this.iu),n=0;return e===this.iu&&(n=Math.ceil(this.ru)),new t(e,n)}},{key:"compareTo",value:function(t){var e=t;return this.iu<e.iu?-1:this.iu>e.iu?1:this.ru<e.ru?-1:this.ru>e.ru?1:0}},{key:"rint",value:function(){return this.isNaN()?this:this.add(.5).floor()}},{key:"setValue",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return this.init(e),this}if("number"==typeof arguments[0]){var n=arguments[0];return this.init(n),this}}},{key:"max",value:function(t){return this.ge(t)?this:t}},{key:"sqrt",value:function(){if(this.isZero())return t.valueOf(0);if(this.isNegative())return t.NaN;var e=1/Math.sqrt(this.iu),n=this.iu*e,i=t.valueOf(n),r=.5*this.subtract(i.sqr()).iu*e;return i.add(r)}},{key:"selfAdd",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfAdd(e.iu,e.ru)}if("number"==typeof arguments[0]){var n,i,r,s,o,a=arguments[0],u=null;return u=(r=this.iu+a)-(s=r-this.iu),i=(o=(u=a-s+(this.iu-u))+this.ru)+(r-(n=r+o)),this.iu=n+i,this.ru=i+(n-this.iu),this}}else if(2===arguments.length){var h,l,c,f,d=arguments[0],p=arguments[1],v=null,m=null,y=null;c=this.iu+d,l=this.ru+p,m=c-(y=c-this.iu),v=l-(f=l-this.ru);var w=(h=c+(y=(m=d-y+(this.iu-m))+l))+(y=(v=p-f+(this.ru-v))+(y+(c-h))),g=y+(h-w);return this.iu=w,this.ru=g,this}}},{key:"selfMultiply",value:function(){if(1===arguments.length){if(arguments[0]instanceof t){var e=arguments[0];return this.selfMultiply(e.iu,e.ru)}if("number"==typeof arguments[0]){var n=arguments[0];return this.selfMultiply(n,0)}}else if(2===arguments.length){var i,r,s=arguments[0],o=arguments[1],a=null,u=null,h=null,l=null;a=(h=t.SPLIT*this.iu)-this.iu,l=t.SPLIT*s,a=h-a,i=this.iu-a,u=l-s;var c=(h=this.iu*s)+(l=a*(u=l-u)-h+a*(r=s-u)+i*u+i*r+this.iu*o+this.ru*s),f=l+(a=h-c);return this.iu=c,this.ru=f,this}}},{key:"selfSqr",value:function(){return this.selfMultiply(this)}},{key:"floor",value:function(){if(this.isNaN())return t.NaN;var e=Math.floor(this.iu),n=0;return e===this.iu&&(n=Math.floor(this.ru)),new t(e,n)}},{key:"negate",value:function(){return this.isNaN()?this:new t(-this.iu,-this.ru)}},{key:"clone",value:function(){try{return null}catch(t){if(t instanceof CloneNotSupportedException)return null;throw t}}},{key:"multiply",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return e.isNaN()?t.createNaN():t.copy(this).selfMultiply(e)}if("number"==typeof arguments[0]){var n=arguments[0];return z.isNaN(n)?t.createNaN():t.copy(this).selfMultiply(n,0)}}},{key:"isNaN",value:function(){return z.isNaN(this.iu)}},{key:"intValue",value:function(){return Math.trunc(this.iu)}},{key:"toString",value:function(){var e=t.magnitude(this.iu);return e>=-3&&e<=20?this.toStandardNotation():this.toSciNotation()}},{key:"toStandardNotation",value:function(){var e=this.getSpecialNumberString();if(null!==e)return e;var n=new Array(1).fill(null),i=this.extractSignificantDigits(!0,n),r=n[0]+1,s=i;if("."===i.charAt(0))s="0"+i;else if(r<0)s="0."+t.stringOfChar("0",-r)+i;else if(-1===i.indexOf(".")){var o=r-i.length;s=i+t.stringOfChar("0",o)+".0"}return this.isNegative()?"-"+s:s}},{key:"reciprocal",value:function(){var e,n,i,r,s=null,o=null,a=null,u=null;e=(i=1/this.iu)-(s=(a=t.SPLIT*i)-(s=a-i)),o=(u=t.SPLIT*this.iu)-this.iu;var h=i+(a=(1-(r=i*this.iu)-(u=s*(o=u-o)-r+s*(n=this.iu-o)+e*o+e*n)-i*this.ru)/this.iu);return new t(h,i-h+a)}},{key:"toSciNotation",value:function(){if(this.isZero())return t.SCI_NOT_ZERO;var e=this.getSpecialNumberString();if(null!==e)return e;var n=new Array(1).fill(null),i=this.extractSignificantDigits(!1,n),r=t.SCI_NOT_EXPONENT_CHAR+n[0];if("0"===i.charAt(0))throw new IllegalStateException("Found leading zero: "+i);var s="";i.length>1&&(s=i.substring(1));var o=i.charAt(0)+"."+s;return this.isNegative()?"-"+o+r:o+r}},{key:"abs",value:function(){return this.isNaN()?t.NaN:this.isNegative()?this.negate():new t(this)}},{key:"isPositive",value:function(){return this.iu>0||0===this.iu&&this.ru>0}},{key:"lt",value:function(t){return this.iu<t.iu||this.iu===t.iu&&this.ru<t.ru}},{key:"add",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return t.copy(this).selfAdd(e)}if("number"==typeof arguments[0]){var n=arguments[0];return t.copy(this).selfAdd(n)}}},{key:"init",value:function(){if(1===arguments.length){if("number"==typeof arguments[0]){var e=arguments[0];this.iu=e,this.ru=0}else if(arguments[0]instanceof t){var n=arguments[0];this.iu=n.iu,this.ru=n.ru}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.iu=i,this.ru=r}}},{key:"gt",value:function(t){return this.iu>t.iu||this.iu===t.iu&&this.ru>t.ru}},{key:"isNegative",value:function(){return this.iu<0||0===this.iu&&this.ru<0}},{key:"trunc",value:function(){return this.isNaN()?t.NaN:this.isPositive()?this.floor():this.ceil()}},{key:"signum",value:function(){return this.iu>0?1:this.iu<0?-1:this.ru>0?1:this.ru<0?-1:0}},{key:"interfaces_",get:function(){return[k,_,x]}}],[{key:"constructor_",value:function(){if(this.iu=0,this.ru=0,0===arguments.length)this.init(0);else if(1===arguments.length){if("number"==typeof arguments[0]){var e=arguments[0];this.init(e)}else if(arguments[0]instanceof t){var n=arguments[0];this.init(n)}else if("string"==typeof arguments[0]){var i=arguments[0];t.constructor_.call(this,t.parse(i))}}else if(2===arguments.length){var r=arguments[0],s=arguments[1];this.init(r,s)}}},{key:"determinant",value:function(){if("number"==typeof arguments[3]&&"number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1],i=arguments[2],r=arguments[3];return t.determinant(t.valueOf(e),t.valueOf(n),t.valueOf(i),t.valueOf(r))}if(arguments[3]instanceof t&&arguments[2]instanceof t&&arguments[0]instanceof t&&arguments[1]instanceof t){var s=arguments[1],o=arguments[2],a=arguments[3];return arguments[0].multiply(a).selfSubtract(s.multiply(o))}}},{key:"sqr",value:function(e){return t.valueOf(e).selfMultiply(e)}},{key:"valueOf",value:function(){if("string"==typeof arguments[0]){var e=arguments[0];return t.parse(e)}if("number"==typeof arguments[0])return new t(arguments[0])}},{key:"sqrt",value:function(e){return t.valueOf(e).sqrt()}},{key:"parse",value:function(e){for(var n=0,i=e.length;ot.isWhitespace(e.charAt(n));)n++;var r=!1;if(n<i){var s=e.charAt(n);"-"!==s&&"+"!==s||(n++,"-"===s&&(r=!0))}for(var o=new t,a=0,u=0,h=0,l=!1;!(n>=i);){var c=e.charAt(n);if(n++,ot.isDigit(c)){var f=c-"0";o.selfMultiply(t.TEN),o.selfAdd(f),a++}else{if("."!==c){if("e"===c||"E"===c){var d=e.substring(n);try{h=st.parseInt(d)}catch(t){throw t instanceof NumberFormatException?new NumberFormatException("Invalid exponent "+d+" in string "+e):t}break}throw new NumberFormatException("Unexpected character '"+c+"' at position "+n+" in string "+e)}u=a,l=!0}}var p=o;l||(u=a);var v=a-u-h;if(0===v)p=o;else if(v>0){var m=t.TEN.pow(v);p=o.divide(m)}else if(v<0){var y=t.TEN.pow(-v);p=o.multiply(y)}return r?p.negate():p}},{key:"createNaN",value:function(){return new t(z.NaN,z.NaN)}},{key:"copy",value:function(e){return new t(e)}},{key:"magnitude",value:function(t){var e=Math.abs(t),n=Math.log(e)/Math.log(10),i=Math.trunc(Math.floor(n));return 10*Math.pow(10,i)<=e&&(i+=1),i}},{key:"stringOfChar",value:function(t,e){for(var n=new rt,i=0;i<e;i++)n.append(t);return n.toString()}}])}();at.PI=new at(3.141592653589793,12246467991473532e-32),at.TWO_PI=new at(6.283185307179586,24492935982947064e-32),at.PI_2=new at(1.5707963267948966,6123233995736766e-32),at.E=new at(2.718281828459045,14456468917292502e-32),at.NaN=new at(z.NaN,z.NaN),at.EPS=123259516440783e-46,at.SPLIT=134217729,at.MAX_PRINT_DIGITS=32,at.TEN=at.valueOf(10),at.ONE=at.valueOf(1),at.SCI_NOT_EXPONENT_CHAR="E",at.SCI_NOT_ZERO="0.0E0";var ut=function(){function t(){n(this,t)}return s(t,null,[{key:"orientationIndex",value:function(e,n,i){var r=t.orientationIndexFilter(e,n,i);if(r<=1)return r;var s=at.valueOf(n.x).selfAdd(-e.x),o=at.valueOf(n.y).selfAdd(-e.y),a=at.valueOf(i.x).selfAdd(-n.x),u=at.valueOf(i.y).selfAdd(-n.y);return s.selfMultiply(u).selfSubtract(o.selfMultiply(a)).signum()}},{key:"signOfDet2x2",value:function(){if(arguments[3]instanceof at&&arguments[2]instanceof at&&arguments[0]instanceof at&&arguments[1]instanceof at){var t=arguments[1],e=arguments[2],n=arguments[3];return arguments[0].multiply(n).selfSubtract(t.multiply(e)).signum()}if("number"==typeof arguments[3]&&"number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var i=arguments[0],r=arguments[1],s=arguments[2],o=arguments[3],a=at.valueOf(i),u=at.valueOf(r),h=at.valueOf(s),l=at.valueOf(o);return a.multiply(l).selfSubtract(u.multiply(h)).signum()}}},{key:"intersection",value:function(t,e,n,i){var r=new at(t.y).selfSubtract(e.y),s=new at(e.x).selfSubtract(t.x),o=new at(t.x).selfMultiply(e.y).selfSubtract(new at(e.x).selfMultiply(t.y)),a=new at(n.y).selfSubtract(i.y),u=new at(i.x).selfSubtract(n.x),h=new at(n.x).selfMultiply(i.y).selfSubtract(new at(i.x).selfMultiply(n.y)),l=s.multiply(h).selfSubtract(u.multiply(o)),c=a.multiply(o).selfSubtract(r.multiply(h)),f=r.multiply(u).selfSubtract(a.multiply(s)),d=l.selfDivide(f).doubleValue(),p=c.selfDivide(f).doubleValue();return z.isNaN(d)||z.isInfinite(d)||z.isNaN(p)||z.isInfinite(p)?null:new j(d,p)}},{key:"orientationIndexFilter",value:function(e,n,i){var r=null,s=(e.x-i.x)*(n.y-i.y),o=(e.y-i.y)*(n.x-i.x),a=s-o;if(s>0){if(o<=0)return t.signum(a);r=s+o}else{if(!(s<0))return t.signum(a);if(o>=0)return t.signum(a);r=-s-o}var u=t.DP_SAFE_EPSILON*r;return a>=u||-a>=u?t.signum(a):2}},{key:"signum",value:function(t){return t>0?1:t<0?-1:0}}])}();ut.DP_SAFE_EPSILON=1e-15;var ht=s((function t(){n(this,t)}),[{key:"getM",value:function(t){if(this.hasM()){var e=this.getDimension()-this.getMeasures();return this.getOrdinate(t,e)}return z.NaN}},{key:"setOrdinate",value:function(t,e,n){}},{key:"getZ",value:function(t){return this.hasZ()?this.getOrdinate(t,2):z.NaN}},{key:"size",value:function(){}},{key:"getOrdinate",value:function(t,e){}},{key:"getCoordinate",value:function(){}},{key:"getCoordinateCopy",value:function(t){}},{key:"createCoordinate",value:function(){}},{key:"getDimension",value:function(){}},{key:"hasM",value:function(){return this.getMeasures()>0}},{key:"getX",value:function(t){}},{key:"hasZ",value:function(){return this.getDimension()-this.getMeasures()>2}},{key:"getMeasures",value:function(){return 0}},{key:"expandEnvelope",value:function(t){}},{key:"copy",value:function(){}},{key:"getY",value:function(t){}},{key:"toCoordinateArray",value:function(){}},{key:"interfaces_",get:function(){return[x]}}]);ht.X=0,ht.Y=1,ht.Z=2,ht.M=3;var lt=function(){function t(){n(this,t)}return s(t,null,[{key:"index",value:function(t,e,n){return ut.orientationIndex(t,e,n)}},{key:"isCCW",value:function(){if(arguments[0]instanceof Array){var e=arguments[0],n=e.length-1;if(n<3)throw new g("Ring has fewer than 4 points, so orientation cannot be determined");for(var i=e[0],r=0,s=1;s<=n;s++){var o=e[s];o.y>i.y&&(i=o,r=s)}var a=r;do{(a-=1)<0&&(a=n)}while(e[a].equals2D(i)&&a!==r);var u=r;do{u=(u+1)%n}while(e[u].equals2D(i)&&u!==r);var h=e[a],l=e[u];if(h.equals2D(i)||l.equals2D(i)||h.equals2D(l))return!1;var c=t.index(h,i,l);return 0===c?h.x>l.x:c>0}if(it(arguments[0],ht)){var f=arguments[0],d=f.size()-1;if(d<3)throw new g("Ring has fewer than 4 points, so orientation cannot be determined");for(var p=f.getCoordinate(0),v=0,m=1;m<=d;m++){var y=f.getCoordinate(m);y.y>p.y&&(p=y,v=m)}var w=null,b=v;do{(b-=1)<0&&(b=d),w=f.getCoordinate(b)}while(w.equals2D(p)&&b!==v);var _=null,x=v;do{x=(x+1)%d,_=f.getCoordinate(x)}while(_.equals2D(p)&&x!==v);if(w.equals2D(p)||_.equals2D(p)||w.equals2D(_))return!1;var k=t.index(w,p,_);return 0===k?w.x>_.x:k>0}}}])}();lt.CLOCKWISE=-1,lt.RIGHT=lt.CLOCKWISE,lt.COUNTERCLOCKWISE=1,lt.LEFT=lt.COUNTERCLOCKWISE,lt.COLLINEAR=0,lt.STRAIGHT=lt.COLLINEAR;var ct=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this.su}},{key:"getRightmostSide",value:function(t,e){var n=this.getRightmostSideOfSegment(t,e);return n<0&&(n=this.getRightmostSideOfSegment(t,e-1)),n<0&&(this.su=null,this.checkForRightmostCoordinate(t)),n}},{key:"findRightmostEdgeAtVertex",value:function(){var t=this.ou.getEdge().getCoordinates();D.isTrue(this.au>0&&this.au<t.length,"rightmost point expected to be interior vertex of edge");var e=t[this.au-1],n=t[this.au+1],i=lt.index(this.su,n,e),r=!1;(e.y<this.su.y&&n.y<this.su.y&&i===lt.COUNTERCLOCKWISE||e.y>this.su.y&&n.y>this.su.y&&i===lt.CLOCKWISE)&&(r=!0),r&&(this.au=this.au-1)}},{key:"getRightmostSideOfSegment",value:function(t,e){var n=t.getEdge().getCoordinates();if(e<0||e+1>=n.length)return-1;if(n[e].y===n[e+1].y)return-1;var i=Z.LEFT;return n[e].y<n[e+1].y&&(i=Z.RIGHT),i}},{key:"getEdge",value:function(){return this.uu}},{key:"checkForRightmostCoordinate",value:function(t){for(var e=t.getEdge().getCoordinates(),n=0;n<e.length-1;n++)(null===this.su||e[n].x>this.su.x)&&(this.ou=t,this.au=n,this.su=e[n])}},{key:"findRightmostEdgeAtNode",value:function(){var t=this.ou.getNode().getEdges();this.ou=t.getRightmostEdge(),this.ou.isForward()||(this.ou=this.ou.getSym(),this.au=this.ou.getEdge().getCoordinates().length-1)}},{key:"findEdge",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next();n.isForward()&&this.checkForRightmostCoordinate(n)}D.isTrue(0!==this.au||this.su.equals(this.ou.getCoordinate()),"inconsistency in rightmost processing"),0===this.au?this.findRightmostEdgeAtNode():this.findRightmostEdgeAtVertex(),this.uu=this.ou,this.getRightmostSide(this.ou,this.au)===Z.LEFT&&(this.uu=this.ou.getSym())}}],[{key:"constructor_",value:function(){this.au=-1,this.su=null,this.ou=null,this.uu=null}}]),ft=function(t){function i(t,r){var s;return n(this,i),(s=e(this,i,[r?t+" [ "+r+" ]":t])).pt=r?new j(r):void 0,s.name=Object.keys({TopologyException:i})[0],s}return h(i,t),s(i,[{key:"getCoordinate",value:function(){return this.pt}}])}(F),dt=s((function t(){n(this,t),this.array=[]}),[{key:"addLast",value:function(t){this.array.push(t)}},{key:"removeFirst",value:function(){return this.array.shift()}},{key:"isEmpty",value:function(){return 0===this.array.length}}]),pt=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).array=[],t instanceof V&&r.addAll(t),r}return h(i,t),s(i,[{key:"interfaces_",get:function(){return[et,V]}},{key:"ensureCapacity",value:function(){}},{key:"add",value:function(t){return 1===arguments.length?this.array.push(t):this.array.splice(arguments[0],0,arguments[1]),!0}},{key:"clear",value:function(){this.array=[]}},{key:"addAll",value:function(t){var e,n=o(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.array.push(i)}}catch(t){n.e(t)}finally{n.f()}}},{key:"set",value:function(t,e){var n=this.array[t];return this.array[t]=e,n}},{key:"iterator",value:function(){return new vt(this)}},{key:"get",value:function(t){if(t<0||t>=this.size())throw new tt;return this.array[t]}},{key:"isEmpty",value:function(){return 0===this.array.length}},{key:"sort",value:function(t){t?this.array.sort((function(e,n){return t.compare(e,n)})):this.array.sort()}},{key:"size",value:function(){return this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"remove",value:function(t){for(var e=0,n=this.array.length;e<n;e++)if(this.array[e]===t)return!!this.array.splice(e,1);return!1}},{key:Symbol.iterator,value:function(){return this.array.values()}}])}(et),vt=s((function t(e){n(this,t),this.arrayList=e,this.position=0}),[{key:"next",value:function(){if(this.position===this.arrayList.size())throw new G;return this.arrayList.get(this.position++)}},{key:"hasNext",value:function(){return this.position<this.arrayList.size()}},{key:"set",value:function(t){return this.arrayList.set(this.position-1,t)}},{key:"remove",value:function(){this.arrayList.remove(this.arrayList.get(this.position))}}]),mt=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"clearVisitedEdges",value:function(){for(var t=this.hu.iterator();t.hasNext();)t.next().setVisited(!1)}},{key:"getRightmostCoordinate",value:function(){return this.lu}},{key:"computeNodeDepth",value:function(t){for(var e=null,n=t.getEdges().iterator();n.hasNext();){var i=n.next();if(i.isVisited()||i.getSym().isVisited()){e=i;break}}if(null===e)throw new ft("unable to find edge to compute depths at "+t.getCoordinate());t.getEdges().computeDepths(e);for(var r=t.getEdges().iterator();r.hasNext();){var s=r.next();s.setVisited(!0),this.copySymDepths(s)}}},{key:"computeDepth",value:function(t){this.clearVisitedEdges();var e=this.cu.getEdge();e.getNode(),e.getLabel(),e.setEdgeDepths(Z.RIGHT,t),this.copySymDepths(e),this.computeDepths(e)}},{key:"create",value:function(t){this.addReachable(t),this.cu.findEdge(this.hu),this.lu=this.cu.getCoordinate()}},{key:"findResultEdges",value:function(){for(var t=this.hu.iterator();t.hasNext();){var e=t.next();e.getDepth(Z.RIGHT)>=1&&e.getDepth(Z.LEFT)<=0&&!e.isInteriorAreaEdge()&&e.setInResult(!0)}}},{key:"computeDepths",value:function(t){var e=new X,n=new dt,i=t.getNode();for(n.addLast(i),e.add(i),t.setVisited(!0);!n.isEmpty();){var r=n.removeFirst();e.add(r),this.computeNodeDepth(r);for(var s=r.getEdges().iterator();s.hasNext();){var o=s.next().getSym();if(!o.isVisited()){var a=o.getNode();e.contains(a)||(n.addLast(a),e.add(a))}}}}},{key:"compareTo",value:function(t){var e=t;return this.lu.x<e.lu.x?-1:this.lu.x>e.lu.x?1:0}},{key:"getEnvelope",value:function(){if(null===this.fu){for(var t=new L,e=this.hu.iterator();e.hasNext();)for(var n=e.next().getEdge().getCoordinates(),i=0;i<n.length-1;i++)t.expandToInclude(n[i]);this.fu=t}return this.fu}},{key:"addReachable",value:function(t){var e=new nt;for(e.add(t);!e.empty();){var n=e.pop();this.add(n,e)}}},{key:"copySymDepths",value:function(t){var e=t.getSym();e.setDepth(Z.LEFT,t.getDepth(Z.RIGHT)),e.setDepth(Z.RIGHT,t.getDepth(Z.LEFT))}},{key:"add",value:function(t,e){t.setVisited(!0),this.du.add(t);for(var n=t.getEdges().iterator();n.hasNext();){var i=n.next();this.hu.add(i);var r=i.getSym().getNode();r.isVisited()||e.push(r)}}},{key:"getNodes",value:function(){return this.du}},{key:"getDirectedEdges",value:function(){return this.hu}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.cu=null,this.hu=new pt,this.du=new pt,this.lu=null,this.fu=null,this.cu=new ct}}]),yt=s((function t(){n(this,t)}),null,[{key:"intersection",value:function(t,e,n,i){var r=t.x<e.x?t.x:e.x,s=t.y<e.y?t.y:e.y,o=t.x>e.x?t.x:e.x,a=t.y>e.y?t.y:e.y,u=n.x<i.x?n.x:i.x,h=n.y<i.y?n.y:i.y,l=n.x>i.x?n.x:i.x,c=n.y>i.y?n.y:i.y,f=((r>u?r:u)+(o<l?o:l))/2,d=((s>h?s:h)+(a<c?a:c))/2,p=t.x-f,v=t.y-d,m=e.x-f,y=e.y-d,w=n.x-f,g=n.y-d,b=i.x-f,_=i.y-d,x=v-y,k=m-p,$=p*y-m*v,S=g-_,M=b-w,E=w*_-b*g,C=x*M-S*k,A=(k*E-M*$)/C,O=(S*$-x*E)/C;return z.isNaN(A)||z.isInfinite(A)||z.isNaN(O)||z.isInfinite(O)?null:new j(A+f,O+d)}}]),wt=s((function t(){n(this,t)}),null,[{key:"arraycopy",value:function(t,e,n,i,r){for(var s=0,o=e;o<e+r;o++)n[i+s]=t[o],s++}},{key:"getProperty",value:function(t){return{"line.separator":"\n"}[t]}}]),gt=function(){function t(){n(this,t)}return s(t,null,[{key:"log10",value:function(e){var n=Math.log(e);return z.isInfinite(n)||z.isNaN(n)?n:n/t.LOG_10}},{key:"min",value:function(t,e,n,i){var r=t;return e<r&&(r=e),n<r&&(r=n),i<r&&(r=i),r}},{key:"clamp",value:function(){if("number"==typeof arguments[2]&&"number"==typeof arguments[0]&&"number"==typeof arguments[1]){var t=arguments[0],e=arguments[1],n=arguments[2];return t<e?e:t>n?n:t}if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var i=arguments[0],r=arguments[1],s=arguments[2];return i<r?r:i>s?s:i}}},{key:"wrap",value:function(t,e){return t<0?e- -t%e:t%e}},{key:"max",value:function(){if(3===arguments.length){var t=arguments[1],e=arguments[2],n=arguments[0];return t>n&&(n=t),e>n&&(n=e),n}if(4===arguments.length){var i=arguments[1],r=arguments[2],s=arguments[3],o=arguments[0];return i>o&&(o=i),r>o&&(o=r),s>o&&(o=s),o}}},{key:"average",value:function(t,e){return(t+e)/2}}])}();gt.LOG_10=Math.log(10);var bt=function(){function t(){n(this,t)}return s(t,null,[{key:"segmentToSegment",value:function(e,n,i,r){if(e.equals(n))return t.pointToSegment(e,i,r);if(i.equals(r))return t.pointToSegment(r,e,n);var s=!1;if(L.intersects(e,n,i,r)){var o=(n.x-e.x)*(r.y-i.y)-(n.y-e.y)*(r.x-i.x);if(0===o)s=!0;else{var a=(e.y-i.y)*(r.x-i.x)-(e.x-i.x)*(r.y-i.y),u=((e.y-i.y)*(n.x-e.x)-(e.x-i.x)*(n.y-e.y))/o,h=a/o;(h<0||h>1||u<0||u>1)&&(s=!0)}}else s=!0;return s?gt.min(t.pointToSegment(e,i,r),t.pointToSegment(n,i,r),t.pointToSegment(i,e,n),t.pointToSegment(r,e,n)):0}},{key:"pointToSegment",value:function(t,e,n){if(e.x===n.x&&e.y===n.y)return t.distance(e);var i=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((t.x-e.x)*(n.x-e.x)+(t.y-e.y)*(n.y-e.y))/i;if(r<=0)return t.distance(e);if(r>=1)return t.distance(n);var s=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/i;return Math.abs(s)*Math.sqrt(i)}},{key:"pointToLinePerpendicular",value:function(t,e,n){var i=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),r=((e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y))/i;return Math.abs(r)*Math.sqrt(i)}},{key:"pointToSegmentString",value:function(e,n){if(0===n.length)throw new g("Line array must contain at least one vertex");for(var i=e.distance(n[0]),r=0;r<n.length-1;r++){var s=t.pointToSegment(e,n[r],n[r+1]);s<i&&(i=s)}return i}}])}(),_t=s((function t(){n(this,t)}),[{key:"create",value:function(){if(1===arguments.length)arguments[0]instanceof Array||it(arguments[0],ht);else if(2===arguments.length);else if(3===arguments.length){var t=arguments[0],e=arguments[1];return this.create(t,e)}}}]),xt=s((function t(){n(this,t)}),[{key:"filter",value:function(t){}}]),kt=s((function t(){n(this,t)}),null,[{key:"ofLine",value:function(t){var e=t.size();if(e<=1)return 0;var n=0,i=new j;t.getCoordinate(0,i);for(var r=i.x,s=i.y,o=1;o<e;o++){t.getCoordinate(o,i);var a=i.x,u=i.y,h=a-r,l=u-s;n+=Math.sqrt(h*h+l*l),r=a,s=u}return n}}]),$t=s((function t(){n(this,t)})),St=function(){function t(){n(this,t)}return s(t,null,[{key:"copyCoord",value:function(t,e,n,i){for(var r=Math.min(t.getDimension(),n.getDimension()),s=0;s<r;s++)n.setOrdinate(i,s,t.getOrdinate(e,s))}},{key:"isRing",value:function(t){var e=t.size();return 0===e||!(e<=3)&&t.getOrdinate(0,ht.X)===t.getOrdinate(e-1,ht.X)&&t.getOrdinate(0,ht.Y)===t.getOrdinate(e-1,ht.Y)}},{key:"scroll",value:function(){if(2===arguments.length){if(it(arguments[0],ht)&&Number.isInteger(arguments[1])){var e=arguments[0],n=arguments[1];t.scroll(e,n,t.isRing(e))}else if(it(arguments[0],ht)&&arguments[1]instanceof j){var i=arguments[0],r=arguments[1],s=t.indexOf(r,i);if(s<=0)return null;t.scroll(i,s)}}else if(3===arguments.length){var o=arguments[0],a=arguments[1],u=arguments[2];if(a<=0)return null;for(var h=o.copy(),l=u?o.size()-1:o.size(),c=0;c<l;c++)for(var f=0;f<o.getDimension();f++)o.setOrdinate(c,f,h.getOrdinate((a+c)%l,f));if(u)for(var d=0;d<o.getDimension();d++)o.setOrdinate(l,d,o.getOrdinate(0,d))}}},{key:"isEqual",value:function(t,e){var n=t.size();if(n!==e.size())return!1;for(var i=Math.min(t.getDimension(),e.getDimension()),r=0;r<n;r++)for(var s=0;s<i;s++){var o=t.getOrdinate(r,s),a=e.getOrdinate(r,s);if(!(t.getOrdinate(r,s)===e.getOrdinate(r,s)||z.isNaN(o)&&z.isNaN(a)))return!1}return!0}},{key:"minCoordinateIndex",value:function(){if(1===arguments.length){var e=arguments[0];return t.minCoordinateIndex(e,0,e.size()-1)}if(3===arguments.length){for(var n=arguments[0],i=arguments[2],r=-1,s=null,o=arguments[1];o<=i;o++){var a=n.getCoordinate(o);(null===s||s.compareTo(a)>0)&&(s=a,r=o)}return r}}},{key:"extend",value:function(e,n,i){var r=e.create(i,n.getDimension()),s=n.size();if(t.copy(n,0,r,0,s),s>0)for(var o=s;o<i;o++)t.copy(n,s-1,r,o,1);return r}},{key:"reverse",value:function(e){for(var n=e.size()-1,i=Math.trunc(n/2),r=0;r<=i;r++)t.swap(e,r,n-r)}},{key:"swap",value:function(t,e,n){if(e===n)return null;for(var i=0;i<t.getDimension();i++){var r=t.getOrdinate(e,i);t.setOrdinate(e,i,t.getOrdinate(n,i)),t.setOrdinate(n,i,r)}}},{key:"copy",value:function(e,n,i,r,s){for(var o=0;o<s;o++)t.copyCoord(e,n+o,i,r+o)}},{key:"ensureValidRing",value:function(e,n){var i=n.size();return 0===i?n:i<=3?t.createClosedRing(e,n,4):n.getOrdinate(0,ht.X)===n.getOrdinate(i-1,ht.X)&&n.getOrdinate(0,ht.Y)===n.getOrdinate(i-1,ht.Y)?n:t.createClosedRing(e,n,i+1)}},{key:"indexOf",value:function(t,e){for(var n=0;n<e.size();n++)if(t.x===e.getOrdinate(n,ht.X)&&t.y===e.getOrdinate(n,ht.Y))return n;return-1}},{key:"createClosedRing",value:function(e,n,i){var r=e.create(i,n.getDimension()),s=n.size();t.copy(n,0,r,0,s);for(var o=s;o<i;o++)t.copy(n,0,r,o,1);return r}},{key:"minCoordinate",value:function(t){for(var e=null,n=0;n<t.size();n++){var i=t.getCoordinate(n);(null===e||e.compareTo(i)>0)&&(e=i)}return e}}])}(),Mt=function(){function t(){n(this,t)}return s(t,null,[{key:"toDimensionSymbol",value:function(e){switch(e){case t.FALSE:return t.SYM_FALSE;case t.TRUE:return t.SYM_TRUE;case t.DONTCARE:return t.SYM_DONTCARE;case t.P:return t.SYM_P;case t.L:return t.SYM_L;case t.A:return t.SYM_A}throw new g("Unknown dimension value: "+e)}},{key:"toDimensionValue",value:function(e){switch(ot.toUpperCase(e)){case t.SYM_FALSE:return t.FALSE;case t.SYM_TRUE:return t.TRUE;case t.SYM_DONTCARE:return t.DONTCARE;case t.SYM_P:return t.P;case t.SYM_L:return t.L;case t.SYM_A:return t.A}throw new g("Unknown dimension symbol: "+e)}}])}();Mt.P=0,Mt.L=1,Mt.A=2,Mt.FALSE=-1,Mt.TRUE=-2,Mt.DONTCARE=-3,Mt.SYM_FALSE="F",Mt.SYM_TRUE="T",Mt.SYM_DONTCARE="*",Mt.SYM_P="0",Mt.SYM_L="1",Mt.SYM_A="2";var Et=s((function t(){n(this,t)}),[{key:"filter",value:function(t){}}]),Ct=s((function t(){n(this,t)}),[{key:"filter",value:function(t,e){}},{key:"isDone",value:function(){}},{key:"isGeometryChanged",value:function(){}}]),At=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"computeEnvelopeInternal",value:function(){return this.isEmpty()?new L:this.Xn.expandEnvelope(new L)}},{key:"isRing",value:function(){return this.isClosed()&&this.isSimple()}},{key:"getCoordinates",value:function(){return this.Xn.toCoordinateArray()}},{key:"copyInternal",value:function(){return new i(this.Xn.copy(),this._a)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t;if(this.Xn.size()!==n.Xn.size())return!1;for(var r=0;r<this.Xn.size();r++)if(!this.equal(this.Xn.getCoordinate(r),n.Xn.getCoordinate(r),e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var t=0;t<Math.trunc(this.Xn.size()/2);t++){var e=this.Xn.size()-1-t;if(!this.Xn.getCoordinate(t).equals(this.Xn.getCoordinate(e))){if(this.Xn.getCoordinate(t).compareTo(this.Xn.getCoordinate(e))>0){var n=this.Xn.copy();St.reverse(n),this.Xn=n}return null}}}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this.Xn.getCoordinate(0)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Mt.FALSE:0}},{key:"isClosed",value:function(){return!this.isEmpty()&&this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints()-1))}},{key:"reverseInternal",value:function(){var t=this.Xn.copy();return St.reverse(t),this.getFactory().createLineString(t)}},{key:"getEndPoint",value:function(){return this.isEmpty()?null:this.getPointN(this.getNumPoints()-1)}},{key:"getTypeCode",value:function(){return H.TYPECODE_LINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getLength",value:function(){return kt.ofLine(this.Xn)}},{key:"getNumPoints",value:function(){return this.Xn.size()}},{key:"compareToSameClass",value:function(){if(1===arguments.length){for(var t=arguments[0],e=0,n=0;e<this.Xn.size()&&n<t.Xn.size();){var i=this.Xn.getCoordinate(e).compareTo(t.Xn.getCoordinate(n));if(0!==i)return i;e++,n++}return e<this.Xn.size()?1:n<t.Xn.size()?-1:0}if(2===arguments.length){var r=arguments[0];return arguments[1].compare(this.Xn,r.Xn)}}},{key:"apply",value:function(){if(it(arguments[0],xt))for(var t=arguments[0],e=0;e<this.Xn.size();e++)t.filter(this.Xn.getCoordinate(e));else if(it(arguments[0],Ct)){var n=arguments[0];if(0===this.Xn.size())return null;for(var i=0;i<this.Xn.size()&&(n.filter(this.Xn,i),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else(it(arguments[0],Et)||it(arguments[0],b))&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){throw new Y}},{key:"isEquivalentClass",value:function(t){return t instanceof i}},{key:"getCoordinateN",value:function(t){return this.Xn.getCoordinate(t)}},{key:"getGeometryType",value:function(){return H.TYPENAME_LINESTRING}},{key:"getCoordinateSequence",value:function(){return this.Xn}},{key:"isEmpty",value:function(){return 0===this.Xn.size()}},{key:"init",value:function(t){if(null===t&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),1===t.size())throw new g("Invalid number of points in LineString (found "+t.size()+" - must be 0 or >= 2)");this.Xn=t}},{key:"isCoordinate",value:function(t){for(var e=0;e<this.Xn.size();e++)if(this.Xn.getCoordinate(e).equals(t))return!0;return!1}},{key:"getStartPoint",value:function(){return this.isEmpty()?null:this.getPointN(0)}},{key:"getPointN",value:function(t){return this.getFactory().createPoint(this.Xn.getCoordinate(t))}},{key:"interfaces_",get:function(){return[$t]}}],[{key:"constructor_",value:function(){if(this.Xn=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];H.constructor_.call(this,e),this.init(t)}}}])}(H),Ot=s((function t(){n(this,t)})),It=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"computeEnvelopeInternal",value:function(){if(this.isEmpty())return new L;var t=new L;return t.expandToInclude(this.pu.getX(0),this.pu.getY(0)),t}},{key:"getCoordinates",value:function(){return this.isEmpty()?[]:[this.getCoordinate()]}},{key:"copyInternal",value:function(){return new i(this.pu.copy(),this._a)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&(!(!this.isEmpty()||!t.isEmpty())||this.isEmpty()===t.isEmpty()&&this.equal(t.getCoordinate(),this.getCoordinate(),e))}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){}},{key:"getCoordinate",value:function(){return 0!==this.pu.size()?this.pu.getCoordinate(0):null}},{key:"getBoundaryDimension",value:function(){return Mt.FALSE}},{key:"reverseInternal",value:function(){return this.getFactory().createPoint(this.pu.copy())}},{key:"getTypeCode",value:function(){return H.TYPECODE_POINT}},{key:"getDimension",value:function(){return 0}},{key:"getNumPoints",value:function(){return this.isEmpty()?0:1}},{key:"getX",value:function(){if(null===this.getCoordinate())throw new IllegalStateException("getX called on empty Point");return this.getCoordinate().x}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0];return this.getCoordinate().compareTo(t.getCoordinate())}if(2===arguments.length){var e=arguments[0];return arguments[1].compare(this.pu,e.pu)}}},{key:"apply",value:function(){if(it(arguments[0],xt)){var t=arguments[0];if(this.isEmpty())return null;t.filter(this.getCoordinate())}else if(it(arguments[0],Ct)){var e=arguments[0];if(this.isEmpty())return null;e.filter(this.pu,0),e.isGeometryChanged()&&this.geometryChanged()}else(it(arguments[0],Et)||it(arguments[0],b))&&arguments[0].filter(this)}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return H.TYPENAME_POINT}},{key:"getCoordinateSequence",value:function(){return this.pu}},{key:"getY",value:function(){if(null===this.getCoordinate())throw new IllegalStateException("getY called on empty Point");return this.getCoordinate().y}},{key:"isEmpty",value:function(){return 0===this.pu.size()}},{key:"init",value:function(t){null===t&&(t=this.getFactory().getCoordinateSequenceFactory().create([])),D.isTrue(t.size()<=1),this.pu=t}},{key:"isSimple",value:function(){return!0}},{key:"interfaces_",get:function(){return[Ot]}}],[{key:"constructor_",value:function(){this.pu=null;var t=arguments[0],e=arguments[1];H.constructor_.call(this,e),this.init(t)}}])}(H),Tt=function(){function t(){n(this,t)}return s(t,null,[{key:"ofRing",value:function(){if(arguments[0]instanceof Array){var e=arguments[0];return Math.abs(t.ofRingSigned(e))}if(it(arguments[0],ht)){var n=arguments[0];return Math.abs(t.ofRingSigned(n))}}},{key:"ofRingSigned",value:function(){if(arguments[0]instanceof Array){var t=arguments[0];if(t.length<3)return 0;for(var e=0,n=t[0].x,i=1;i<t.length-1;i++){var r=t[i].x-n,s=t[i+1].y;e+=r*(t[i-1].y-s)}return e/2}if(it(arguments[0],ht)){var o=arguments[0],a=o.size();if(a<3)return 0;var u=new j,h=new j,l=new j;o.getCoordinate(0,h),o.getCoordinate(1,l);var c=h.x;l.x-=c;for(var f=0,d=1;d<a-1;d++)u.y=h.y,h.x=l.x,h.y=l.y,o.getCoordinate(d+1,l),l.x-=c,f+=h.x*(u.y-l.y);return f/2}}}])}(),zt=s((function t(){n(this,t)}),null,[{key:"sort",value:function(){var t=arguments,e=arguments[0];if(1===arguments.length)e.sort((function(t,e){return t.compareTo(e)}));else if(2===arguments.length)e.sort((function(e,n){return t[1].compare(e,n)}));else if(3===arguments.length){var n=e.slice(arguments[1],arguments[2]);n.sort();var i=e.slice(0,arguments[1]).concat(n,e.slice(arguments[2],e.length));e.splice(0,e.length);var r,s=o(i);try{for(s.s();!(r=s.n()).done;){var a=r.value;e.push(a)}}catch(t){s.e(t)}finally{s.f()}}else if(4===arguments.length){var u=e.slice(arguments[1],arguments[2]);u.sort((function(e,n){return t[3].compare(e,n)}));var h=e.slice(0,arguments[1]).concat(u,e.slice(arguments[2],e.length));e.splice(0,e.length);var l,c=o(h);try{for(c.s();!(l=c.n()).done;){var f=l.value;e.push(f)}}catch(t){c.e(t)}finally{c.f()}}}},{key:"asList",value:function(t){var e,n=new pt,i=o(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n.add(r)}}catch(t){i.e(t)}finally{i.f()}return n}},{key:"copyOf",value:function(t,e){return t.slice(0,e)}}]),Rt=s((function t(){n(this,t)})),Ft=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"computeEnvelopeInternal",value:function(){return this.vu.getEnvelopeInternal()}},{key:"getCoordinates",value:function(){if(this.isEmpty())return[];for(var t=new Array(this.getNumPoints()).fill(null),e=-1,n=this.vu.getCoordinates(),i=0;i<n.length;i++)t[++e]=n[i];for(var r=0;r<this.mu.length;r++)for(var s=this.mu[r].getCoordinates(),o=0;o<s.length;o++)t[++e]=s[o];return t}},{key:"getArea",value:function(){var t=0;t+=Tt.ofRing(this.vu.getCoordinateSequence());for(var e=0;e<this.mu.length;e++)t-=Tt.ofRing(this.mu[e].getCoordinateSequence());return t}},{key:"copyInternal",value:function(){for(var t=this.vu.copy(),e=new Array(this.mu.length).fill(null),n=0;n<this.mu.length;n++)e[n]=this.mu[n].copy();return new i(t,e,this._a)}},{key:"isRectangle",value:function(){if(0!==this.getNumInteriorRing())return!1;if(null===this.vu)return!1;if(5!==this.vu.getNumPoints())return!1;for(var t=this.vu.getCoordinateSequence(),e=this.getEnvelopeInternal(),n=0;n<5;n++){var i=t.getX(n);if(i!==e.getMinX()&&i!==e.getMaxX())return!1;var r=t.getY(n);if(r!==e.getMinY()&&r!==e.getMaxY())return!1}for(var s=t.getX(0),o=t.getY(0),a=1;a<=4;a++){var u=t.getX(a),h=t.getY(a);if(u!==s==(h!==o))return!1;s=u,o=h}return!0}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t,r=this.vu,s=n.vu;if(!r.equalsExact(s,e))return!1;if(this.mu.length!==n.mu.length)return!1;for(var o=0;o<this.mu.length;o++)if(!this.mu[o].equalsExact(n.mu[o],e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){if(0===arguments.length){this.vu=this.normalized(this.vu,!0);for(var t=0;t<this.mu.length;t++)this.mu[t]=this.normalized(this.mu[t],!1);zt.sort(this.mu)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];if(e.isEmpty())return null;var i=e.getCoordinateSequence(),r=St.minCoordinateIndex(i,0,i.size()-2);St.scroll(i,r,!0),lt.isCCW(i)===n&&St.reverse(i)}}},{key:"getCoordinate",value:function(){return this.vu.getCoordinate()}},{key:"getNumInteriorRing",value:function(){return this.mu.length}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"reverseInternal",value:function(){for(var t=this.getExteriorRing().reverse(),e=new Array(this.getNumInteriorRing()).fill(null),n=0;n<e.length;n++)e[n]=this.getInteriorRingN(n).reverse();return this.getFactory().createPolygon(t,e)}},{key:"getTypeCode",value:function(){return H.TYPECODE_POLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getLength",value:function(){var t=0;t+=this.vu.getLength();for(var e=0;e<this.mu.length;e++)t+=this.mu[e].getLength();return t}},{key:"getNumPoints",value:function(){for(var t=this.vu.getNumPoints(),e=0;e<this.mu.length;e++)t+=this.mu[e].getNumPoints();return t}},{key:"convexHull",value:function(){return this.getExteriorRing().convexHull()}},{key:"normalized",value:function(t,e){var n=t.copy();return this.normalize(n,e),n}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0],e=this.vu,n=t.vu;return e.compareToSameClass(n)}if(2===arguments.length){var i=arguments[1],r=arguments[0],s=this.vu,o=r.vu,a=s.compareToSameClass(o,i);if(0!==a)return a;for(var u=this.getNumInteriorRing(),h=r.getNumInteriorRing(),l=0;l<u&&l<h;){var c=this.getInteriorRingN(l),f=r.getInteriorRingN(l),d=c.compareToSameClass(f,i);if(0!==d)return d;l++}return l<u?1:l<h?-1:0}}},{key:"apply",value:function(){if(it(arguments[0],xt)){var t=arguments[0];this.vu.apply(t);for(var e=0;e<this.mu.length;e++)this.mu[e].apply(t)}else if(it(arguments[0],Ct)){var n=arguments[0];if(this.vu.apply(n),!n.isDone())for(var i=0;i<this.mu.length&&(this.mu[i].apply(n),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else if(it(arguments[0],Et))arguments[0].filter(this);else if(it(arguments[0],b)){var r=arguments[0];r.filter(this),this.vu.apply(r);for(var s=0;s<this.mu.length;s++)this.mu[s].apply(r)}}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();var t=new Array(this.mu.length+1).fill(null);t[0]=this.vu;for(var e=0;e<this.mu.length;e++)t[e+1]=this.mu[e];return t.length<=1?this.getFactory().createLinearRing(t[0].getCoordinateSequence()):this.getFactory().createMultiLineString(t)}},{key:"getGeometryType",value:function(){return H.TYPENAME_POLYGON}},{key:"getExteriorRing",value:function(){return this.vu}},{key:"isEmpty",value:function(){return this.vu.isEmpty()}},{key:"getInteriorRingN",value:function(t){return this.mu[t]}},{key:"interfaces_",get:function(){return[Rt]}}],[{key:"constructor_",value:function(){this.vu=null,this.mu=null;var t=arguments[0],e=arguments[1],n=arguments[2];if(H.constructor_.call(this,n),null===t&&(t=this.getFactory().createLinearRing()),null===e&&(e=[]),H.hasNullElements(e))throw new g("holes must not contain null elements");if(t.isEmpty()&&H.hasNonEmptyElements(e))throw new g("shell is empty but holes are not");this.vu=t,this.mu=e}}])}(H),Pt=function(t){function i(){return n(this,i),e(this,i,arguments)}return h(i,t),s(i)}(K),Dt=function(t){function i(t){var r;return n(this,i),(r=e(this,i)).array=[],t instanceof V&&r.addAll(t),r}return h(i,t),s(i,[{key:"contains",value:function(t){var e,n=o(this.array);try{for(n.s();!(e=n.n()).done;)if(0===e.value.compareTo(t))return!0}catch(t){n.e(t)}finally{n.f()}return!1}},{key:"add",value:function(t){if(this.contains(t))return!1;for(var e=0,n=this.array.length;e<n;e++)if(1===this.array[e].compareTo(t))return!!this.array.splice(e,0,t);return this.array.push(t),!0}},{key:"addAll",value:function(t){var e,n=o(t);try{for(n.s();!(e=n.n()).done;){var i=e.value;this.add(i)}}catch(t){n.e(t)}finally{n.f()}return!0}},{key:"remove",value:function(){throw new Y}},{key:"size",value:function(){return this.array.length}},{key:"isEmpty",value:function(){return 0===this.array.length}},{key:"toArray",value:function(){return this.array.slice()}},{key:"iterator",value:function(){return new Nt(this.array)}}])}(Pt),Nt=s((function t(e){n(this,t),this.array=e,this.position=0}),[{key:"next",value:function(){if(this.position===this.array.length)throw new G;return this.array[this.position++]}},{key:"hasNext",value:function(){return this.position<this.array.length}},{key:"remove",value:function(){throw new Y}}]),Ut=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"computeEnvelopeInternal",value:function(){for(var t=new L,e=0;e<this.yu.length;e++)t.expandToInclude(this.yu[e].getEnvelopeInternal());return t}},{key:"getGeometryN",value:function(t){return this.yu[t]}},{key:"getCoordinates",value:function(){for(var t=new Array(this.getNumPoints()).fill(null),e=-1,n=0;n<this.yu.length;n++)for(var i=this.yu[n].getCoordinates(),r=0;r<i.length;r++)t[++e]=i[r];return t}},{key:"getArea",value:function(){for(var t=0,e=0;e<this.yu.length;e++)t+=this.yu[e].getArea();return t}},{key:"copyInternal",value:function(){for(var t=new Array(this.yu.length).fill(null),e=0;e<t.length;e++)t[e]=this.yu[e].copy();return new i(t,this._a)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];if(!this.isEquivalentClass(t))return!1;var n=t;if(this.yu.length!==n.yu.length)return!1;for(var r=0;r<this.yu.length;r++)if(!this.yu[r].equalsExact(n.yu[r],e))return!1;return!0}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"normalize",value:function(){for(var t=0;t<this.yu.length;t++)this.yu[t].normalize();zt.sort(this.yu)}},{key:"getCoordinate",value:function(){return this.isEmpty()?null:this.yu[0].getCoordinate()}},{key:"getBoundaryDimension",value:function(){for(var t=Mt.FALSE,e=0;e<this.yu.length;e++)t=Math.max(t,this.yu[e].getBoundaryDimension());return t}},{key:"reverseInternal",value:function(){for(var t=this.yu.length,e=new pt(t),n=0;n<t;n++)e.add(this.yu[n].reverse());return this.getFactory().buildGeometry(e)}},{key:"getTypeCode",value:function(){return H.TYPECODE_GEOMETRYCOLLECTION}},{key:"getDimension",value:function(){for(var t=Mt.FALSE,e=0;e<this.yu.length;e++)t=Math.max(t,this.yu[e].getDimension());return t}},{key:"getLength",value:function(){for(var t=0,e=0;e<this.yu.length;e++)t+=this.yu[e].getLength();return t}},{key:"getNumPoints",value:function(){for(var t=0,e=0;e<this.yu.length;e++)t+=this.yu[e].getNumPoints();return t}},{key:"getNumGeometries",value:function(){return this.yu.length}},{key:"compareToSameClass",value:function(){if(1===arguments.length){var t=arguments[0],e=new Dt(zt.asList(this.yu)),n=new Dt(zt.asList(t.yu));return this.compare(e,n)}if(2===arguments.length){for(var i=arguments[1],r=arguments[0],s=this.getNumGeometries(),o=r.getNumGeometries(),a=0;a<s&&a<o;){var u=this.getGeometryN(a),h=r.getGeometryN(a),l=u.compareToSameClass(h,i);if(0!==l)return l;a++}return a<s?1:a<o?-1:0}}},{key:"apply",value:function(){if(it(arguments[0],xt))for(var t=arguments[0],e=0;e<this.yu.length;e++)this.yu[e].apply(t);else if(it(arguments[0],Ct)){var n=arguments[0];if(0===this.yu.length)return null;for(var i=0;i<this.yu.length&&(this.yu[i].apply(n),!n.isDone());i++);n.isGeometryChanged()&&this.geometryChanged()}else if(it(arguments[0],Et)){var r=arguments[0];r.filter(this);for(var s=0;s<this.yu.length;s++)this.yu[s].apply(r)}else if(it(arguments[0],b)){var o=arguments[0];o.filter(this);for(var a=0;a<this.yu.length;a++)this.yu[a].apply(o)}}},{key:"getBoundary",value:function(){return H.checkNotGeometryCollection(this),D.shouldNeverReachHere(),null}},{key:"getGeometryType",value:function(){return H.TYPENAME_GEOMETRYCOLLECTION}},{key:"isEmpty",value:function(){for(var t=0;t<this.yu.length;t++)if(!this.yu[t].isEmpty())return!1;return!0}}],[{key:"constructor_",value:function(){if(this.yu=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];if(H.constructor_.call(this,e),null===t&&(t=[]),H.hasNullElements(t))throw new g("geometries must not contain null elements");this.yu=t}}}])}(H),qt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"copyInternal",value:function(){for(var t=new Array(this.yu.length).fill(null),e=0;e<t.length;e++)t[e]=this.yu[e].copy();return new i(t,this._a)}},{key:"isValid",value:function(){return!0}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getCoordinate",value:function(){if(1===arguments.length&&Number.isInteger(arguments[0])){var t=arguments[0];return this.yu[t].getCoordinate()}return f(i,"getCoordinate",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return Mt.FALSE}},{key:"getTypeCode",value:function(){return H.TYPECODE_MULTIPOINT}},{key:"getDimension",value:function(){return 0}},{key:"getBoundary",value:function(){return this.getFactory().createGeometryCollection()}},{key:"getGeometryType",value:function(){return H.TYPENAME_MULTIPOINT}},{key:"interfaces_",get:function(){return[Ot]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ut.constructor_.call(this,t,e)}}])}(Ut),jt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"copyInternal",value:function(){return new i(this.Xn.copy(),this._a)}},{key:"getBoundaryDimension",value:function(){return Mt.FALSE}},{key:"isClosed",value:function(){return!!this.isEmpty()||f(i,"isClosed",this,1).call(this)}},{key:"reverseInternal",value:function(){var t=this.Xn.copy();return St.reverse(t),this.getFactory().createLinearRing(t)}},{key:"getTypeCode",value:function(){return H.TYPECODE_LINEARRING}},{key:"validateConstruction",value:function(){if(!this.isEmpty()&&!f(i,"isClosed",this,1).call(this))throw new g("Points of LinearRing do not form a closed linestring");if(this.getCoordinateSequence().size()>=1&&this.getCoordinateSequence().size()<i.MINIMUM_VALID_SIZE)throw new g("Invalid number of points in LinearRing (found "+this.getCoordinateSequence().size()+" - must be 0 or >= 4)")}},{key:"getGeometryType",value:function(){return H.TYPENAME_LINEARRING}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];At.constructor_.call(this,t,e),this.validateConstruction()}}])}(At);jt.MINIMUM_VALID_SIZE=4;var Bt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"setOrdinate",value:function(t,e){switch(t){case i.X:this.x=e;break;case i.Y:this.y=e;break;default:throw new g("Invalid ordinate index: "+t)}}},{key:"getZ",value:function(){return j.NULL_ORDINATE}},{key:"getOrdinate",value:function(t){switch(t){case i.X:return this.x;case i.Y:return this.y}throw new g("Invalid ordinate index: "+t)}},{key:"setZ",value:function(t){throw new g("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ()}}],[{key:"constructor_",value:function(){if(0===arguments.length)j.constructor_.call(this);else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];j.constructor_.call(this,t.x,t.y)}else if(arguments[0]instanceof j){var e=arguments[0];j.constructor_.call(this,e.x,e.y)}}else if(2===arguments.length){var n=arguments[0],r=arguments[1];j.constructor_.call(this,n,r,j.NULL_ORDINATE)}}}])}(j);Bt.X=0,Bt.Y=1,Bt.Z=-1,Bt.M=-1;var Lt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getM",value:function(){return this.wu}},{key:"setOrdinate",value:function(t,e){switch(t){case i.X:this.x=e;break;case i.Y:this.y=e;break;case i.M:this.wu=e;break;default:throw new g("Invalid ordinate index: "+t)}}},{key:"setM",value:function(t){this.wu=t}},{key:"getZ",value:function(){return j.NULL_ORDINATE}},{key:"getOrdinate",value:function(t){switch(t){case i.X:return this.x;case i.Y:return this.y;case i.M:return this.wu}throw new g("Invalid ordinate index: "+t)}},{key:"setZ",value:function(t){throw new g("CoordinateXY dimension 2 does not support z-ordinate")}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this.wu=t.getM()}}],[{key:"constructor_",value:function(){if(this.wu=null,0===arguments.length)j.constructor_.call(this),this.wu=0;else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];j.constructor_.call(this,t.x,t.y),this.wu=t.wu}else if(arguments[0]instanceof j){var e=arguments[0];j.constructor_.call(this,e.x,e.y),this.wu=this.getM()}}else if(3===arguments.length){var n=arguments[0],r=arguments[1],s=arguments[2];j.constructor_.call(this,n,r,j.NULL_ORDINATE),this.wu=s}}}])}(j);Lt.X=0,Lt.Y=1,Lt.Z=-1,Lt.M=2;var Ht=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getM",value:function(){return this.wu}},{key:"setOrdinate",value:function(t,e){switch(t){case j.X:this.x=e;break;case j.Y:this.y=e;break;case j.Z:this.z=e;break;case j.M:this.wu=e;break;default:throw new g("Invalid ordinate index: "+t)}}},{key:"setM",value:function(t){this.wu=t}},{key:"getOrdinate",value:function(t){switch(t){case j.X:return this.x;case j.Y:return this.y;case j.Z:return this.getZ();case j.M:return this.getM()}throw new g("Invalid ordinate index: "+t)}},{key:"copy",value:function(){return new i(this)}},{key:"toString",value:function(){return"("+this.x+", "+this.y+", "+this.getZ()+" m="+this.getM()+")"}},{key:"setCoordinate",value:function(t){this.x=t.x,this.y=t.y,this.z=t.getZ(),this.wu=t.getM()}}],[{key:"constructor_",value:function(){if(this.wu=null,0===arguments.length)j.constructor_.call(this),this.wu=0;else if(1===arguments.length){if(arguments[0]instanceof i){var t=arguments[0];j.constructor_.call(this,t),this.wu=t.wu}else if(arguments[0]instanceof j){var e=arguments[0];j.constructor_.call(this,e),this.wu=this.getM()}}else if(4===arguments.length){var n=arguments[0],r=arguments[1],s=arguments[2],o=arguments[3];j.constructor_.call(this,n,r,s),this.wu=o}}}])}(j),Wt=function(){function t(){n(this,t)}return s(t,null,[{key:"measures",value:function(t){return t instanceof Bt?0:t instanceof Lt||t instanceof Ht?1:0}},{key:"dimension",value:function(t){return t instanceof Bt?2:t instanceof Lt?3:t instanceof Ht?4:3}},{key:"create",value:function(){if(1===arguments.length){var e=arguments[0];return t.create(e,0)}if(2===arguments.length){var n=arguments[0],i=arguments[1];return 2===n?new Bt:3===n&&0===i?new j:3===n&&1===i?new Lt:4===n&&1===i?new Ht:new j}}}])}(),Vt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getCoordinate",value:function(t){return this.get(t)}},{key:"addAll",value:function(){if(2===arguments.length&&"boolean"==typeof arguments[1]&&it(arguments[0],V)){for(var t=arguments[1],e=!1,n=arguments[0].iterator();n.hasNext();)this.add(n.next(),t),e=!0;return e}return f(i,"addAll",this,1).apply(this,arguments)}},{key:"clone",value:function(){for(var t=f(i,"clone",this,1).call(this),e=0;e<this.size();e++)t.add(e,this.get(e).clone());return t}},{key:"toCoordinateArray",value:function(){if(0===arguments.length)return this.toArray(i.coordArrayType);if(1===arguments.length){if(arguments[0])return this.toArray(i.coordArrayType);for(var t=this.size(),e=new Array(t).fill(null),n=0;n<t;n++)e[n]=this.get(t-n-1);return e}}},{key:"add",value:function(){if(1===arguments.length){var t=arguments[0];return f(i,"add",this,1).call(this,t)}if(2===arguments.length){if(arguments[0]instanceof Array&&"boolean"==typeof arguments[1]){var e=arguments[0],n=arguments[1];return this.add(e,n,!0),!0}if(arguments[0]instanceof j&&"boolean"==typeof arguments[1]){var r=arguments[0];if(!arguments[1]&&this.size()>=1&&this.get(this.size()-1).equals2D(r))return null;f(i,"add",this,1).call(this,r)}else if(arguments[0]instanceof Object&&"boolean"==typeof arguments[1]){var s=arguments[0],o=arguments[1];return this.add(s,o),!0}}else if(3===arguments.length){if("boolean"==typeof arguments[2]&&arguments[0]instanceof Array&&"boolean"==typeof arguments[1]){var a=arguments[0],u=arguments[1];if(arguments[2])for(var h=0;h<a.length;h++)this.add(a[h],u);else for(var l=a.length-1;l>=0;l--)this.add(a[l],u);return!0}if("boolean"==typeof arguments[2]&&Number.isInteger(arguments[0])&&arguments[1]instanceof j){var c=arguments[0],d=arguments[1];if(!arguments[2]){var p=this.size();if(p>0){if(c>0&&this.get(c-1).equals2D(d))return null;if(c<p&&this.get(c).equals2D(d))return null}}f(i,"add",this,1).call(this,c,d)}}else if(4===arguments.length){var v=arguments[0],m=arguments[1],y=arguments[2],w=arguments[3],g=1;y>w&&(g=-1);for(var b=y;b!==w;b+=g)this.add(v[b],m);return!0}}},{key:"closeRing",value:function(){if(this.size()>0){var t=this.get(0).copy();this.add(t,!1)}}}],[{key:"constructor_",value:function(){if(0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.ensureCapacity(t.length),this.add(t,!0)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.ensureCapacity(e.length),this.add(e,n)}}}])}(pt);Vt.coordArrayType=new Array(0).fill(null);var Gt=function(){function t(){n(this,t)}return s(t,null,[{key:"isRing",value:function(t){return!(t.length<4||!t[0].equals2D(t[t.length-1]))}},{key:"ptNotInList",value:function(e,n){for(var i=0;i<e.length;i++){var r=e[i];if(t.indexOf(r,n)<0)return r}return null}},{key:"scroll",value:function(e,n){var i=t.indexOf(n,e);if(i<0)return null;var r=new Array(e.length).fill(null);wt.arraycopy(e,i,r,0,e.length-i),wt.arraycopy(e,0,r,e.length-i,i),wt.arraycopy(r,0,e,0,e.length)}},{key:"equals",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];if(t===e)return!0;if(null===t||null===e)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!t[n].equals(e[n]))return!1;return!0}if(3===arguments.length){var i=arguments[0],r=arguments[1],s=arguments[2];if(i===r)return!0;if(null===i||null===r)return!1;if(i.length!==r.length)return!1;for(var o=0;o<i.length;o++)if(0!==s.compare(i[o],r[o]))return!1;return!0}}},{key:"intersection",value:function(t,e){for(var n=new Vt,i=0;i<t.length;i++)e.intersects(t[i])&&n.add(t[i],!0);return n.toCoordinateArray()}},{key:"measures",value:function(t){if(null===t||0===t.length)return 0;var e,n=0,i=o(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n=Math.max(n,Wt.measures(r))}}catch(t){i.e(t)}finally{i.f()}return n}},{key:"hasRepeatedPoints",value:function(t){for(var e=1;e<t.length;e++)if(t[e-1].equals(t[e]))return!0;return!1}},{key:"removeRepeatedPoints",value:function(e){return t.hasRepeatedPoints(e)?new Vt(e,!1).toCoordinateArray():e}},{key:"reverse",value:function(t){for(var e=t.length-1,n=Math.trunc(e/2),i=0;i<=n;i++){var r=t[i];t[i]=t[e-i],t[e-i]=r}}},{key:"removeNull",value:function(t){for(var e=0,n=0;n<t.length;n++)null!==t[n]&&e++;var i=new Array(e).fill(null);if(0===e)return i;for(var r=0,s=0;s<t.length;s++)null!==t[s]&&(i[r++]=t[s]);return i}},{key:"copyDeep",value:function(){if(1===arguments.length){for(var t=arguments[0],e=new Array(t.length).fill(null),n=0;n<t.length;n++)e[n]=t[n].copy();return e}if(5===arguments.length)for(var i=arguments[0],r=arguments[1],s=arguments[2],o=arguments[3],a=arguments[4],u=0;u<a;u++)s[o+u]=i[r+u].copy()}},{key:"isEqualReversed",value:function(t,e){for(var n=0;n<t.length;n++){var i=t[n],r=e[t.length-n-1];if(0!==i.compareTo(r))return!1}return!0}},{key:"envelope",value:function(t){for(var e=new L,n=0;n<t.length;n++)e.expandToInclude(t[n]);return e}},{key:"toCoordinateArray",value:function(e){return e.toArray(t.coordArrayType)}},{key:"dimension",value:function(t){if(null===t||0===t.length)return 3;var e,n=0,i=o(t);try{for(i.s();!(e=i.n()).done;){var r=e.value;n=Math.max(n,Wt.dimension(r))}}catch(t){i.e(t)}finally{i.f()}return n}},{key:"atLeastNCoordinatesOrNothing",value:function(t,e){return e.length>=t?e:[]}},{key:"indexOf",value:function(t,e){for(var n=0;n<e.length;n++)if(t.equals(e[n]))return n;return-1}},{key:"increasingDirection",value:function(t){for(var e=0;e<Math.trunc(t.length/2);e++){var n=t.length-1-e,i=t[e].compareTo(t[n]);if(0!==i)return i}return 1}},{key:"compare",value:function(t,e){for(var n=0;n<t.length&&n<e.length;){var i=t[n].compareTo(e[n]);if(0!==i)return i;n++}return n<e.length?-1:n<t.length?1:0}},{key:"minCoordinate",value:function(t){for(var e=null,n=0;n<t.length;n++)(null===e||e.compareTo(t[n])>0)&&(e=t[n]);return e}},{key:"extract",value:function(t,e,n){e=gt.clamp(e,0,t.length);var i=(n=gt.clamp(n,-1,t.length))-e+1;n<0&&(i=0),e>=t.length&&(i=0),n<e&&(i=0);var r=new Array(i).fill(null);if(0===i)return r;for(var s=0,o=e;o<=n;o++)r[s++]=t[o];return r}}])}(),Yt=s((function t(){n(this,t)}),[{key:"compare",value:function(t,e){var n=t,i=e;return Gt.compare(n,i)}},{key:"interfaces_",get:function(){return[R]}}]),Kt=s((function t(){n(this,t)}),[{key:"compare",value:function(t,e){var n=t,i=e;if(n.length<i.length)return-1;if(n.length>i.length)return 1;if(0===n.length)return 0;var r=Gt.compare(n,i);return Gt.isEqualReversed(n,i)?0:r}},{key:"OLDcompare",value:function(t,e){var n=t,i=e;if(n.length<i.length)return-1;if(n.length>i.length)return 1;if(0===n.length)return 0;for(var r=Gt.increasingDirection(n),s=Gt.increasingDirection(i),o=r>0?0:n.length-1,a=s>0?0:n.length-1,u=0;u<n.length;u++){var h=n[o].compareTo(i[a]);if(0!==h)return h;o+=r,a+=s}return 0}},{key:"interfaces_",get:function(){return[R]}}]);Gt.ForwardComparator=Yt,Gt.BidirectionalComparator=Kt,Gt.coordArrayType=new Array(0).fill(null);var Xt=s((function t(e){n(this,t),this.str=e}),[{key:"append",value:function(t){this.str+=t}},{key:"setCharAt",value:function(t,e){this.str=this.str.substr(0,t)+e+this.str.substr(t+1)}},{key:"toString",value:function(){return this.str}}]),Qt=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getM",value:function(t){return this.hasM()?this.pu[t].getM():z.NaN}},{key:"setOrdinate",value:function(t,e,n){switch(e){case ht.X:this.pu[t].x=n;break;case ht.Y:this.pu[t].y=n;break;default:this.pu[t].setOrdinate(e,n)}}},{key:"getZ",value:function(t){return this.hasZ()?this.pu[t].getZ():z.NaN}},{key:"size",value:function(){return this.pu.length}},{key:"getOrdinate",value:function(t,e){switch(e){case ht.X:return this.pu[t].x;case ht.Y:return this.pu[t].y;default:return this.pu[t].getOrdinate(e)}}},{key:"getCoordinate",value:function(){if(1===arguments.length){var t=arguments[0];return this.pu[t]}if(2===arguments.length){var e=arguments[0];arguments[1].setCoordinate(this.pu[e])}}},{key:"getCoordinateCopy",value:function(t){var e=this.createCoordinate();return e.setCoordinate(this.pu[t]),e}},{key:"createCoordinate",value:function(){return Wt.create(this.getDimension(),this.getMeasures())}},{key:"getDimension",value:function(){return this.gu}},{key:"getX",value:function(t){return this.pu[t].x}},{key:"getMeasures",value:function(){return this.bu}},{key:"expandEnvelope",value:function(t){for(var e=0;e<this.pu.length;e++)t.expandToInclude(this.pu[e]);return t}},{key:"copy",value:function(){for(var e=new Array(this.size()).fill(null),n=0;n<this.pu.length;n++){var i=this.createCoordinate();i.setCoordinate(this.pu[n]),e[n]=i}return new t(e,this.gu,this.bu)}},{key:"toString",value:function(){if(this.pu.length>0){var t=new Xt(17*this.pu.length);t.append("("),t.append(this.pu[0]);for(var e=1;e<this.pu.length;e++)t.append(", "),t.append(this.pu[e]);return t.append(")"),t.toString()}return"()"}},{key:"getY",value:function(t){return this.pu[t].y}},{key:"toCoordinateArray",value:function(){return this.pu}},{key:"interfaces_",get:function(){return[ht,k]}}],[{key:"constructor_",value:function(){if(this.gu=3,this.bu=0,this.pu=null,1===arguments.length){if(arguments[0]instanceof Array){var e=arguments[0];t.constructor_.call(this,e,Gt.dimension(e),Gt.measures(e))}else if(Number.isInteger(arguments[0])){var n=arguments[0];this.pu=new Array(n).fill(null);for(var i=0;i<n;i++)this.pu[i]=new j}else if(it(arguments[0],ht)){var r=arguments[0];if(null===r)return this.pu=new Array(0).fill(null),null;this.gu=r.getDimension(),this.bu=r.getMeasures(),this.pu=new Array(r.size()).fill(null);for(var s=0;s<this.pu.length;s++)this.pu[s]=r.getCoordinateCopy(s)}}else if(2===arguments.length){if(arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var o=arguments[0],a=arguments[1];t.constructor_.call(this,o,a,Gt.measures(o))}else if(Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var u=arguments[0],h=arguments[1];this.pu=new Array(u).fill(null),this.gu=h;for(var l=0;l<u;l++)this.pu[l]=Wt.create(h)}}else if(3===arguments.length)if(Number.isInteger(arguments[2])&&arguments[0]instanceof Array&&Number.isInteger(arguments[1])){var c=arguments[0],f=arguments[1],d=arguments[2];this.gu=f,this.bu=d,this.pu=null===c?new Array(0).fill(null):c}else if(Number.isInteger(arguments[2])&&Number.isInteger(arguments[0])&&Number.isInteger(arguments[1])){var p=arguments[0],v=arguments[1],m=arguments[2];this.pu=new Array(p).fill(null),this.gu=v,this.bu=m;for(var y=0;y<p;y++)this.pu[y]=this.createCoordinate()}}}])}(),Zt=function(){function t(){n(this,t)}return s(t,[{key:"readResolve",value:function(){return t.instance()}},{key:"create",value:function(){if(1===arguments.length){if(arguments[0]instanceof Array)return new Qt(arguments[0]);if(it(arguments[0],ht))return new Qt(arguments[0])}else{if(2===arguments.length){var t=arguments[1];return t>3&&(t=3),t<2&&(t=2),new Qt(arguments[0],t)}if(3===arguments.length){var e=arguments[2],n=arguments[1]-e;return e>1&&(e=1),n>3&&(n=3),n<2&&(n=2),new Qt(arguments[0],n+e,e)}}}},{key:"interfaces_",get:function(){return[_t,k]}}],[{key:"instance",value:function(){return t.instanceObject}}])}();Zt.instanceObject=new Zt;var Jt=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"copyInternal",value:function(){for(var t=new Array(this.yu.length).fill(null),e=0;e<t.length;e++)t[e]=this.yu[e].copy();return new i(t,this._a)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return 1}},{key:"getTypeCode",value:function(){return H.TYPECODE_MULTIPOLYGON}},{key:"getDimension",value:function(){return 2}},{key:"getBoundary",value:function(){if(this.isEmpty())return this.getFactory().createMultiLineString();for(var t=new pt,e=0;e<this.yu.length;e++)for(var n=this.yu[e].getBoundary(),i=0;i<n.getNumGeometries();i++)t.add(n.getGeometryN(i));var r=new Array(t.size()).fill(null);return this.getFactory().createMultiLineString(t.toArray(r))}},{key:"getGeometryType",value:function(){return H.TYPENAME_MULTIPOLYGON}},{key:"interfaces_",get:function(){return[Rt]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ut.constructor_.call(this,t,e)}}])}(Ut),te=s((function t(){n(this,t)}),[{key:"get",value:function(){}},{key:"put",value:function(){}},{key:"size",value:function(){}},{key:"values",value:function(){}},{key:"entrySet",value:function(){}}]),ee=function(t){function i(){var t;return n(this,i),(t=e(this,i)).map=new Map,t}return h(i,t),s(i,[{key:"get",value:function(t){return this.map.get(t)||null}},{key:"put",value:function(t,e){return this.map.set(t,e),e}},{key:"values",value:function(){for(var t=new pt,e=this.map.values(),n=e.next();!n.done;)t.add(n.value),n=e.next();return t}},{key:"entrySet",value:function(){var t=new X;return this.map.entries().forEach((function(e){return t.add(e)})),t}},{key:"size",value:function(){return this.map.size()}}])}(te),ne=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this._u===n._u&&this.$r===n.$r}},{key:"compareTo",value:function(t){var e=t,n=this.getMaximumSignificantDigits(),i=e.getMaximumSignificantDigits();return st.compare(n,i)}},{key:"getScale",value:function(){return this.$r}},{key:"isFloating",value:function(){return this._u===t.FLOATING||this._u===t.FLOATING_SINGLE}},{key:"getType",value:function(){return this._u}},{key:"toString",value:function(){var e="UNKNOWN";return this._u===t.FLOATING?e="Floating":this._u===t.FLOATING_SINGLE?e="Floating-Single":this._u===t.FIXED&&(e="Fixed (Scale="+this.getScale()+")"),e}},{key:"makePrecise",value:function(){if("number"==typeof arguments[0]){var e=arguments[0];return z.isNaN(e)||this._u===t.FLOATING_SINGLE?e:this._u===t.FIXED?Math.round(e*this.$r)/this.$r:e}if(arguments[0]instanceof j){var n=arguments[0];if(this._u===t.FLOATING)return null;n.x=this.makePrecise(n.x),n.y=this.makePrecise(n.y)}}},{key:"getMaximumSignificantDigits",value:function(){var e=16;return this._u===t.FLOATING?e=16:this._u===t.FLOATING_SINGLE?e=6:this._u===t.FIXED&&(e=1+Math.trunc(Math.ceil(Math.log(this.getScale())/Math.log(10)))),e}},{key:"setScale",value:function(t){this.$r=Math.abs(t)}},{key:"interfaces_",get:function(){return[k,_]}}],[{key:"constructor_",value:function(){if(this._u=null,this.$r=null,0===arguments.length)this._u=t.FLOATING;else if(1===arguments.length)if(arguments[0]instanceof ie){var e=arguments[0];this._u=e,e===t.FIXED&&this.setScale(1)}else if("number"==typeof arguments[0]){var n=arguments[0];this._u=t.FIXED,this.setScale(n)}else if(arguments[0]instanceof t){var i=arguments[0];this._u=i._u,this.$r=i.$r}}},{key:"mostPrecise",value:function(t,e){return t.compareTo(e)>=0?t:e}}])}(),ie=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"readResolve",value:function(){return t.nameToTypeMap.get(this.do)}},{key:"toString",value:function(){return this.do}},{key:"interfaces_",get:function(){return[k]}}],[{key:"constructor_",value:function(){this.do=null;var e=arguments[0];this.do=e,t.nameToTypeMap.put(e,this)}}])}();ie.nameToTypeMap=new ee,ne.Type=ie,ne.FIXED=new ie("FIXED"),ne.FLOATING=new ie("FLOATING"),ne.FLOATING_SINGLE=new ie("FLOATING SINGLE"),ne.maximumPreciseValue=9007199254740992;var re=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"copyInternal",value:function(){for(var t=new Array(this.yu.length).fill(null),e=0;e<t.length;e++)t[e]=this.yu[e].copy();return new i(t,this._a)}},{key:"equalsExact",value:function(){if(2===arguments.length&&"number"==typeof arguments[1]&&arguments[0]instanceof H){var t=arguments[0],e=arguments[1];return!!this.isEquivalentClass(t)&&f(i,"equalsExact",this,1).call(this,t,e)}return f(i,"equalsExact",this,1).apply(this,arguments)}},{key:"getBoundaryDimension",value:function(){return this.isClosed()?Mt.FALSE:0}},{key:"isClosed",value:function(){if(this.isEmpty())return!1;for(var t=0;t<this.yu.length;t++)if(!this.yu[t].isClosed())return!1;return!0}},{key:"getTypeCode",value:function(){return H.TYPECODE_MULTILINESTRING}},{key:"getDimension",value:function(){return 1}},{key:"getBoundary",value:function(){throw new Y}},{key:"getGeometryType",value:function(){return H.TYPENAME_MULTILINESTRING}},{key:"interfaces_",get:function(){return[$t]}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Ut.constructor_.call(this,t,e)}}])}(Ut),se=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"createEmpty",value:function(t){switch(t){case-1:return this.createGeometryCollection();case 0:return this.createPoint();case 1:return this.createLineString();case 2:return this.createPolygon();default:throw new g("Invalid dimension: "+t)}}},{key:"toGeometry",value:function(t){return t.isNull()?this.createPoint():t.getMinX()===t.getMaxX()&&t.getMinY()===t.getMaxY()?this.createPoint(new j(t.getMinX(),t.getMinY())):t.getMinX()===t.getMaxX()||t.getMinY()===t.getMaxY()?this.createLineString([new j(t.getMinX(),t.getMinY()),new j(t.getMaxX(),t.getMaxY())]):this.createPolygon(this.createLinearRing([new j(t.getMinX(),t.getMinY()),new j(t.getMinX(),t.getMaxY()),new j(t.getMaxX(),t.getMaxY()),new j(t.getMaxX(),t.getMinY()),new j(t.getMinX(),t.getMinY())]),null)}},{key:"createLineString",value:function(){if(0===arguments.length)return this.createLineString(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof Array){var t=arguments[0];return this.createLineString(null!==t?this.getCoordinateSequenceFactory().create(t):null)}if(it(arguments[0],ht))return new At(arguments[0],this)}}},{key:"createMultiLineString",value:function(){return 0===arguments.length?new re(null,this):1===arguments.length?new re(arguments[0],this):void 0}},{key:"buildGeometry",value:function(e){for(var n=null,i=!1,r=!1,s=e.iterator();s.hasNext();){var o=s.next(),a=o.getTypeCode();null===n&&(n=a),a!==n&&(i=!0),o instanceof Ut&&(r=!0)}if(null===n)return this.createGeometryCollection();if(i||r)return this.createGeometryCollection(t.toGeometryArray(e));var u=e.iterator().next();if(e.size()>1){if(u instanceof Ft)return this.createMultiPolygon(t.toPolygonArray(e));if(u instanceof At)return this.createMultiLineString(t.toLineStringArray(e));if(u instanceof It)return this.createMultiPoint(t.toPointArray(e));D.shouldNeverReachHere("Unhandled geometry type: "+u.getGeometryType())}return u}},{key:"createMultiPointFromCoords",value:function(t){return this.createMultiPoint(null!==t?this.getCoordinateSequenceFactory().create(t):null)}},{key:"createPoint",value:function(){if(0===arguments.length)return this.createPoint(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof j){var t=arguments[0];return this.createPoint(null!==t?this.getCoordinateSequenceFactory().create([t]):null)}if(it(arguments[0],ht))return new It(arguments[0],this)}}},{key:"getCoordinateSequenceFactory",value:function(){return this.xu}},{key:"createPolygon",value:function(){if(0===arguments.length)return this.createPolygon(null,null);if(1===arguments.length){if(it(arguments[0],ht)){var t=arguments[0];return this.createPolygon(this.createLinearRing(t))}if(arguments[0]instanceof Array){var e=arguments[0];return this.createPolygon(this.createLinearRing(e))}if(arguments[0]instanceof jt){var n=arguments[0];return this.createPolygon(n,null)}}else if(2===arguments.length)return new Ft(arguments[0],arguments[1],this)}},{key:"getSRID",value:function(){return this.nu}},{key:"createGeometryCollection",value:function(){return 0===arguments.length?new Ut(null,this):1===arguments.length?new Ut(arguments[0],this):void 0}},{key:"getPrecisionModel",value:function(){return this.ku}},{key:"createLinearRing",value:function(){if(0===arguments.length)return this.createLinearRing(this.getCoordinateSequenceFactory().create([]));if(1===arguments.length){if(arguments[0]instanceof Array){var t=arguments[0];return this.createLinearRing(null!==t?this.getCoordinateSequenceFactory().create(t):null)}if(it(arguments[0],ht))return new jt(arguments[0],this)}}},{key:"createMultiPolygon",value:function(){return 0===arguments.length?new Jt(null,this):1===arguments.length?new Jt(arguments[0],this):void 0}},{key:"createMultiPoint",value:function(){if(0===arguments.length)return new qt(null,this);if(1===arguments.length){if(arguments[0]instanceof Array)return new qt(arguments[0],this);if(it(arguments[0],ht)){var t=arguments[0];if(null===t)return this.createMultiPoint(new Array(0).fill(null));for(var e=new Array(t.size()).fill(null),n=0;n<t.size();n++){var i=this.getCoordinateSequenceFactory().create(1,t.getDimension(),t.getMeasures());St.copy(t,n,i,0,1),e[n]=this.createPoint(i)}return this.createMultiPoint(e)}}}},{key:"interfaces_",get:function(){return[k]}}],[{key:"constructor_",value:function(){if(this.ku=null,this.xu=null,this.nu=null,0===arguments.length)t.constructor_.call(this,new ne,0);else if(1===arguments.length){if(it(arguments[0],_t)){var e=arguments[0];t.constructor_.call(this,new ne,0,e)}else if(arguments[0]instanceof ne){var n=arguments[0];t.constructor_.call(this,n,0,t.getDefaultCoordinateSequenceFactory())}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];t.constructor_.call(this,i,r,t.getDefaultCoordinateSequenceFactory())}else if(3===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2];this.ku=s,this.xu=a,this.nu=o}}},{key:"toMultiPolygonArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toGeometryArray",value:function(t){if(null===t)return null;var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"getDefaultCoordinateSequenceFactory",value:function(){return Zt.instance()}},{key:"toMultiLineStringArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toLineStringArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toMultiPointArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toLinearRingArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toPointArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"toPolygonArray",value:function(t){var e=new Array(t.size()).fill(null);return t.toArray(e)}},{key:"createPointFromInternalCoord",value:function(t,e){return e.getPrecisionModel().makePrecise(t),e.getFactory().createPoint(t)}}])}(),oe="XY",ae={POINT:"Point",LINE_STRING:"LineString",LINEAR_RING:"LinearRing",POLYGON:"Polygon",MULTI_POINT:"MultiPoint",MULTI_LINE_STRING:"MultiLineString",MULTI_POLYGON:"MultiPolygon",GEOMETRY_COLLECTION:"GeometryCollection",CIRCLE:"Circle"},ue="EMPTY";for(var he in ae)ae[he].toUpperCase();var le=s((function t(e){n(this,t),this.wkt=e,this.index_=-1}),[{key:"isAlpha_",value:function(t){return t>="a"&&t<="z"||t>="A"&&t<="Z"}},{key:"isNumeric_",value:function(t,e){return t>="0"&&t<="9"||"."==t&&!(void 0!==e&&e)}},{key:"isWhiteSpace_",value:function(t){return" "==t||"\t"==t||"\r"==t||"\n"==t}},{key:"nextChar_",value:function(){return this.wkt.charAt(++this.index_)}},{key:"nextToken",value:function(){var t,e=this.nextChar_(),n=this.index_,i=e;if("("==e)t=2;else if(","==e)t=5;else if(")"==e)t=3;else if(this.isNumeric_(e)||"-"==e)t=4,i=this.readNumber_();else if(this.isAlpha_(e))t=1,i=this.readText_();else{if(this.isWhiteSpace_(e))return this.nextToken();if(""!==e)throw new Error("Unexpected character: "+e);t=6}return{position:n,value:i,type:t}}},{key:"readNumber_",value:function(){var t,e=this.index_,n=!1,i=!1;do{"."==t?n=!0:"e"!=t&&"E"!=t||(i=!0),t=this.nextChar_()}while(this.isNumeric_(t,n)||!i&&("e"==t||"E"==t)||i&&("-"==t||"+"==t));return parseFloat(this.wkt.substring(e,this.index_--))}},{key:"readText_",value:function(){var t,e=this.index_;do{t=this.nextChar_()}while(this.isAlpha_(t));return this.wkt.substring(e,this.index_--).toUpperCase()}}]),ce=s((function t(e,i){n(this,t),this.lexer_=e,this.token_,this.layout_=oe,this.factory=i}),[{key:"consume_",value:function(){this.token_=this.lexer_.nextToken()}},{key:"isTokenType",value:function(t){return this.token_.type==t}},{key:"match",value:function(t){var e=this.isTokenType(t);return e&&this.consume_(),e}},{key:"parse",value:function(){return this.consume_(),this.parseGeometry_()}},{key:"parseGeometryLayout_",value:function(){var t=oe,e=this.token_;if(this.isTokenType(1)){var n=e.value;"Z"===n?t="XYZ":"M"===n?t="XYM":"ZM"===n&&(t="XYZM"),t!==oe&&this.consume_()}return t}},{key:"parseGeometryCollectionText_",value:function(){if(this.match(2)){var t=[];do{t.push(this.parseGeometry_())}while(this.match(5));if(this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePointText_",value:function(){if(this.match(2)){var t=this.parsePoint_();if(this.match(3))return t}else if(this.isEmptyGeometry_())return null;throw new Error(this.formatErrorMessage_())}},{key:"parseLineStringText_",value:function(){if(this.match(2)){var t=this.parsePointList_();if(this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePolygonText_",value:function(){if(this.match(2)){var t=this.parseLineStringTextList_();if(this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPointText_",value:function(){var t;if(this.match(2)){if(t=2==this.token_.type?this.parsePointTextList_():this.parsePointList_(),this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiLineStringText_",value:function(){if(this.match(2)){var t=this.parseLineStringTextList_();if(this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parseMultiPolygonText_",value:function(){if(this.match(2)){var t=this.parsePolygonTextList_();if(this.match(3))return t}else if(this.isEmptyGeometry_())return[];throw new Error(this.formatErrorMessage_())}},{key:"parsePoint_",value:function(){for(var t=[],e=this.layout_.length,n=0;n<e;++n){var i=this.token_;if(!this.match(4))break;t.push(i.value)}if(t.length==e)return t;throw new Error(this.formatErrorMessage_())}},{key:"parsePointList_",value:function(){for(var t=[this.parsePoint_()];this.match(5);)t.push(this.parsePoint_());return t}},{key:"parsePointTextList_",value:function(){for(var t=[this.parsePointText_()];this.match(5);)t.push(this.parsePointText_());return t}},{key:"parseLineStringTextList_",value:function(){for(var t=[this.parseLineStringText_()];this.match(5);)t.push(this.parseLineStringText_());return t}},{key:"parsePolygonTextList_",value:function(){for(var t=[this.parsePolygonText_()];this.match(5);)t.push(this.parsePolygonText_());return t}},{key:"isEmptyGeometry_",value:function(){var t=this.isTokenType(1)&&this.token_.value==ue;return t&&this.consume_(),t}},{key:"formatErrorMessage_",value:function(){return"Unexpected `"+this.token_.value+"` at position "+this.token_.position+" in `"+this.lexer_.wkt+"`"}},{key:"parseGeometry_",value:function(){var t=this.factory,e=function(t){return i(j,d(t))},n=function(n){var i=n.map((function(n){return t.createLinearRing(n.map(e))}));return i.length>1?t.createPolygon(i[0],i.slice(1)):t.createPolygon(i[0])},r=this.token_;if(this.match(1)){var s=r.value;if(this.layout_=this.parseGeometryLayout_(),"GEOMETRYCOLLECTION"==s){var o=this.parseGeometryCollectionText_();return t.createGeometryCollection(o)}switch(s){case"POINT":var a=this.parsePointText_();return a?t.createPoint(i(j,d(a))):t.createPoint();case"LINESTRING":var u=this.parseLineStringText_().map(e);return t.createLineString(u);case"LINEARRING":var h=this.parseLineStringText_().map(e);return t.createLinearRing(h);case"POLYGON":var l=this.parsePolygonText_();return l&&0!==l.length?n(l):t.createPolygon();case"MULTIPOINT":var c=this.parseMultiPointText_();if(!c||0===c.length)return t.createMultiPoint();var f=c.map(e).map((function(e){return t.createPoint(e)}));return t.createMultiPoint(f);case"MULTILINESTRING":var p=this.parseMultiLineStringText_().map((function(n){return t.createLineString(n.map(e))}));return t.createMultiLineString(p);case"MULTIPOLYGON":var v=this.parseMultiPolygonText_();if(!v||0===v.length)return t.createMultiPolygon();var m=v.map(n);return t.createMultiPolygon(m);default:throw new Error("Invalid geometry type: "+s)}}throw new Error(this.formatErrorMessage_())}}]);function fe(t){if(t.isEmpty())return"";var e=t.getCoordinate(),n=[e.x,e.y];return void 0===e.z||Number.isNaN(e.z)||n.push(e.z),void 0===e.m||Number.isNaN(e.m)||n.push(e.m),n.join(" ")}function de(t){for(var e=t.getCoordinates().map((function(t){var e=[t.x,t.y];return void 0===t.z||Number.isNaN(t.z)||e.push(t.z),void 0===t.m||Number.isNaN(t.m)||e.push(t.m),e})),n=[],i=0,r=e.length;i<r;++i)n.push(e[i].join(" "));return n.join(", ")}function pe(t){var e=[];e.push("("+de(t.getExteriorRing())+")");for(var n=0,i=t.getNumInteriorRing();n<i;++n)e.push("("+de(t.getInteriorRingN(n))+")");return e.join(", ")}var ve={Point:fe,LineString:de,LinearRing:de,Polygon:pe,MultiPoint:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+fe(t.getGeometryN(n))+")");return e.join(", ")},MultiLineString:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+de(t.getGeometryN(n))+")");return e.join(", ")},MultiPolygon:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push("("+pe(t.getGeometryN(n))+")");return e.join(", ")},GeometryCollection:function(t){for(var e=[],n=0,i=t.getNumGeometries();n<i;++n)e.push(me(t.getGeometryN(n)));return e.join(", ")}};function me(t){var e=t.getGeometryType(),n=ve[e];e=e.toUpperCase();var i=function(t){var e="";if(t.isEmpty())return e;var n=t.getCoordinate();return void 0===n.z||Number.isNaN(n.z)||(e+="Z"),void 0===n.m||Number.isNaN(n.m)||(e+="M"),e}(t);return i.length>0&&(e+=" "+i),t.isEmpty()?e+" "+ue:e+" ("+n(t)+")"}var ye=s((function t(e){n(this,t),this.geometryFactory=e||new se,this.precisionModel=this.geometryFactory.getPrecisionModel()}),[{key:"read",value:function(t){var e=new le(t);return new ce(e,this.geometryFactory).parse()}},{key:"write",value:function(t){return me(t)}}]),we=s((function t(e){n(this,t),this.parser=new ye(e)}),[{key:"write",value:function(t){return this.parser.write(t)}}],[{key:"toLineString",value:function(t,e){if(2!==arguments.length)throw new Error("Not implemented");return"LINESTRING ( "+t.x+" "+t.y+", "+e.x+" "+e.y+" )"}}]),ge=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getIndexAlongSegment",value:function(t,e){return this.computeIntLineIndex(),this.$u[t][e]}},{key:"getTopologySummary",value:function(){var t=new Xt;return this.isEndPoint()&&t.append(" endpoint"),this.Su&&t.append(" proper"),this.isCollinear()&&t.append(" collinear"),t.toString()}},{key:"computeIntersection",value:function(t,e,n,i){this.Mu[0][0]=t,this.Mu[0][1]=e,this.Mu[1][0]=n,this.Mu[1][1]=i,this.Eu=this.computeIntersect(t,e,n,i)}},{key:"getIntersectionNum",value:function(){return this.Eu}},{key:"computeIntLineIndex",value:function(){if(0===arguments.length)null===this.$u&&(this.$u=Array(2).fill().map((function(){return Array(2)})),this.computeIntLineIndex(0),this.computeIntLineIndex(1));else if(1===arguments.length){var t=arguments[0];this.getEdgeDistance(t,0)>this.getEdgeDistance(t,1)?(this.$u[t][0]=0,this.$u[t][1]=1):(this.$u[t][0]=1,this.$u[t][1]=0)}}},{key:"isProper",value:function(){return this.hasIntersection()&&this.Su}},{key:"setPrecisionModel",value:function(t){this.ku=t}},{key:"isInteriorIntersection",value:function(){if(0===arguments.length)return!!this.isInteriorIntersection(0)||!!this.isInteriorIntersection(1);if(1===arguments.length){for(var t=arguments[0],e=0;e<this.Eu;e++)if(!this.Cu[e].equals2D(this.Mu[t][0])&&!this.Cu[e].equals2D(this.Mu[t][1]))return!0;return!1}}},{key:"getIntersection",value:function(t){return this.Cu[t]}},{key:"isEndPoint",value:function(){return this.hasIntersection()&&!this.Su}},{key:"hasIntersection",value:function(){return this.Eu!==t.NO_INTERSECTION}},{key:"getEdgeDistance",value:function(e,n){return t.computeEdgeDistance(this.Cu[n],this.Mu[e][0],this.Mu[e][1])}},{key:"isCollinear",value:function(){return this.Eu===t.COLLINEAR_INTERSECTION}},{key:"toString",value:function(){return we.toLineString(this.Mu[0][0],this.Mu[0][1])+" - "+we.toLineString(this.Mu[1][0],this.Mu[1][1])+this.getTopologySummary()}},{key:"getEndpoint",value:function(t,e){return this.Mu[t][e]}},{key:"isIntersection",value:function(t){for(var e=0;e<this.Eu;e++)if(this.Cu[e].equals2D(t))return!0;return!1}},{key:"getIntersectionAlongSegment",value:function(t,e){return this.computeIntLineIndex(),this.Cu[this.$u[t][e]]}}],[{key:"constructor_",value:function(){this.Eu=null,this.Mu=Array(2).fill().map((function(){return Array(2)})),this.Cu=new Array(2).fill(null),this.$u=null,this.Su=null,this.Au=null,this.Ou=null,this.ku=null,this.Cu[0]=new j,this.Cu[1]=new j,this.Au=this.Cu[0],this.Ou=this.Cu[1],this.Eu=0}},{key:"computeEdgeDistance",value:function(t,e,n){var i=Math.abs(n.x-e.x),r=Math.abs(n.y-e.y),s=-1;if(t.equals(e))s=0;else if(t.equals(n))s=i>r?i:r;else{var o=Math.abs(t.x-e.x),a=Math.abs(t.y-e.y);0!==(s=i>r?o:a)||t.equals(e)||(s=Math.max(o,a))}return D.isTrue(!(0===s&&!t.equals(e)),"Bad distance calculation"),s}},{key:"nonRobustComputeEdgeDistance",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y,s=Math.sqrt(i*i+r*r);return D.isTrue(!(0===s&&!t.equals(e)),"Invalid distance calculation"),s}}])}();ge.DONT_INTERSECT=0,ge.DO_INTERSECT=1,ge.COLLINEAR=2,ge.NO_INTERSECTION=0,ge.POINT_INTERSECTION=1,ge.COLLINEAR_INTERSECTION=2;var be=function(t){function i(){return n(this,i),e(this,i)}return h(i,t),s(i,[{key:"isInSegmentEnvelopes",value:function(t){var e=new L(this.Mu[0][0],this.Mu[0][1]),n=new L(this.Mu[1][0],this.Mu[1][1]);return e.contains(t)&&n.contains(t)}},{key:"computeIntersection",value:function(){if(3!==arguments.length)return f(i,"computeIntersection",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1],n=arguments[2];if(this.Su=!1,L.intersects(e,n,t)&&0===lt.index(e,n,t)&&0===lt.index(n,e,t))return this.Su=!0,(t.equals(e)||t.equals(n))&&(this.Su=!1),this.Eu=ge.POINT_INTERSECTION,null;this.Eu=ge.NO_INTERSECTION}},{key:"intersection",value:function(t,e,n,r){var s=this.intersectionSafe(t,e,n,r);return this.isInSegmentEnvelopes(s)||(s=new j(i.nearestEndpoint(t,e,n,r))),null!==this.ku&&this.ku.makePrecise(s),s}},{key:"checkDD",value:function(t,e,n,i,r){var s=ut.intersection(t,e,n,i),o=this.isInSegmentEnvelopes(s);wt.out.println("DD in env = "+o+" --------------------- "+s),r.distance(s)>1e-4&&wt.out.println("Distance = "+r.distance(s))}},{key:"intersectionSafe",value:function(t,e,n,r){var s=yt.intersection(t,e,n,r);return null===s&&(s=i.nearestEndpoint(t,e,n,r)),s}},{key:"computeCollinearIntersection",value:function(t,e,n,i){var r=L.intersects(t,e,n),s=L.intersects(t,e,i),o=L.intersects(n,i,t),a=L.intersects(n,i,e);return r&&s?(this.Cu[0]=n,this.Cu[1]=i,ge.COLLINEAR_INTERSECTION):o&&a?(this.Cu[0]=t,this.Cu[1]=e,ge.COLLINEAR_INTERSECTION):r&&o?(this.Cu[0]=n,this.Cu[1]=t,!n.equals(t)||s||a?ge.COLLINEAR_INTERSECTION:ge.POINT_INTERSECTION):r&&a?(this.Cu[0]=n,this.Cu[1]=e,!n.equals(e)||s||o?ge.COLLINEAR_INTERSECTION:ge.POINT_INTERSECTION):s&&o?(this.Cu[0]=i,this.Cu[1]=t,!i.equals(t)||r||a?ge.COLLINEAR_INTERSECTION:ge.POINT_INTERSECTION):s&&a?(this.Cu[0]=i,this.Cu[1]=e,!i.equals(e)||r||o?ge.COLLINEAR_INTERSECTION:ge.POINT_INTERSECTION):ge.NO_INTERSECTION}},{key:"computeIntersect",value:function(t,e,n,i){if(this.Su=!1,!L.intersects(t,e,n,i))return ge.NO_INTERSECTION;var r=lt.index(t,e,n),s=lt.index(t,e,i);if(r>0&&s>0||r<0&&s<0)return ge.NO_INTERSECTION;var o=lt.index(n,i,t),a=lt.index(n,i,e);return o>0&&a>0||o<0&&a<0?ge.NO_INTERSECTION:0===r&&0===s&&0===o&&0===a?this.computeCollinearIntersection(t,e,n,i):(0===r||0===s||0===o||0===a?(this.Su=!1,t.equals2D(n)||t.equals2D(i)?this.Cu[0]=t:e.equals2D(n)||e.equals2D(i)?this.Cu[0]=e:0===r?this.Cu[0]=new j(n):0===s?this.Cu[0]=new j(i):0===o?this.Cu[0]=new j(t):0===a&&(this.Cu[0]=new j(e))):(this.Su=!0,this.Cu[0]=this.intersection(t,e,n,i)),ge.POINT_INTERSECTION)}}],[{key:"nearestEndpoint",value:function(t,e,n,i){var r=t,s=bt.pointToSegment(t,n,i),o=bt.pointToSegment(e,n,i);return o<s&&(s=o,r=e),(o=bt.pointToSegment(n,t,e))<s&&(s=o,r=n),(o=bt.pointToSegment(i,t,e))<s&&(s=o,r=i),r}}])}(ge),_e=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"countSegment",value:function(t,e){if(t.x<this.Iu.x&&e.x<this.Iu.x)return null;if(this.Iu.x===e.x&&this.Iu.y===e.y)return this.Tu=!0,null;if(t.y===this.Iu.y&&e.y===this.Iu.y){var n=t.x,i=e.x;return n>i&&(n=e.x,i=t.x),this.Iu.x>=n&&this.Iu.x<=i&&(this.Tu=!0),null}if(t.y>this.Iu.y&&e.y<=this.Iu.y||e.y>this.Iu.y&&t.y<=this.Iu.y){var r=lt.index(t,e,this.Iu);if(r===lt.COLLINEAR)return this.Tu=!0,null;e.y<t.y&&(r=-r),r===lt.LEFT&&this.zu++}}},{key:"isPointInPolygon",value:function(){return this.getLocation()!==W.EXTERIOR}},{key:"getLocation",value:function(){return this.Tu?W.BOUNDARY:this.zu%2==1?W.INTERIOR:W.EXTERIOR}},{key:"isOnSegment",value:function(){return this.Tu}}],[{key:"constructor_",value:function(){this.Iu=null,this.zu=0,this.Tu=!1;var t=arguments[0];this.Iu=t}},{key:"locatePointInRing",value:function(){if(arguments[0]instanceof j&&it(arguments[1],ht)){for(var e=arguments[1],n=new t(arguments[0]),i=new j,r=new j,s=1;s<e.size();s++)if(e.getCoordinate(s,i),e.getCoordinate(s-1,r),n.countSegment(i,r),n.isOnSegment())return n.getLocation();return n.getLocation()}if(arguments[0]instanceof j&&arguments[1]instanceof Array){for(var o=arguments[1],a=new t(arguments[0]),u=1;u<o.length;u++){var h=o[u],l=o[u-1];if(a.countSegment(h,l),a.isOnSegment())return a.getLocation()}return a.getLocation()}}}])}(),xe=function(){function t(){n(this,t)}return s(t,null,[{key:"isOnLine",value:function(){if(arguments[0]instanceof j&&it(arguments[1],ht)){for(var t=arguments[0],e=arguments[1],n=new be,i=new j,r=new j,s=e.size(),o=1;o<s;o++)if(e.getCoordinate(o-1,i),e.getCoordinate(o,r),n.computeIntersection(t,i,r),n.hasIntersection())return!0;return!1}if(arguments[0]instanceof j&&arguments[1]instanceof Array){for(var a=arguments[0],u=arguments[1],h=new be,l=1;l<u.length;l++){var c=u[l-1],f=u[l];if(h.computeIntersection(a,c,f),h.hasIntersection())return!0}return!1}}},{key:"locateInRing",value:function(t,e){return _e.locatePointInRing(t,e)}},{key:"isInRing",value:function(e,n){return t.locateInRing(e,n)!==W.EXTERIOR}}])}(),ke=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"setAllLocations",value:function(t){for(var e=0;e<this.location.length;e++)this.location[e]=t}},{key:"isNull",value:function(){for(var t=0;t<this.location.length;t++)if(this.location[t]!==W.NONE)return!1;return!0}},{key:"setAllLocationsIfNull",value:function(t){for(var e=0;e<this.location.length;e++)this.location[e]===W.NONE&&(this.location[e]=t)}},{key:"isLine",value:function(){return 1===this.location.length}},{key:"merge",value:function(t){if(t.location.length>this.location.length){var e=new Array(3).fill(null);e[Z.ON]=this.location[Z.ON],e[Z.LEFT]=W.NONE,e[Z.RIGHT]=W.NONE,this.location=e}for(var n=0;n<this.location.length;n++)this.location[n]===W.NONE&&n<t.location.length&&(this.location[n]=t.location[n])}},{key:"getLocations",value:function(){return this.location}},{key:"flip",value:function(){if(this.location.length<=1)return null;var t=this.location[Z.LEFT];this.location[Z.LEFT]=this.location[Z.RIGHT],this.location[Z.RIGHT]=t}},{key:"toString",value:function(){var t=new rt;return this.location.length>1&&t.append(W.toLocationSymbol(this.location[Z.LEFT])),t.append(W.toLocationSymbol(this.location[Z.ON])),this.location.length>1&&t.append(W.toLocationSymbol(this.location[Z.RIGHT])),t.toString()}},{key:"setLocations",value:function(t,e,n){this.location[Z.ON]=t,this.location[Z.LEFT]=e,this.location[Z.RIGHT]=n}},{key:"get",value:function(t){return t<this.location.length?this.location[t]:W.NONE}},{key:"isArea",value:function(){return this.location.length>1}},{key:"isAnyNull",value:function(){for(var t=0;t<this.location.length;t++)if(this.location[t]===W.NONE)return!0;return!1}},{key:"setLocation",value:function(){if(1===arguments.length){var t=arguments[0];this.setLocation(Z.ON,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.location[e]=n}}},{key:"init",value:function(t){this.location=new Array(t).fill(null),this.setAllLocations(W.NONE)}},{key:"isEqualOnSide",value:function(t,e){return this.location[e]===t.location[e]}},{key:"allPositionsEqual",value:function(t){for(var e=0;e<this.location.length;e++)if(this.location[e]!==t)return!1;return!0}}],[{key:"constructor_",value:function(){if(this.location=null,1===arguments.length){if(arguments[0]instanceof Array){var e=arguments[0];this.init(e.length)}else if(Number.isInteger(arguments[0])){var n=arguments[0];this.init(1),this.location[Z.ON]=n}else if(arguments[0]instanceof t){var i=arguments[0];if(this.init(i.location.length),null!==i)for(var r=0;r<this.location.length;r++)this.location[r]=i.location[r]}}else if(3===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2];this.init(3),this.location[Z.ON]=s,this.location[Z.LEFT]=o,this.location[Z.RIGHT]=a}}}])}(),$e=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getGeometryCount",value:function(){var t=0;return this.elt[0].isNull()||t++,this.elt[1].isNull()||t++,t}},{key:"setAllLocations",value:function(t,e){this.elt[t].setAllLocations(e)}},{key:"isNull",value:function(t){return this.elt[t].isNull()}},{key:"setAllLocationsIfNull",value:function(){if(1===arguments.length){var t=arguments[0];this.setAllLocationsIfNull(0,t),this.setAllLocationsIfNull(1,t)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.elt[e].setAllLocationsIfNull(n)}}},{key:"isLine",value:function(t){return this.elt[t].isLine()}},{key:"merge",value:function(t){for(var e=0;e<2;e++)null===this.elt[e]&&null!==t.elt[e]?this.elt[e]=new ke(t.elt[e]):this.elt[e].merge(t.elt[e])}},{key:"flip",value:function(){this.elt[0].flip(),this.elt[1].flip()}},{key:"getLocation",value:function(){if(1===arguments.length){var t=arguments[0];return this.elt[t].get(Z.ON)}if(2===arguments.length){var e=arguments[0],n=arguments[1];return this.elt[e].get(n)}}},{key:"toString",value:function(){var t=new rt;return null!==this.elt[0]&&(t.append("A:"),t.append(this.elt[0].toString())),null!==this.elt[1]&&(t.append(" B:"),t.append(this.elt[1].toString())),t.toString()}},{key:"isArea",value:function(){if(0===arguments.length)return this.elt[0].isArea()||this.elt[1].isArea();if(1===arguments.length){var t=arguments[0];return this.elt[t].isArea()}}},{key:"isAnyNull",value:function(t){return this.elt[t].isAnyNull()}},{key:"setLocation",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.elt[t].setLocation(Z.ON,e)}else if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];this.elt[n].setLocation(i,r)}}},{key:"isEqualOnSide",value:function(t,e){return this.elt[0].isEqualOnSide(t.elt[0],e)&&this.elt[1].isEqualOnSide(t.elt[1],e)}},{key:"allPositionsEqual",value:function(t,e){return this.elt[t].allPositionsEqual(e)}},{key:"toLine",value:function(t){this.elt[t].isArea()&&(this.elt[t]=new ke(this.elt[t].location[0]))}}],[{key:"constructor_",value:function(){if(this.elt=new Array(2).fill(null),1===arguments.length){if(Number.isInteger(arguments[0])){var e=arguments[0];this.elt[0]=new ke(e),this.elt[1]=new ke(e)}else if(arguments[0]instanceof t){var n=arguments[0];this.elt[0]=new ke(n.elt[0]),this.elt[1]=new ke(n.elt[1])}}else if(2===arguments.length){var i=arguments[0],r=arguments[1];this.elt[0]=new ke(W.NONE),this.elt[1]=new ke(W.NONE),this.elt[i].setLocation(r)}else if(3===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2];this.elt[0]=new ke(s,o,a),this.elt[1]=new ke(s,o,a)}else if(4===arguments.length){var u=arguments[0],h=arguments[1],l=arguments[2],c=arguments[3];this.elt[0]=new ke(W.NONE,W.NONE,W.NONE),this.elt[1]=new ke(W.NONE,W.NONE,W.NONE),this.elt[u].setLocations(h,l,c)}}},{key:"toLineLabel",value:function(e){for(var n=new t(W.NONE),i=0;i<2;i++)n.setLocation(i,e.getLocation(i));return n}}])}(),Se=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"computeRing",value:function(){if(null!==this.Ru)return null;for(var t=new Array(this.Fu.size()).fill(null),e=0;e<this.Fu.size();e++)t[e]=this.Fu.get(e);this.Ru=this.Pu.createLinearRing(t),this.Du=lt.isCCW(this.Ru.getCoordinates())}},{key:"isIsolated",value:function(){return 1===this.Nu.getGeometryCount()}},{key:"computePoints",value:function(t){this.Uu=t;var e=t,n=!0;do{if(null===e)throw new ft("Found null DirectedEdge");if(e.getEdgeRing()===this)throw new ft("Directed Edge visited twice during ring-building at "+e.getCoordinate());this.qu.add(e);var i=e.getLabel();D.isTrue(i.isArea()),this.mergeLabel(i),this.addPoints(e.getEdge(),e.isForward(),n),n=!1,this.setEdgeRing(e,this),e=this.getNext(e)}while(e!==this.Uu)}},{key:"getLinearRing",value:function(){return this.Ru}},{key:"getCoordinate",value:function(t){return this.Fu.get(t)}},{key:"computeMaxNodeDegree",value:function(){this.ju=0;var t=this.Uu;do{var e=t.getNode().getEdges().getOutgoingDegree(this);e>this.ju&&(this.ju=e),t=this.getNext(t)}while(t!==this.Uu);this.ju*=2}},{key:"addPoints",value:function(t,e,n){var i=t.getCoordinates();if(e){var r=1;n&&(r=0);for(var s=r;s<i.length;s++)this.Fu.add(i[s])}else{var o=i.length-2;n&&(o=i.length-1);for(var a=o;a>=0;a--)this.Fu.add(i[a])}}},{key:"isHole",value:function(){return this.Du}},{key:"setInResult",value:function(){var t=this.Uu;do{t.getEdge().setInResult(!0),t=t.getNext()}while(t!==this.Uu)}},{key:"containsPoint",value:function(t){var e=this.getLinearRing();if(!e.getEnvelopeInternal().contains(t))return!1;if(!xe.isInRing(t,e.getCoordinates()))return!1;for(var n=this.mu.iterator();n.hasNext();)if(n.next().containsPoint(t))return!1;return!0}},{key:"addHole",value:function(t){this.mu.add(t)}},{key:"isShell",value:function(){return null===this.vu}},{key:"getLabel",value:function(){return this.Nu}},{key:"getEdges",value:function(){return this.qu}},{key:"getMaxNodeDegree",value:function(){return this.ju<0&&this.computeMaxNodeDegree(),this.ju}},{key:"getShell",value:function(){return this.vu}},{key:"mergeLabel",value:function(){if(1===arguments.length){var t=arguments[0];this.mergeLabel(t,0),this.mergeLabel(t,1)}else if(2===arguments.length){var e=arguments[1],n=arguments[0].getLocation(e,Z.RIGHT);if(n===W.NONE)return null;if(this.Nu.getLocation(e)===W.NONE)return this.Nu.setLocation(e,n),null}}},{key:"setShell",value:function(t){this.vu=t,null!==t&&t.addHole(this)}},{key:"toPolygon",value:function(t){for(var e=new Array(this.mu.size()).fill(null),n=0;n<this.mu.size();n++)e[n]=this.mu.get(n).getLinearRing();return t.createPolygon(this.getLinearRing(),e)}}],[{key:"constructor_",value:function(){if(this.Uu=null,this.ju=-1,this.qu=new pt,this.Fu=new pt,this.Nu=new $e(W.NONE),this.Ru=null,this.Du=null,this.vu=null,this.mu=new pt,this.Pu=null,0===arguments.length);else if(2===arguments.length){var t=arguments[0],e=arguments[1];this.Pu=e,this.computePoints(t),this.computeRing()}}}]),Me=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"setEdgeRing",value:function(t,e){t.setMinEdgeRing(e)}},{key:"getNext",value:function(t){return t.getNextMin()}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Se.constructor_.call(this,t,e)}}])}(Se),Ee=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"buildMinimalRings",value:function(){var t=new pt,e=this.Uu;do{if(null===e.getMinEdgeRing()){var n=new Me(e,this.Pu);t.add(n)}e=e.getNext()}while(e!==this.Uu);return t}},{key:"setEdgeRing",value:function(t,e){t.setEdgeRing(e)}},{key:"linkDirectedEdgesForMinimalEdgeRings",value:function(){var t=this.Uu;do{t.getNode().getEdges().linkMinimalDirectedEdges(this),t=t.getNext()}while(t!==this.Uu)}},{key:"getNext",value:function(t){return t.getNext()}}],[{key:"constructor_",value:function(){var t=arguments[0],e=arguments[1];Se.constructor_.call(this,t,e)}}])}(Se),Ce=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"setVisited",value:function(t){this.Bu=t}},{key:"setInResult",value:function(t){this.Lu=t}},{key:"isCovered",value:function(){return this.Hu}},{key:"isCoveredSet",value:function(){return this.Wu}},{key:"setLabel",value:function(t){this.Nu=t}},{key:"getLabel",value:function(){return this.Nu}},{key:"setCovered",value:function(t){this.Hu=t,this.Wu=!0}},{key:"updateIM",value:function(t){D.isTrue(this.Nu.getGeometryCount()>=2,"found partial label"),this.computeIM(t)}},{key:"isInResult",value:function(){return this.Lu}},{key:"isVisited",value:function(){return this.Bu}}],[{key:"constructor_",value:function(){if(this.Nu=null,this.Lu=!1,this.Hu=!1,this.Wu=!1,this.Bu=!1,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.Nu=t}}}]),Ae=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"isIncidentEdgeInResult",value:function(){for(var t=this.getEdges().getEdges().iterator();t.hasNext();)if(t.next().getEdge().isInResult())return!0;return!1}},{key:"isIsolated",value:function(){return 1===this.Nu.getGeometryCount()}},{key:"getCoordinate",value:function(){return this.Ti}},{key:"print",value:function(t){t.println("node "+this.Ti+" lbl: "+this.Nu)}},{key:"computeIM",value:function(t){}},{key:"computeMergedLocation",value:function(t,e){var n=W.NONE;if(n=this.Nu.getLocation(e),!t.isNull(e)){var i=t.getLocation(e);n!==W.BOUNDARY&&(n=i)}return n}},{key:"setLabel",value:function(){if(2!==arguments.length||!Number.isInteger(arguments[1])||!Number.isInteger(arguments[0]))return f(i,"setLabel",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1];null===this.Nu?this.Nu=new $e(t,e):this.Nu.setLocation(t,e)}},{key:"getEdges",value:function(){return this.qu}},{key:"mergeLabel",value:function(){if(arguments[0]instanceof i){var t=arguments[0];this.mergeLabel(t.Nu)}else if(arguments[0]instanceof $e)for(var e=arguments[0],n=0;n<2;n++){var r=this.computeMergedLocation(e,n);this.Nu.getLocation(n)===W.NONE&&this.Nu.setLocation(n,r)}}},{key:"add",value:function(t){this.qu.insert(t),t.setNode(this)}},{key:"setLabelBoundary",value:function(t){if(null===this.Nu)return null;var e=W.NONE;null!==this.Nu&&(e=this.Nu.getLocation(t));var n=null;switch(e){case W.BOUNDARY:n=W.INTERIOR;break;case W.INTERIOR:default:n=W.BOUNDARY}this.Nu.setLocation(t,n)}}],[{key:"constructor_",value:function(){this.Ti=null,this.qu=null;var t=arguments[0],e=arguments[1];this.Ti=t,this.qu=e,this.Nu=new $e(0,W.NONE)}}])}(Ce),Oe=function(t){function i(){return n(this,i),e(this,i,arguments)}return h(i,t),s(i)}(te);function Ie(t){return null==t?0:t.color}function Te(t){return null==t?null:t.parent}function ze(t,e){null!==t&&(t.color=e)}function Re(t){return null==t?null:t.left}function Fe(t){return null==t?null:t.right}var Pe=function(t){function i(){var t;return n(this,i),(t=e(this,i)).root_=null,t.size_=0,t}return h(i,t),s(i,[{key:"get",value:function(t){for(var e=this.root_;null!==e;){var n=t.compareTo(e.key);if(n<0)e=e.left;else{if(!(n>0))return e.value;e=e.right}}return null}},{key:"put",value:function(t,e){if(null===this.root_)return this.root_={key:t,value:e,left:null,right:null,parent:null,color:0,getValue:function(){return this.value},getKey:function(){return this.key}},this.size_=1,null;var n,i,r=this.root_;do{if(n=r,(i=t.compareTo(r.key))<0)r=r.left;else{if(!(i>0)){var s=r.value;return r.value=e,s}r=r.right}}while(null!==r);var o={key:t,left:null,right:null,value:e,parent:n,color:0,getValue:function(){return this.value},getKey:function(){return this.key}};return i<0?n.left=o:n.right=o,this.fixAfterInsertion(o),this.size_++,null}},{key:"fixAfterInsertion",value:function(t){var e;for(t.color=1;null!=t&&t!==this.root_&&1===t.parent.color;)Te(t)===Re(Te(Te(t)))?1===Ie(e=Fe(Te(Te(t))))?(ze(Te(t),0),ze(e,0),ze(Te(Te(t)),1),t=Te(Te(t))):(t===Fe(Te(t))&&(t=Te(t),this.rotateLeft(t)),ze(Te(t),0),ze(Te(Te(t)),1),this.rotateRight(Te(Te(t)))):1===Ie(e=Re(Te(Te(t))))?(ze(Te(t),0),ze(e,0),ze(Te(Te(t)),1),t=Te(Te(t))):(t===Re(Te(t))&&(t=Te(t),this.rotateRight(t)),ze(Te(t),0),ze(Te(Te(t)),1),this.rotateLeft(Te(Te(t))));this.root_.color=0}},{key:"values",value:function(){var t=new pt,e=this.getFirstEntry();if(null!==e)for(t.add(e.value);null!==(e=i.successor(e));)t.add(e.value);return t}},{key:"entrySet",value:function(){var t=new X,e=this.getFirstEntry();if(null!==e)for(t.add(e);null!==(e=i.successor(e));)t.add(e);return t}},{key:"rotateLeft",value:function(t){if(null!=t){var e=t.right;t.right=e.left,null!=e.left&&(e.left.parent=t),e.parent=t.parent,null==t.parent?this.root_=e:t.parent.left===t?t.parent.left=e:t.parent.right=e,e.left=t,t.parent=e}}},{key:"rotateRight",value:function(t){if(null!=t){var e=t.left;t.left=e.right,null!=e.right&&(e.right.parent=t),e.parent=t.parent,null==t.parent?this.root_=e:t.parent.right===t?t.parent.right=e:t.parent.left=e,e.right=t,t.parent=e}}},{key:"getFirstEntry",value:function(){var t=this.root_;if(null!=t)for(;null!=t.left;)t=t.left;return t}},{key:"size",value:function(){return this.size_}},{key:"containsKey",value:function(t){for(var e=this.root_;null!==e;){var n=t.compareTo(e.key);if(n<0)e=e.left;else{if(!(n>0))return!0;e=e.right}}return!1}}],[{key:"successor",value:function(t){var e;if(null===t)return null;if(null!==t.right){for(e=t.right;null!==e.left;)e=e.left;return e}e=t.parent;for(var n=t;null!==e&&n===e.right;)n=e,e=e.parent;return e}}])}(Oe),De=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"find",value:function(t){return this.nodeMap.get(t)}},{key:"addNode",value:function(){if(arguments[0]instanceof j){var t=arguments[0],e=this.nodeMap.get(t);return null===e&&(e=this.nodeFact.createNode(t),this.nodeMap.put(t,e)),e}if(arguments[0]instanceof Ae){var n=arguments[0],i=this.nodeMap.get(n.getCoordinate());return null===i?(this.nodeMap.put(n.getCoordinate(),n),n):(i.mergeLabel(n),i)}}},{key:"print",value:function(t){for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"iterator",value:function(){return this.nodeMap.values().iterator()}},{key:"values",value:function(){return this.nodeMap.values()}},{key:"getBoundaryNodes",value:function(t){for(var e=new pt,n=this.iterator();n.hasNext();){var i=n.next();i.getLabel().getLocation(t)===W.BOUNDARY&&e.add(i)}return e}},{key:"add",value:function(t){var e=t.getCoordinate();this.addNode(e).add(t)}}],[{key:"constructor_",value:function(){this.nodeMap=new Pe,this.nodeFact=null;var t=arguments[0];this.nodeFact=t}}]),Ne=function(){function t(){n(this,t)}return s(t,null,[{key:"isNorthern",value:function(e){return e===t.NE||e===t.NW}},{key:"isOpposite",value:function(t,e){return t!==e&&2==(t-e+4)%4}},{key:"commonHalfPlane",value:function(t,e){if(t===e)return t;if(2==(t-e+4)%4)return-1;var n=t<e?t:e;return 0===n&&3===(t>e?t:e)?3:n}},{key:"isInHalfPlane",value:function(e,n){return n===t.SE?e===t.SE||e===t.SW:e===n||e===n+1}},{key:"quadrant",value:function(){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1];if(0===e&&0===n)throw new g("Cannot compute the quadrant for point ( "+e+", "+n+" )");return e>=0?n>=0?t.NE:t.SE:n>=0?t.NW:t.SW}if(arguments[0]instanceof j&&arguments[1]instanceof j){var i=arguments[0],r=arguments[1];if(r.x===i.x&&r.y===i.y)throw new g("Cannot compute the quadrant for two identical points "+i);return r.x>=i.x?r.y>=i.y?t.NE:t.SE:r.y>=i.y?t.NW:t.SW}}}])}();Ne.NE=0,Ne.NW=1,Ne.SW=2,Ne.SE=3;var Ue=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"compareDirection",value:function(t){return this.Vu===t.Vu&&this.Gu===t.Gu?0:this.Yu>t.Yu?1:this.Yu<t.Yu?-1:lt.index(t.Ku,t.Xu,this.Xu)}},{key:"getDy",value:function(){return this.Gu}},{key:"getCoordinate",value:function(){return this.Ku}},{key:"setNode",value:function(t){this.Qu=t}},{key:"print",value:function(t){var e=Math.atan2(this.Gu,this.Vu),n=this.getClass().getName(),i=n.lastIndexOf("."),r=n.substring(i+1);t.print(" "+r+": "+this.Ku+" - "+this.Xu+" "+this.Yu+":"+e+" "+this.Nu)}},{key:"compareTo",value:function(t){var e=t;return this.compareDirection(e)}},{key:"getDirectedCoordinate",value:function(){return this.Xu}},{key:"getDx",value:function(){return this.Vu}},{key:"getLabel",value:function(){return this.Nu}},{key:"getEdge",value:function(){return this.Zu}},{key:"getQuadrant",value:function(){return this.Yu}},{key:"getNode",value:function(){return this.Qu}},{key:"toString",value:function(){var t=Math.atan2(this.Gu,this.Vu),e=this.getClass().getName(),n=e.lastIndexOf(".");return" "+e.substring(n+1)+": "+this.Ku+" - "+this.Xu+" "+this.Yu+":"+t+" "+this.Nu}},{key:"computeLabel",value:function(t){}},{key:"init",value:function(t,e){this.Ku=t,this.Xu=e,this.Vu=e.x-t.x,this.Gu=e.y-t.y,this.Yu=Ne.quadrant(this.Vu,this.Gu),D.isTrue(!(0===this.Vu&&0===this.Gu),"EdgeEnd with identical endpoints found")}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){if(this.Zu=null,this.Nu=null,this.Qu=null,this.Ku=null,this.Xu=null,this.Vu=null,this.Gu=null,this.Yu=null,1===arguments.length){var e=arguments[0];this.Zu=e}else if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];t.constructor_.call(this,n,i,r,null)}else if(4===arguments.length){var s=arguments[0],o=arguments[1],a=arguments[2],u=arguments[3];t.constructor_.call(this,s),this.init(o,a),this.Nu=u}}}])}(),qe=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getNextMin",value:function(){return this.Ju}},{key:"getDepth",value:function(t){return this.th[t]}},{key:"setVisited",value:function(t){this.Bu=t}},{key:"computeDirectedLabel",value:function(){this.Nu=new $e(this.Zu.getLabel()),this.eh||this.Nu.flip()}},{key:"getNext",value:function(){return this.nh}},{key:"setDepth",value:function(t,e){if(-999!==this.th[t]&&this.th[t]!==e)throw new ft("assigned depths do not match",this.getCoordinate());this.th[t]=e}},{key:"isInteriorAreaEdge",value:function(){for(var t=!0,e=0;e<2;e++)this.Nu.isArea(e)&&this.Nu.getLocation(e,Z.LEFT)===W.INTERIOR&&this.Nu.getLocation(e,Z.RIGHT)===W.INTERIOR||(t=!1);return t}},{key:"setNextMin",value:function(t){this.Ju=t}},{key:"print",value:function(t){f(i,"print",this,1).call(this,t),t.print(" "+this.th[Z.LEFT]+"/"+this.th[Z.RIGHT]),t.print(" ("+this.getDepthDelta()+")"),this.Lu&&t.print(" inResult")}},{key:"setMinEdgeRing",value:function(t){this.ih=t}},{key:"isLineEdge",value:function(){var t=this.Nu.isLine(0)||this.Nu.isLine(1),e=!this.Nu.isArea(0)||this.Nu.allPositionsEqual(0,W.EXTERIOR),n=!this.Nu.isArea(1)||this.Nu.allPositionsEqual(1,W.EXTERIOR);return t&&e&&n}},{key:"setEdgeRing",value:function(t){this.rh=t}},{key:"getMinEdgeRing",value:function(){return this.ih}},{key:"getDepthDelta",value:function(){var t=this.Zu.getDepthDelta();return this.eh||(t=-t),t}},{key:"setInResult",value:function(t){this.Lu=t}},{key:"getSym",value:function(){return this.sh}},{key:"isForward",value:function(){return this.eh}},{key:"getEdge",value:function(){return this.Zu}},{key:"printEdge",value:function(t){this.print(t),t.print(" "),this.eh?this.Zu.print(t):this.Zu.printReverse(t)}},{key:"setSym",value:function(t){this.sh=t}},{key:"setVisitedEdge",value:function(t){this.setVisited(t),this.sh.setVisited(t)}},{key:"setEdgeDepths",value:function(t,e){var n=this.getEdge().getDepthDelta();this.eh||(n=-n);var i=1;t===Z.LEFT&&(i=-1);var r=Z.opposite(t),s=e+n*i;this.setDepth(t,e),this.setDepth(r,s)}},{key:"getEdgeRing",value:function(){return this.rh}},{key:"isInResult",value:function(){return this.Lu}},{key:"setNext",value:function(t){this.nh=t}},{key:"isVisited",value:function(){return this.Bu}}],[{key:"constructor_",value:function(){this.eh=null,this.Lu=!1,this.Bu=!1,this.sh=null,this.nh=null,this.Ju=null,this.rh=null,this.ih=null,this.th=[0,-999,-999];var t=arguments[0],e=arguments[1];if(Ue.constructor_.call(this,t),this.eh=e,e)this.init(t.getCoordinate(0),t.getCoordinate(1));else{var n=t.getNumPoints()-1;this.init(t.getCoordinate(n),t.getCoordinate(n-1))}this.computeDirectedLabel()}},{key:"depthFactor",value:function(t,e){return t===W.EXTERIOR&&e===W.INTERIOR?1:t===W.INTERIOR&&e===W.EXTERIOR?-1:0}}])}(Ue),je=s((function t(){n(this,t)}),[{key:"createNode",value:function(t){return new Ae(t,null)}}]),Be=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"printEdges",value:function(t){t.println("Edges:");for(var e=0;e<this.qu.size();e++){t.println("edge "+e+":");var n=this.qu.get(e);n.print(t),n.eiList.print(t)}}},{key:"find",value:function(t){return this.du.find(t)}},{key:"addNode",value:function(){if(arguments[0]instanceof Ae){var t=arguments[0];return this.du.addNode(t)}if(arguments[0]instanceof j){var e=arguments[0];return this.du.addNode(e)}}},{key:"getNodeIterator",value:function(){return this.du.iterator()}},{key:"linkResultDirectedEdges",value:function(){for(var t=this.du.iterator();t.hasNext();)t.next().getEdges().linkResultDirectedEdges()}},{key:"debugPrintln",value:function(t){wt.out.println(t)}},{key:"isBoundaryNode",value:function(t,e){var n=this.du.find(e);if(null===n)return!1;var i=n.getLabel();return null!==i&&i.getLocation(t)===W.BOUNDARY}},{key:"linkAllDirectedEdges",value:function(){for(var t=this.du.iterator();t.hasNext();)t.next().getEdges().linkAllDirectedEdges()}},{key:"matchInSameDirection",value:function(t,e,n,i){return!!t.equals(n)&<.index(t,e,i)===lt.COLLINEAR&&Ne.quadrant(t,e)===Ne.quadrant(n,i)}},{key:"getEdgeEnds",value:function(){return this.oh}},{key:"debugPrint",value:function(t){wt.out.print(t)}},{key:"getEdgeIterator",value:function(){return this.qu.iterator()}},{key:"findEdgeInSameDirection",value:function(t,e){for(var n=0;n<this.qu.size();n++){var i=this.qu.get(n),r=i.getCoordinates();if(this.matchInSameDirection(t,e,r[0],r[1]))return i;if(this.matchInSameDirection(t,e,r[r.length-1],r[r.length-2]))return i}return null}},{key:"insertEdge",value:function(t){this.qu.add(t)}},{key:"findEdgeEnd",value:function(t){for(var e=this.getEdgeEnds().iterator();e.hasNext();){var n=e.next();if(n.getEdge()===t)return n}return null}},{key:"addEdges",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next();this.qu.add(n);var i=new qe(n,!0),r=new qe(n,!1);i.setSym(r),r.setSym(i),this.add(i),this.add(r)}}},{key:"add",value:function(t){this.du.add(t),this.oh.add(t)}},{key:"getNodes",value:function(){return this.du.values()}},{key:"findEdge",value:function(t,e){for(var n=0;n<this.qu.size();n++){var i=this.qu.get(n),r=i.getCoordinates();if(t.equals(r[0])&&e.equals(r[1]))return i}return null}}],[{key:"constructor_",value:function(){if(this.qu=new pt,this.du=null,this.oh=new pt,0===arguments.length)this.du=new De(new je);else if(1===arguments.length){var t=arguments[0];this.du=new De(t)}}},{key:"linkResultDirectedEdges",value:function(t){for(var e=t.iterator();e.hasNext();)e.next().getEdges().linkResultDirectedEdges()}}]),Le=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"sortShellsAndHoles",value:function(t,e,n){for(var i=t.iterator();i.hasNext();){var r=i.next();r.isHole()?n.add(r):e.add(r)}}},{key:"computePolygons",value:function(t){for(var e=new pt,n=t.iterator();n.hasNext();){var i=n.next().toPolygon(this.Pu);e.add(i)}return e}},{key:"placeFreeHoles",value:function(e,n){for(var i=n.iterator();i.hasNext();){var r=i.next();if(null===r.getShell()){var s=t.findEdgeRingContaining(r,e);if(null===s)throw new ft("unable to assign hole to a shell",r.getCoordinate(0));r.setShell(s)}}}},{key:"buildMinimalEdgeRings",value:function(t,e,n){for(var i=new pt,r=t.iterator();r.hasNext();){var s=r.next();if(s.getMaxNodeDegree()>2){s.linkDirectedEdgesForMinimalEdgeRings();var o=s.buildMinimalRings(),a=this.findShell(o);null!==a?(this.placePolygonHoles(a,o),e.add(a)):n.addAll(o)}else i.add(s)}return i}},{key:"buildMaximalEdgeRings",value:function(t){for(var e=new pt,n=t.iterator();n.hasNext();){var i=n.next();if(i.isInResult()&&i.getLabel().isArea()&&null===i.getEdgeRing()){var r=new Ee(i,this.Pu);e.add(r),r.setInResult()}}return e}},{key:"placePolygonHoles",value:function(t,e){for(var n=e.iterator();n.hasNext();){var i=n.next();i.isHole()&&i.setShell(t)}}},{key:"getPolygons",value:function(){return this.computePolygons(this.ah)}},{key:"findShell",value:function(t){for(var e=0,n=null,i=t.iterator();i.hasNext();){var r=i.next();r.isHole()||(n=r,e++)}return D.isTrue(e<=1,"found two shells in MinimalEdgeRing list"),n}},{key:"add",value:function(){if(1===arguments.length){var t=arguments[0];this.add(t.getEdgeEnds(),t.getNodes())}else if(2===arguments.length){var e=arguments[0],n=arguments[1];Be.linkResultDirectedEdges(n);var i=this.buildMaximalEdgeRings(e),r=new pt,s=this.buildMinimalEdgeRings(i,this.ah,r);this.sortShellsAndHoles(s,this.ah,r),this.placeFreeHoles(this.ah,r)}}}],[{key:"constructor_",value:function(){this.Pu=null,this.ah=new pt;var t=arguments[0];this.Pu=t}},{key:"findEdgeRingContaining",value:function(t,e){for(var n=t.getLinearRing(),i=n.getEnvelopeInternal(),r=n.getCoordinateN(0),s=null,o=null,a=e.iterator();a.hasNext();){var u=a.next(),h=u.getLinearRing(),l=h.getEnvelopeInternal();if(!l.equals(i)&&l.contains(i)){r=Gt.ptNotInList(n.getCoordinates(),h.getCoordinates());var c=!1;xe.isInRing(r,h.getCoordinates())&&(c=!0),c&&(null===s||o.contains(l))&&(o=(s=u).getLinearRing().getEnvelopeInternal())}}return s}}])}(),He=s((function t(){n(this,t)}),[{key:"getBounds",value:function(){}}]),We=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getItem",value:function(){return this.uh}},{key:"getBounds",value:function(){return this.hh}},{key:"interfaces_",get:function(){return[He,k]}}],[{key:"constructor_",value:function(){this.hh=null,this.uh=null;var t=arguments[0],e=arguments[1];this.hh=t,this.uh=e}}]),Ve=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"poll",value:function(){if(this.isEmpty())return null;var t=this.fh.get(1);return this.fh.set(1,this.fh.get(this.Hi)),this.Hi-=1,this.reorder(1),t}},{key:"size",value:function(){return this.Hi}},{key:"reorder",value:function(t){for(var e=null,n=this.fh.get(t);2*t<=this.Hi&&((e=2*t)!==this.Hi&&this.fh.get(e+1).compareTo(this.fh.get(e))<0&&e++,this.fh.get(e).compareTo(n)<0);t=e)this.fh.set(t,this.fh.get(e));this.fh.set(t,n)}},{key:"clear",value:function(){this.Hi=0,this.fh.clear()}},{key:"peek",value:function(){return this.isEmpty()?null:this.fh.get(1)}},{key:"isEmpty",value:function(){return 0===this.Hi}},{key:"add",value:function(t){this.fh.add(null),this.Hi+=1;var e=this.Hi;for(this.fh.set(0,t);t.compareTo(this.fh.get(Math.trunc(e/2)))<0;e/=2)this.fh.set(e,this.fh.get(Math.trunc(e/2)));this.fh.set(e,t)}}],[{key:"constructor_",value:function(){this.Hi=null,this.fh=null,this.Hi=0,this.fh=new pt,this.fh.add(null)}}]),Ge=s((function t(){n(this,t)}),[{key:"insert",value:function(t,e){}},{key:"remove",value:function(t,e){}},{key:"query",value:function(){}}]),Ye=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getLevel",value:function(){return this.dh}},{key:"size",value:function(){return this.ph.size()}},{key:"getChildBoundables",value:function(){return this.ph}},{key:"addChildBoundable",value:function(t){D.isTrue(null===this.hh),this.ph.add(t)}},{key:"isEmpty",value:function(){return this.ph.isEmpty()}},{key:"getBounds",value:function(){return null===this.hh&&(this.hh=this.computeBounds()),this.hh}},{key:"interfaces_",get:function(){return[He,k]}}],[{key:"constructor_",value:function(){if(this.ph=new pt,this.hh=null,this.dh=null,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.dh=t}}}]),Ke={reverseOrder:function(){return{compare:function(t,e){return e.compareTo(t)}}},min:function(t){return Ke.sort(t),t.get(0)},sort:function(t,e){var n=t.toArray();e?zt.sort(n,e):zt.sort(n);for(var i=t.iterator(),r=0,s=n.length;r<s;r++)i.next(),i.set(n[r])},singletonList:function(t){var e=new pt;return e.add(t),e}},Xe=function(){function t(){n(this,t)}return s(t,null,[{key:"maxDistance",value:function(e,n,i,r,s,o,a,u){var h=t.distance(e,n,s,o);return h=Math.max(h,t.distance(e,n,a,u)),h=Math.max(h,t.distance(i,r,s,o)),Math.max(h,t.distance(i,r,a,u))}},{key:"distance",value:function(t,e,n,i){var r=n-t,s=i-e;return Math.sqrt(r*r+s*s)}},{key:"maximumDistance",value:function(e,n){var i=Math.min(e.getMinX(),n.getMinX()),r=Math.min(e.getMinY(),n.getMinY()),s=Math.max(e.getMaxX(),n.getMaxX()),o=Math.max(e.getMaxY(),n.getMaxY());return t.distance(i,r,s,o)}},{key:"minMaxDistance",value:function(e,n){var i=e.getMinX(),r=e.getMinY(),s=e.getMaxX(),o=e.getMaxY(),a=n.getMinX(),u=n.getMinY(),h=n.getMaxX(),l=n.getMaxY(),c=t.maxDistance(i,r,i,o,a,u,a,l);return c=Math.min(c,t.maxDistance(i,r,i,o,a,u,h,u)),c=Math.min(c,t.maxDistance(i,r,i,o,h,l,a,l)),c=Math.min(c,t.maxDistance(i,r,i,o,h,l,h,u)),c=Math.min(c,t.maxDistance(i,r,s,r,a,u,a,l)),c=Math.min(c,t.maxDistance(i,r,s,r,a,u,h,u)),c=Math.min(c,t.maxDistance(i,r,s,r,h,l,a,l)),c=Math.min(c,t.maxDistance(i,r,s,r,h,l,h,u)),c=Math.min(c,t.maxDistance(s,o,i,o,a,u,a,l)),c=Math.min(c,t.maxDistance(s,o,i,o,a,u,h,u)),c=Math.min(c,t.maxDistance(s,o,i,o,h,l,a,l)),c=Math.min(c,t.maxDistance(s,o,i,o,h,l,h,u)),c=Math.min(c,t.maxDistance(s,o,s,r,a,u,a,l)),c=Math.min(c,t.maxDistance(s,o,s,r,a,u,h,u)),c=Math.min(c,t.maxDistance(s,o,s,r,h,l,a,l)),Math.min(c,t.maxDistance(s,o,s,r,h,l,h,u))}}])}(),Qe=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"maximumDistance",value:function(){return Xe.maximumDistance(this.mh.getBounds(),this.yh.getBounds())}},{key:"expandToQueue",value:function(e,n){var i=t.isComposite(this.mh),r=t.isComposite(this.yh);if(i&&r)return t.area(this.mh)>t.area(this.yh)?(this.expand(this.mh,this.yh,!1,e,n),null):(this.expand(this.yh,this.mh,!0,e,n),null);if(i)return this.expand(this.mh,this.yh,!1,e,n),null;if(r)return this.expand(this.yh,this.mh,!0,e,n),null;throw new g("neither boundable is composite")}},{key:"isLeaves",value:function(){return!(t.isComposite(this.mh)||t.isComposite(this.yh))}},{key:"compareTo",value:function(t){var e=t;return this.wh<e.wh?-1:this.wh>e.wh?1:0}},{key:"expand",value:function(e,n,i,r,s){for(var o=e.getChildBoundables().iterator();o.hasNext();){var a=o.next(),u=null;(u=i?new t(n,a,this.gh):new t(a,n,this.gh)).getDistance()<s&&r.add(u)}}},{key:"getBoundable",value:function(t){return 0===t?this.mh:this.yh}},{key:"getDistance",value:function(){return this.wh}},{key:"distance",value:function(){return this.isLeaves()?this.gh.distance(this.mh,this.yh):this.mh.getBounds().distance(this.yh.getBounds())}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.mh=null,this.yh=null,this.wh=null,this.gh=null;var t=arguments[0],e=arguments[1],n=arguments[2];this.mh=t,this.yh=e,this.gh=n,this.wh=this.distance()}},{key:"area",value:function(t){return t.getBounds().getArea()}},{key:"isComposite",value:function(t){return t instanceof Ye}}])}(),Ze=s((function t(){n(this,t)}),[{key:"visitItem",value:function(t){}}]),Je=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"queryInternal",value:function(){if(it(arguments[2],Ze)&&arguments[0]instanceof Object&&arguments[1]instanceof Ye)for(var t=arguments[0],e=arguments[2],n=arguments[1].getChildBoundables(),i=0;i<n.size();i++){var r=n.get(i);this.getIntersectsOp().intersects(r.getBounds(),t)&&(r instanceof Ye?this.queryInternal(t,r,e):r instanceof We?e.visitItem(r.getItem()):D.shouldNeverReachHere())}else if(it(arguments[2],et)&&arguments[0]instanceof Object&&arguments[1]instanceof Ye)for(var s=arguments[0],o=arguments[2],a=arguments[1].getChildBoundables(),u=0;u<a.size();u++){var h=a.get(u);this.getIntersectsOp().intersects(h.getBounds(),s)&&(h instanceof Ye?this.queryInternal(s,h,o):h instanceof We?o.add(h.getItem()):D.shouldNeverReachHere())}}},{key:"getNodeCapacity",value:function(){return this.bh}},{key:"lastNode",value:function(t){return t.get(t.size()-1)}},{key:"size",value:function(){if(0===arguments.length)return this.isEmpty()?0:(this.build(),this.size(this._root));if(1===arguments.length){for(var t=0,e=arguments[0].getChildBoundables().iterator();e.hasNext();){var n=e.next();n instanceof Ye?t+=this.size(n):n instanceof We&&(t+=1)}return t}}},{key:"removeItem",value:function(t,e){for(var n=null,i=t.getChildBoundables().iterator();i.hasNext();){var r=i.next();r instanceof We&&r.getItem()===e&&(n=r)}return null!==n&&(t.getChildBoundables().remove(n),!0)}},{key:"itemsTree",value:function(){if(0===arguments.length){this.build();var t=this.itemsTree(this._root);return null===t?new pt:t}if(1===arguments.length){for(var e=arguments[0],n=new pt,i=e.getChildBoundables().iterator();i.hasNext();){var r=i.next();if(r instanceof Ye){var s=this.itemsTree(r);null!==s&&n.add(s)}else r instanceof We?n.add(r.getItem()):D.shouldNeverReachHere()}return n.size()<=0?null:n}}},{key:"insert",value:function(t,e){D.isTrue(!this._h,"Cannot insert items into an STR packed R-tree after it has been built."),this.xh.add(new We(t,e))}},{key:"boundablesAtLevel",value:function(){if(1===arguments.length){var t=arguments[0],e=new pt;return this.boundablesAtLevel(t,this._root,e),e}if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2];if(D.isTrue(n>-2),i.getLevel()===n)return r.add(i),null;for(var s=i.getChildBoundables().iterator();s.hasNext();){var o=s.next();o instanceof Ye?this.boundablesAtLevel(n,o,r):(D.isTrue(o instanceof We),-1===n&&r.add(o))}return null}}},{key:"query",value:function(){if(1===arguments.length){var t=arguments[0];this.build();var e=new pt;return this.isEmpty()||this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.queryInternal(t,this._root,e),e}if(2===arguments.length){var n=arguments[0],i=arguments[1];if(this.build(),this.isEmpty())return null;this.getIntersectsOp().intersects(this._root.getBounds(),n)&&this.queryInternal(n,this._root,i)}}},{key:"build",value:function(){if(this._h)return null;this._root=this.xh.isEmpty()?this.createNode(0):this.createHigherLevels(this.xh,-1),this.xh=null,this._h=!0}},{key:"getRoot",value:function(){return this.build(),this._root}},{key:"remove",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];return this.build(),!!this.getIntersectsOp().intersects(this._root.getBounds(),t)&&this.remove(t,this._root,e)}if(3===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2],s=this.removeItem(i,r);if(s)return!0;for(var o=null,a=i.getChildBoundables().iterator();a.hasNext();){var u=a.next();if(this.getIntersectsOp().intersects(u.getBounds(),n)&&u instanceof Ye&&(s=this.remove(n,u,r))){o=u;break}}return null!==o&&o.getChildBoundables().isEmpty()&&i.getChildBoundables().remove(o),s}}},{key:"createHigherLevels",value:function(t,e){D.isTrue(!t.isEmpty());var n=this.createParentBoundables(t,e+1);return 1===n.size()?n.get(0):this.createHigherLevels(n,e+1)}},{key:"depth",value:function(){if(0===arguments.length)return this.isEmpty()?0:(this.build(),this.depth(this._root));if(1===arguments.length){for(var t=0,e=arguments[0].getChildBoundables().iterator();e.hasNext();){var n=e.next();if(n instanceof Ye){var i=this.depth(n);i>t&&(t=i)}}return t+1}}},{key:"createParentBoundables",value:function(t,e){D.isTrue(!t.isEmpty());var n=new pt;n.add(this.createNode(e));var i=new pt(t);Ke.sort(i,this.getComparator());for(var r=i.iterator();r.hasNext();){var s=r.next();this.lastNode(n).getChildBoundables().size()===this.getNodeCapacity()&&n.add(this.createNode(e)),this.lastNode(n).addChildBoundable(s)}return n}},{key:"isEmpty",value:function(){return this._h?this._root.isEmpty():this.xh.isEmpty()}},{key:"interfaces_",get:function(){return[k]}}],[{key:"constructor_",value:function(){if(this._root=null,this._h=!1,this.xh=new pt,this.bh=null,0===arguments.length)t.constructor_.call(this,t.DEFAULT_NODE_CAPACITY);else if(1===arguments.length){var e=arguments[0];D.isTrue(e>1,"Node capacity must be greater than 1"),this.bh=e}}},{key:"compareDoubles",value:function(t,e){return t>e?1:t<e?-1:0}}])}();Je.IntersectsOp=function(){},Je.DEFAULT_NODE_CAPACITY=10;var tn=s((function t(){n(this,t)}),[{key:"distance",value:function(t,e){}}]),en=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"createParentBoundablesFromVerticalSlices",value:function(t,e){D.isTrue(t.length>0);for(var n=new pt,i=0;i<t.length;i++)n.addAll(this.createParentBoundablesFromVerticalSlice(t[i],e));return n}},{key:"nearestNeighbourK",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];return this.nearestNeighbourK(t,z.POSITIVE_INFINITY,e)}if(3===arguments.length){var n=arguments[0],r=arguments[2],s=arguments[1],o=new Ve;o.add(n);for(var a=new Ve;!o.isEmpty()&&s>=0;){var u=o.poll(),h=u.getDistance();if(h>=s)break;u.isLeaves()?a.size()<r?a.add(u):(a.peek().getDistance()>h&&(a.poll(),a.add(u)),s=a.peek().getDistance()):u.expandToQueue(o,s)}return i.getItems(a)}}},{key:"createNode",value:function(t){return new nn(t)}},{key:"size",value:function(){return 0===arguments.length?f(i,"size",this,1).call(this):f(i,"size",this,1).apply(this,arguments)}},{key:"insert",value:function(){if(!(2===arguments.length&&arguments[1]instanceof Object&&arguments[0]instanceof L))return f(i,"insert",this,1).apply(this,arguments);var t=arguments[0],e=arguments[1];if(t.isNull())return null;f(i,"insert",this,1).call(this,t,e)}},{key:"getIntersectsOp",value:function(){return i.intersectsOp}},{key:"verticalSlices",value:function(t,e){for(var n=Math.trunc(Math.ceil(t.size()/e)),i=new Array(e).fill(null),r=t.iterator(),s=0;s<e;s++){i[s]=new pt;for(var o=0;r.hasNext()&&o<n;){var a=r.next();i[s].add(a),o++}}return i}},{key:"query",value:function(){if(1===arguments.length){var t=arguments[0];return f(i,"query",this,1).call(this,t)}if(2===arguments.length){var e=arguments[0],n=arguments[1];f(i,"query",this,1).call(this,e,n)}}},{key:"getComparator",value:function(){return i.yComparator}},{key:"createParentBoundablesFromVerticalSlice",value:function(t,e){return f(i,"createParentBoundables",this,1).call(this,t,e)}},{key:"remove",value:function(){if(2===arguments.length&&arguments[1]instanceof Object&&arguments[0]instanceof L){var t=arguments[0],e=arguments[1];return f(i,"remove",this,1).call(this,t,e)}return f(i,"remove",this,1).apply(this,arguments)}},{key:"depth",value:function(){return 0===arguments.length?f(i,"depth",this,1).call(this):f(i,"depth",this,1).apply(this,arguments)}},{key:"createParentBoundables",value:function(t,e){D.isTrue(!t.isEmpty());var n=Math.trunc(Math.ceil(t.size()/this.getNodeCapacity())),r=new pt(t);Ke.sort(r,i.xComparator);var s=this.verticalSlices(r,Math.trunc(Math.ceil(Math.sqrt(n))));return this.createParentBoundablesFromVerticalSlices(s,e)}},{key:"nearestNeighbour",value:function(){if(1===arguments.length){if(it(arguments[0],tn)){var t=arguments[0];if(this.isEmpty())return null;var e=new Qe(this.getRoot(),this.getRoot(),t);return this.nearestNeighbour(e)}if(arguments[0]instanceof Qe){var n=arguments[0],i=z.POSITIVE_INFINITY,r=null,s=new Ve;for(s.add(n);!s.isEmpty()&&i>0;){var o=s.poll(),a=o.getDistance();if(a>=i)break;o.isLeaves()?(i=a,r=o):o.expandToQueue(s,i)}return null===r?null:[r.getBoundable(0).getItem(),r.getBoundable(1).getItem()]}}else{if(2===arguments.length){var u=arguments[0],h=arguments[1];if(this.isEmpty()||u.isEmpty())return null;var l=new Qe(this.getRoot(),u.getRoot(),h);return this.nearestNeighbour(l)}if(3===arguments.length){var c=arguments[2],f=new We(arguments[0],arguments[1]),d=new Qe(this.getRoot(),f,c);return this.nearestNeighbour(d)[0]}if(4===arguments.length){var p=arguments[2],v=arguments[3],m=new We(arguments[0],arguments[1]),y=new Qe(this.getRoot(),m,p);return this.nearestNeighbourK(y,v)}}}},{key:"isWithinDistance",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1],n=z.POSITIVE_INFINITY,i=new Ve;for(i.add(t);!i.isEmpty();){var r=i.poll(),s=r.getDistance();if(s>e)return!1;if(r.maximumDistance()<=e)return!0;if(r.isLeaves()){if((n=s)<=e)return!0}else r.expandToQueue(i,n)}return!1}if(3===arguments.length){var o=arguments[0],a=arguments[1],u=arguments[2],h=new Qe(this.getRoot(),o.getRoot(),a);return this.isWithinDistance(h,u)}}},{key:"interfaces_",get:function(){return[Ge,k]}}],[{key:"constructor_",value:function(){if(0===arguments.length)i.constructor_.call(this,i.DEFAULT_NODE_CAPACITY);else if(1===arguments.length){var t=arguments[0];Je.constructor_.call(this,t)}}},{key:"centreX",value:function(t){return i.avg(t.getMinX(),t.getMaxX())}},{key:"avg",value:function(t,e){return(t+e)/2}},{key:"getItems",value:function(t){for(var e=new Array(t.size()).fill(null),n=0;!t.isEmpty();){var i=t.poll();e[n]=i.getBoundable(0).getItem(),n++}return e}},{key:"centreY",value:function(t){return i.avg(t.getMinY(),t.getMaxY())}}])}(Je),nn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"computeBounds",value:function(){for(var t=null,e=this.getChildBoundables().iterator();e.hasNext();){var n=e.next();null===t?t=new L(n.getBounds()):t.expandToInclude(n.getBounds())}return t}}],[{key:"constructor_",value:function(){var t=arguments[0];Ye.constructor_.call(this,t)}}])}(Ye);en.STRtreeNode=nn,en.xComparator=new(s((function t(){n(this,t)}),[{key:"interfaces_",get:function(){return[R]}},{key:"compare",value:function(t,e){return Je.compareDoubles(en.centreX(t.getBounds()),en.centreX(e.getBounds()))}}])),en.yComparator=new(s((function t(){n(this,t)}),[{key:"interfaces_",get:function(){return[R]}},{key:"compare",value:function(t,e){return Je.compareDoubles(en.centreY(t.getBounds()),en.centreY(e.getBounds()))}}])),en.intersectsOp=new(s((function t(){n(this,t)}),[{key:"interfaces_",get:function(){return[IntersectsOp]}},{key:"intersects",value:function(t,e){return t.intersects(e)}}])),en.DEFAULT_NODE_CAPACITY=10;var rn=function(){function t(){n(this,t)}return s(t,null,[{key:"relativeSign",value:function(t,e){return t<e?-1:t>e?1:0}},{key:"compare",value:function(e,n,i){if(n.equals2D(i))return 0;var r=t.relativeSign(n.x,i.x),s=t.relativeSign(n.y,i.y);switch(e){case 0:return t.compareValue(r,s);case 1:return t.compareValue(s,r);case 2:return t.compareValue(s,-r);case 3:return t.compareValue(-r,s);case 4:return t.compareValue(-r,-s);case 5:return t.compareValue(-s,-r);case 6:return t.compareValue(-s,r);case 7:return t.compareValue(r,-s)}return D.shouldNeverReachHere("invalid octant value"),0}},{key:"compareValue",value:function(t,e){return t<0?-1:t>0?1:e<0?-1:e>0?1:0}}])}(),sn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex)}},{key:"compareTo",value:function(t){var e=t;return this.segmentIndex<e.segmentIndex?-1:this.segmentIndex>e.segmentIndex?1:this.coord.equals2D(e.coord)?0:this.kh?e.kh?rn.compare(this.$h,this.coord,e.coord):1:-1}},{key:"isEndPoint",value:function(t){return 0===this.segmentIndex&&!this.kh||this.segmentIndex===t}},{key:"toString",value:function(){return this.segmentIndex+":"+this.coord.toString()}},{key:"isInterior",value:function(){return this.kh}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.Sh=null,this.coord=null,this.segmentIndex=null,this.$h=null,this.kh=null;var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this.Sh=t,this.coord=new j(e),this.segmentIndex=n,this.$h=i,this.kh=!e.equals2D(t.getCoordinate(n))}}]),on=s((function t(){n(this,t)}),[{key:"hasNext",value:function(){}},{key:"next",value:function(){}},{key:"remove",value:function(){}}]),an=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getSplitCoordinates",value:function(){var t=new Vt;this.addEndpoints();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next();this.addEdgeCoordinates(n,i,t),n=i}return t.toCoordinateArray()}},{key:"addCollapsedNodes",value:function(){var t=new pt;this.findCollapsesFromInsertedNodes(t),this.findCollapsesFromExistingVertices(t);for(var e=t.iterator();e.hasNext();){var n=e.next().intValue();this.add(this.Zu.getCoordinate(n),n)}}},{key:"createSplitEdgePts",value:function(t,e){var n=e.segmentIndex-t.segmentIndex+2;if(2===n)return[new j(t.coord),new j(e.coord)];var i=this.Zu.getCoordinate(e.segmentIndex),r=e.isInterior()||!e.coord.equals2D(i);r||n--;var s=new Array(n).fill(null),o=0;s[o++]=new j(t.coord);for(var a=t.segmentIndex+1;a<=e.segmentIndex;a++)s[o++]=this.Zu.getCoordinate(a);return r&&(s[o]=new j(e.coord)),s}},{key:"print",value:function(t){t.println("Intersections:");for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"findCollapsesFromExistingVertices",value:function(t){for(var e=0;e<this.Zu.size()-2;e++){var n=this.Zu.getCoordinate(e);this.Zu.getCoordinate(e+1);var i=this.Zu.getCoordinate(e+2);n.equals2D(i)&&t.add(st.valueOf(e+1))}}},{key:"addEdgeCoordinates",value:function(t,e,n){var i=this.createSplitEdgePts(t,e);n.add(i,!1)}},{key:"iterator",value:function(){return this.Mh.values().iterator()}},{key:"addSplitEdges",value:function(t){this.addEndpoints(),this.addCollapsedNodes();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next(),r=this.createSplitEdge(n,i);t.add(r),n=i}}},{key:"findCollapseIndex",value:function(t,e,n){if(!t.coord.equals2D(e.coord))return!1;var i=e.segmentIndex-t.segmentIndex;return e.isInterior()||i--,1===i&&(n[0]=t.segmentIndex+1,!0)}},{key:"findCollapsesFromInsertedNodes",value:function(t){for(var e=new Array(1).fill(null),n=this.iterator(),i=n.next();n.hasNext();){var r=n.next();this.findCollapseIndex(i,r,e)&&t.add(st.valueOf(e[0])),i=r}}},{key:"getEdge",value:function(){return this.Zu}},{key:"addEndpoints",value:function(){var t=this.Zu.size()-1;this.add(this.Zu.getCoordinate(0),0),this.add(this.Zu.getCoordinate(t),t)}},{key:"createSplitEdge",value:function(t,e){var n=this.createSplitEdgePts(t,e);return new cn(n,this.Zu.getData())}},{key:"add",value:function(t,e){var n=new sn(this.Zu,t,e,this.Zu.getSegmentOctant(e)),i=this.Mh.get(n);return null!==i?(D.isTrue(i.coord.equals2D(t),"Found equal nodes with different coordinates"),i):(this.Mh.put(n,n),n)}},{key:"checkSplitEdgesCorrectness",value:function(t){var e=this.Zu.getCoordinates(),n=t.get(0).getCoordinate(0);if(!n.equals2D(e[0]))throw new F("bad split edge start point at "+n);var i=t.get(t.size()-1).getCoordinates(),r=i[i.length-1];if(!r.equals2D(e[e.length-1]))throw new F("bad split edge end point at "+r)}}],[{key:"constructor_",value:function(){this.Mh=new Pe,this.Zu=null;var t=arguments[0];this.Zu=t}}]),un=function(){function t(){n(this,t)}return s(t,null,[{key:"octant",value:function(){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var e=arguments[0],n=arguments[1];if(0===e&&0===n)throw new g("Cannot compute the octant for point ( "+e+", "+n+" )");var i=Math.abs(e),r=Math.abs(n);return e>=0?n>=0?i>=r?0:1:i>=r?7:6:n>=0?i>=r?3:2:i>=r?4:5}if(arguments[0]instanceof j&&arguments[1]instanceof j){var s=arguments[0],o=arguments[1],a=o.x-s.x,u=o.y-s.y;if(0===a&&0===u)throw new g("Cannot compute the octant for two identical points "+s);return t.octant(a,u)}}}])}(),hn=s((function t(){n(this,t)}),[{key:"getCoordinates",value:function(){}},{key:"size",value:function(){}},{key:"getCoordinate",value:function(t){}},{key:"isClosed",value:function(){}},{key:"setData",value:function(t){}},{key:"getData",value:function(){}}]),ln=s((function t(){n(this,t)}),[{key:"addIntersection",value:function(t,e){}},{key:"interfaces_",get:function(){return[hn]}}]),cn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getCoordinates",value:function(){return this.Fu}},{key:"size",value:function(){return this.Fu.length}},{key:"getCoordinate",value:function(t){return this.Fu[t]}},{key:"isClosed",value:function(){return this.Fu[0].equals(this.Fu[this.Fu.length-1])}},{key:"getSegmentOctant",value:function(t){return t===this.Fu.length-1?-1:this.safeOctant(this.getCoordinate(t),this.getCoordinate(t+1))}},{key:"setData",value:function(t){this.Ve=t}},{key:"safeOctant",value:function(t,e){return t.equals2D(e)?0:un.octant(t,e)}},{key:"getData",value:function(){return this.Ve}},{key:"addIntersection",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.addIntersectionNode(t,e)}else if(4===arguments.length){var n=arguments[1],i=arguments[3],r=new j(arguments[0].getIntersection(i));this.addIntersection(r,n)}}},{key:"toString",value:function(){return we.toLineString(new Qt(this.Fu))}},{key:"getNodeList",value:function(){return this.Eh}},{key:"addIntersectionNode",value:function(t,e){var n=e,i=n+1;if(i<this.Fu.length){var r=this.Fu[i];t.equals2D(r)&&(n=i)}return this.Eh.add(t,n)}},{key:"addIntersections",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++)this.addIntersection(t,e,n,i)}},{key:"interfaces_",get:function(){return[ln]}}],[{key:"constructor_",value:function(){this.Eh=new an(this),this.Fu=null,this.Ve=null;var t=arguments[0],e=arguments[1];this.Fu=t,this.Ve=e}},{key:"getNodedSubstrings",value:function(){if(1===arguments.length){var e=arguments[0],n=new pt;return t.getNodedSubstrings(e,n),n}if(2===arguments.length)for(var i=arguments[1],r=arguments[0].iterator();r.hasNext();)r.next().getNodeList().addSplitEdges(i)}}])}(),fn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"minX",value:function(){return Math.min(this.p0.x,this.p1.x)}},{key:"orientationIndex",value:function(){if(arguments[0]instanceof t){var e=arguments[0],n=lt.index(this.p0,this.p1,e.p0),i=lt.index(this.p0,this.p1,e.p1);return n>=0&&i>=0||n<=0&&i<=0?Math.max(n,i):0}if(arguments[0]instanceof j){var r=arguments[0];return lt.index(this.p0,this.p1,r)}}},{key:"toGeometry",value:function(t){return t.createLineString([this.p0,this.p1])}},{key:"isVertical",value:function(){return this.p0.x===this.p1.x}},{key:"equals",value:function(e){if(!(e instanceof t))return!1;var n=e;return this.p0.equals(n.p0)&&this.p1.equals(n.p1)}},{key:"intersection",value:function(t){var e=new be;return e.computeIntersection(this.p0,this.p1,t.p0,t.p1),e.hasIntersection()?e.getIntersection(0):null}},{key:"project",value:function(){if(arguments[0]instanceof j){var e=arguments[0];if(e.equals(this.p0)||e.equals(this.p1))return new j(e);var n=this.projectionFactor(e),i=new j;return i.x=this.p0.x+n*(this.p1.x-this.p0.x),i.y=this.p0.y+n*(this.p1.y-this.p0.y),i}if(arguments[0]instanceof t){var r=arguments[0],s=this.projectionFactor(r.p0),o=this.projectionFactor(r.p1);if(s>=1&&o>=1)return null;if(s<=0&&o<=0)return null;var a=this.project(r.p0);s<0&&(a=this.p0),s>1&&(a=this.p1);var u=this.project(r.p1);return o<0&&(u=this.p0),o>1&&(u=this.p1),new t(a,u)}}},{key:"normalize",value:function(){this.p1.compareTo(this.p0)<0&&this.reverse()}},{key:"angle",value:function(){return Math.atan2(this.p1.y-this.p0.y,this.p1.x-this.p0.x)}},{key:"getCoordinate",value:function(t){return 0===t?this.p0:this.p1}},{key:"distancePerpendicular",value:function(t){return bt.pointToLinePerpendicular(t,this.p0,this.p1)}},{key:"minY",value:function(){return Math.min(this.p0.y,this.p1.y)}},{key:"midPoint",value:function(){return t.midPoint(this.p0,this.p1)}},{key:"projectionFactor",value:function(t){if(t.equals(this.p0))return 0;if(t.equals(this.p1))return 1;var e=this.p1.x-this.p0.x,n=this.p1.y-this.p0.y,i=e*e+n*n;return i<=0?z.NaN:((t.x-this.p0.x)*e+(t.y-this.p0.y)*n)/i}},{key:"closestPoints",value:function(t){var e=this.intersection(t);if(null!==e)return[e,e];var n=new Array(2).fill(null),i=z.MAX_VALUE,r=null,s=this.closestPoint(t.p0);i=s.distance(t.p0),n[0]=s,n[1]=t.p0;var o=this.closestPoint(t.p1);(r=o.distance(t.p1))<i&&(i=r,n[0]=o,n[1]=t.p1);var a=t.closestPoint(this.p0);(r=a.distance(this.p0))<i&&(i=r,n[0]=this.p0,n[1]=a);var u=t.closestPoint(this.p1);return(r=u.distance(this.p1))<i&&(i=r,n[0]=this.p1,n[1]=u),n}},{key:"closestPoint",value:function(t){var e=this.projectionFactor(t);return e>0&&e<1?this.project(t):this.p0.distance(t)<this.p1.distance(t)?this.p0:this.p1}},{key:"maxX",value:function(){return Math.max(this.p0.x,this.p1.x)}},{key:"getLength",value:function(){return this.p0.distance(this.p1)}},{key:"compareTo",value:function(t){var e=t,n=this.p0.compareTo(e.p0);return 0!==n?n:this.p1.compareTo(e.p1)}},{key:"reverse",value:function(){var t=this.p0;this.p0=this.p1,this.p1=t}},{key:"equalsTopo",value:function(t){return this.p0.equals(t.p0)&&this.p1.equals(t.p1)||this.p0.equals(t.p1)&&this.p1.equals(t.p0)}},{key:"lineIntersection",value:function(t){return yt.intersection(this.p0,this.p1,t.p0,t.p1)}},{key:"maxY",value:function(){return Math.max(this.p0.y,this.p1.y)}},{key:"pointAlongOffset",value:function(t,e){var n=this.p0.x+t*(this.p1.x-this.p0.x),i=this.p0.y+t*(this.p1.y-this.p0.y),r=this.p1.x-this.p0.x,s=this.p1.y-this.p0.y,o=Math.sqrt(r*r+s*s),a=0,u=0;if(0!==e){if(o<=0)throw new IllegalStateException("Cannot compute offset from zero-length line segment");a=e*r/o,u=e*s/o}return new j(n-u,i+a)}},{key:"setCoordinates",value:function(){if(1===arguments.length){var t=arguments[0];this.setCoordinates(t.p0,t.p1)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.p0.x=e.x,this.p0.y=e.y,this.p1.x=n.x,this.p1.y=n.y}}},{key:"segmentFraction",value:function(t){var e=this.projectionFactor(t);return e<0?e=0:(e>1||z.isNaN(e))&&(e=1),e}},{key:"toString",value:function(){return"LINESTRING( "+this.p0.x+" "+this.p0.y+", "+this.p1.x+" "+this.p1.y+")"}},{key:"isHorizontal",value:function(){return this.p0.y===this.p1.y}},{key:"reflect",value:function(t){var e=this.p1.getY()-this.p0.getY(),n=this.p0.getX()-this.p1.getX(),i=this.p0.getY()*(this.p1.getX()-this.p0.getX())-this.p0.getX()*(this.p1.getY()-this.p0.getY()),r=e*e+n*n,s=e*e-n*n,o=t.getX(),a=t.getY();return new j((-s*o-2*e*n*a-2*e*i)/r,(s*a-2*e*n*o-2*n*i)/r)}},{key:"distance",value:function(){if(arguments[0]instanceof t){var e=arguments[0];return bt.segmentToSegment(this.p0,this.p1,e.p0,e.p1)}if(arguments[0]instanceof j){var n=arguments[0];return bt.pointToSegment(n,this.p0,this.p1)}}},{key:"pointAlong",value:function(t){var e=new j;return e.x=this.p0.x+t*(this.p1.x-this.p0.x),e.y=this.p0.y+t*(this.p1.y-this.p0.y),e}},{key:"hashCode",value:function(){var t=z.doubleToLongBits(this.p0.x);t^=31*z.doubleToLongBits(this.p0.y);var e=Math.trunc(t)^Math.trunc(t>>32),n=z.doubleToLongBits(this.p1.x);return n^=31*z.doubleToLongBits(this.p1.y),e^Math.trunc(n)^Math.trunc(n>>32)}},{key:"interfaces_",get:function(){return[_,k]}}],[{key:"constructor_",value:function(){if(this.p0=null,this.p1=null,0===arguments.length)t.constructor_.call(this,new j,new j);else if(1===arguments.length){var e=arguments[0];t.constructor_.call(this,e.p0,e.p1)}else if(2===arguments.length){var n=arguments[0],i=arguments[1];this.p0=n,this.p1=i}else if(4===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2],a=arguments[3];t.constructor_.call(this,new j(r,s),new j(o,a))}}},{key:"midPoint",value:function(t,e){return new j((t.x+e.x)/2,(t.y+e.y)/2)}}])}(),dn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"overlap",value:function(){if(2===arguments.length);else if(4===arguments.length){var t=arguments[1],e=arguments[2],n=arguments[3];arguments[0].getLineSegment(t,this.Ch),e.getLineSegment(n,this.Ah),this.overlap(this.Ch,this.Ah)}}}],[{key:"constructor_",value:function(){this.Ch=new fn,this.Ah=new fn}}]),pn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getLineSegment",value:function(t,e){e.p0=this.Fu[t],e.p1=this.Fu[t+1]}},{key:"computeSelect",value:function(t,e,n,i){var r=this.Fu[e],s=this.Fu[n];if(n-e==1)return i.select(this,e),null;if(!t.intersects(r,s))return null;var o=Math.trunc((e+n)/2);e<o&&this.computeSelect(t,e,o,i),o<n&&this.computeSelect(t,o,n,i)}},{key:"getCoordinates",value:function(){for(var t=new Array(this.Oh-this.Ih+1).fill(null),e=0,n=this.Ih;n<=this.Oh;n++)t[e++]=this.Fu[n];return t}},{key:"computeOverlaps",value:function(){if(2===arguments.length){var t=arguments[0],e=arguments[1];this.computeOverlaps(this.Ih,this.Oh,t,t.Ih,t.Oh,e)}else if(6===arguments.length){var n=arguments[0],i=arguments[1],r=arguments[2],s=arguments[3],o=arguments[4],a=arguments[5];if(i-n==1&&o-s==1)return a.overlap(this,n,r,s),null;if(!this.overlaps(n,i,r,s,o))return null;var u=Math.trunc((n+i)/2),h=Math.trunc((s+o)/2);n<u&&(s<h&&this.computeOverlaps(n,u,r,s,h,a),h<o&&this.computeOverlaps(n,u,r,h,o,a)),u<i&&(s<h&&this.computeOverlaps(u,i,r,s,h,a),h<o&&this.computeOverlaps(u,i,r,h,o,a))}}},{key:"setId",value:function(t){this._id=t}},{key:"select",value:function(t,e){this.computeSelect(t,this.Ih,this.Oh,e)}},{key:"getEnvelope",value:function(){if(null===this.fu){var t=this.Fu[this.Ih],e=this.Fu[this.Oh];this.fu=new L(t,e)}return this.fu}},{key:"overlaps",value:function(t,e,n,i,r){return L.intersects(this.Fu[t],this.Fu[e],n.Fu[i],n.Fu[r])}},{key:"getEndIndex",value:function(){return this.Oh}},{key:"getStartIndex",value:function(){return this.Ih}},{key:"getContext",value:function(){return this.fe}},{key:"getId",value:function(){return this._id}}],[{key:"constructor_",value:function(){this.Fu=null,this.Ih=null,this.Oh=null,this.fu=null,this.fe=null,this._id=null;var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this.Fu=t,this.Ih=e,this.Oh=n,this.fe=i}}]),vn=function(){function t(){n(this,t)}return s(t,null,[{key:"findChainEnd",value:function(t,e){for(var n=e;n<t.length-1&&t[n].equals2D(t[n+1]);)n++;if(n>=t.length-1)return t.length-1;for(var i=Ne.quadrant(t[n],t[n+1]),r=e+1;r<t.length&&(t[r-1].equals2D(t[r])||Ne.quadrant(t[r-1],t[r])===i);)r++;return r-1}},{key:"getChains",value:function(){if(1===arguments.length){var e=arguments[0];return t.getChains(e,null)}if(2===arguments.length){var n=arguments[0],i=arguments[1],r=new pt,s=0;do{var o=t.findChainEnd(n,s),a=new pn(n,s,o,i);r.add(a),s=o}while(s<n.length-1);return r}}}])}(),mn=s((function t(){n(this,t)}),[{key:"computeNodes",value:function(t){}},{key:"getNodedSubstrings",value:function(){}}]),yn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"setSegmentIntersector",value:function(t){this.Th=t}},{key:"interfaces_",get:function(){return[mn]}}],[{key:"constructor_",value:function(){if(this.Th=null,0===arguments.length);else if(1===arguments.length){var t=arguments[0];this.setSegmentIntersector(t)}}}]),wn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getMonotoneChains",value:function(){return this.zh}},{key:"getNodedSubstrings",value:function(){return cn.getNodedSubstrings(this.Rh)}},{key:"getIndex",value:function(){return this._index}},{key:"add",value:function(t){for(var e=vn.getChains(t.getCoordinates(),t).iterator();e.hasNext();){var n=e.next();n.setId(this.Fh++),this._index.insert(n.getEnvelope(),n),this.zh.add(n)}}},{key:"computeNodes",value:function(t){this.Rh=t;for(var e=t.iterator();e.hasNext();)this.add(e.next());this.intersectChains()}},{key:"intersectChains",value:function(){for(var t=new gn(this.Th),e=this.zh.iterator();e.hasNext();)for(var n=e.next(),i=this._index.query(n.getEnvelope()).iterator();i.hasNext();){var r=i.next();if(r.getId()>n.getId()&&(n.computeOverlaps(r,t),this.Ph++),this.Th.isDone())return null}}}],[{key:"constructor_",value:function(){if(this.zh=new pt,this._index=new en,this.Fh=0,this.Rh=null,this.Ph=0,0===arguments.length);else if(1===arguments.length){var t=arguments[0];yn.constructor_.call(this,t)}}}])}(yn),gn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"overlap",value:function(){if(4!==arguments.length)return f(i,"overlap",this,1).apply(this,arguments);var t=arguments[1],e=arguments[2],n=arguments[3],r=arguments[0].getContext(),s=e.getContext();this.Dh.processIntersections(r,t,s,n)}}],[{key:"constructor_",value:function(){this.Dh=null;var t=arguments[0];this.Dh=t}}])}(dn);wn.SegmentOverlapAction=gn;var bn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"isDeletable",value:function(t,e,n,i){var r=this.Nh[t],s=this.Nh[e],o=this.Nh[n];return!!this.isConcave(r,s,o)&&!!this.isShallow(r,s,o,i)&&this.isShallowSampled(r,s,t,n,i)}},{key:"deleteShallowConcavities",value:function(){for(var e=1,n=this.findNextNonDeletedIndex(e),i=this.findNextNonDeletedIndex(n),r=!1;i<this.Nh.length;){var s=!1;this.isDeletable(e,n,i,this.Uh)&&(this.Ur[n]=t.DELETE,s=!0,r=!0),e=s?i:n,n=this.findNextNonDeletedIndex(e),i=this.findNextNonDeletedIndex(n)}return r}},{key:"isShallowConcavity",value:function(t,e,n,i){return lt.index(t,e,n)===this.qh&&bt.pointToSegment(e,t,n)<i}},{key:"isShallowSampled",value:function(e,n,i,r,s){var o=Math.trunc((r-i)/t.NUM_PTS_TO_CHECK);o<=0&&(o=1);for(var a=i;a<r;a+=o)if(!this.isShallow(e,n,this.Nh[a],s))return!1;return!0}},{key:"isConcave",value:function(t,e,n){return lt.index(t,e,n)===this.qh}},{key:"simplify",value:function(t){this.Uh=Math.abs(t),t<0&&(this.qh=lt.CLOCKWISE),this.Ur=new Array(this.Nh.length).fill(null);var e=!1;do{e=this.deleteShallowConcavities()}while(e);return this.collapseLine()}},{key:"findNextNonDeletedIndex",value:function(e){for(var n=e+1;n<this.Nh.length&&this.Ur[n]===t.DELETE;)n++;return n}},{key:"isShallow",value:function(t,e,n,i){return bt.pointToSegment(e,t,n)<i}},{key:"collapseLine",value:function(){for(var e=new Vt,n=0;n<this.Nh.length;n++)this.Ur[n]!==t.DELETE&&e.add(this.Nh[n]);return e.toCoordinateArray()}}],[{key:"constructor_",value:function(){this.Nh=null,this.Uh=null,this.Ur=null,this.qh=lt.COUNTERCLOCKWISE;var t=arguments[0];this.Nh=t}},{key:"simplify",value:function(e,n){return new t(e).simplify(n)}}])}();bn.INIT=0,bn.DELETE=1,bn.KEEP=1,bn.NUM_PTS_TO_CHECK=10;var _n=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getCoordinates",value:function(){return this.jh.toArray(t.COORDINATE_ARRAY_TYPE)}},{key:"setPrecisionModel",value:function(t){this.ku=t}},{key:"addPt",value:function(t){var e=new j(t);if(this.ku.makePrecise(e),this.isRedundant(e))return null;this.jh.add(e)}},{key:"reverse",value:function(){}},{key:"addPts",value:function(t,e){if(e)for(var n=0;n<t.length;n++)this.addPt(t[n]);else for(var i=t.length-1;i>=0;i--)this.addPt(t[i])}},{key:"isRedundant",value:function(t){if(this.jh.size()<1)return!1;var e=this.jh.get(this.jh.size()-1);return t.distance(e)<this.Bh}},{key:"toString",value:function(){return(new se).createLineString(this.getCoordinates()).toString()}},{key:"closeRing",value:function(){if(this.jh.size()<1)return null;var t=new j(this.jh.get(0)),e=this.jh.get(this.jh.size()-1);if(t.equals(e))return null;this.jh.add(t)}},{key:"setMinimumVertexDistance",value:function(t){this.Bh=t}}],[{key:"constructor_",value:function(){this.jh=null,this.ku=null,this.Bh=0,this.jh=new pt}}])}();_n.COORDINATE_ARRAY_TYPE=new Array(0).fill(null);var xn=function(){function t(){n(this,t)}return s(t,null,[{key:"toDegrees",value:function(t){return 180*t/Math.PI}},{key:"normalize",value:function(e){for(;e>Math.PI;)e-=t.PI_TIMES_2;for(;e<=-Math.PI;)e+=t.PI_TIMES_2;return e}},{key:"angle",value:function(){if(1===arguments.length){var t=arguments[0];return Math.atan2(t.y,t.x)}if(2===arguments.length){var e=arguments[0],n=arguments[1],i=n.x-e.x,r=n.y-e.y;return Math.atan2(r,i)}}},{key:"isAcute",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y;return i*(n.x-e.x)+r*(n.y-e.y)>0}},{key:"isObtuse",value:function(t,e,n){var i=t.x-e.x,r=t.y-e.y;return i*(n.x-e.x)+r*(n.y-e.y)<0}},{key:"interiorAngle",value:function(e,n,i){var r=t.angle(n,e),s=t.angle(n,i);return Math.abs(s-r)}},{key:"normalizePositive",value:function(e){if(e<0){for(;e<0;)e+=t.PI_TIMES_2;e>=t.PI_TIMES_2&&(e=0)}else{for(;e>=t.PI_TIMES_2;)e-=t.PI_TIMES_2;e<0&&(e=0)}return e}},{key:"angleBetween",value:function(e,n,i){var r=t.angle(n,e),s=t.angle(n,i);return t.diff(r,s)}},{key:"diff",value:function(t,e){var n=null;return(n=t<e?e-t:t-e)>Math.PI&&(n=2*Math.PI-n),n}},{key:"toRadians",value:function(t){return t*Math.PI/180}},{key:"getTurn",value:function(e,n){var i=Math.sin(n-e);return i>0?t.COUNTERCLOCKWISE:i<0?t.CLOCKWISE:t.NONE}},{key:"angleBetweenOriented",value:function(e,n,i){var r=t.angle(n,e),s=t.angle(n,i)-r;return s<=-Math.PI?s+t.PI_TIMES_2:s>Math.PI?s-t.PI_TIMES_2:s}}])}();xn.PI_TIMES_2=2*Math.PI,xn.PI_OVER_2=Math.PI/2,xn.PI_OVER_4=Math.PI/4,xn.COUNTERCLOCKWISE=lt.COUNTERCLOCKWISE,xn.CLOCKWISE=lt.CLOCKWISE,xn.NONE=lt.COLLINEAR;var kn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"addNextSegment",value:function(t,e){if(this.Lh=this.Hh,this.Hh=this.Wh,this.Wh=t,this.Vh.setCoordinates(this.Lh,this.Hh),this.computeOffsetSegment(this.Vh,this.Gh,this.wh,this.Yh),this.Kh.setCoordinates(this.Hh,this.Wh),this.computeOffsetSegment(this.Kh,this.Gh,this.wh,this.Xh),this.Hh.equals(this.Wh))return null;var n=lt.index(this.Lh,this.Hh,this.Wh),i=n===lt.CLOCKWISE&&this.Gh===Z.LEFT||n===lt.COUNTERCLOCKWISE&&this.Gh===Z.RIGHT;0===n?this.addCollinear(e):i?this.addOutsideTurn(n,e):this.addInsideTurn(n,e)}},{key:"addLineEndCap",value:function(t,e){var n=new fn(t,e),i=new fn;this.computeOffsetSegment(n,Z.LEFT,this.wh,i);var r=new fn;this.computeOffsetSegment(n,Z.RIGHT,this.wh,r);var s=e.x-t.x,o=e.y-t.y,a=Math.atan2(o,s);switch(this.Qh.getEndCapStyle()){case y.CAP_ROUND:this.Zh.addPt(i.p1),this.addDirectedFillet(e,a+Math.PI/2,a-Math.PI/2,lt.CLOCKWISE,this.wh),this.Zh.addPt(r.p1);break;case y.CAP_FLAT:this.Zh.addPt(i.p1),this.Zh.addPt(r.p1);break;case y.CAP_SQUARE:var u=new j;u.x=Math.abs(this.wh)*Math.cos(a),u.y=Math.abs(this.wh)*Math.sin(a);var h=new j(i.p1.x+u.x,i.p1.y+u.y),l=new j(r.p1.x+u.x,r.p1.y+u.y);this.Zh.addPt(h),this.Zh.addPt(l)}}},{key:"getCoordinates",value:function(){return this.Zh.getCoordinates()}},{key:"addMitreJoin",value:function(t,e,n,i){var r=yt.intersection(e.p0,e.p1,n.p0,n.p1);if(null!==r&&(i<=0?1:r.distance(t)/Math.abs(i))<=this.Qh.getMitreLimit())return this.Zh.addPt(r),null;this.addLimitedMitreJoin(e,n,i,this.Qh.getMitreLimit())}},{key:"addOutsideTurn",value:function(e,n){if(this.Yh.p1.distance(this.Xh.p0)<this.wh*t.OFFSET_SEGMENT_SEPARATION_FACTOR)return this.Zh.addPt(this.Yh.p1),null;this.Qh.getJoinStyle()===y.JOIN_MITRE?this.addMitreJoin(this.Hh,this.Yh,this.Xh,this.wh):this.Qh.getJoinStyle()===y.JOIN_BEVEL?this.addBevelJoin(this.Yh,this.Xh):(n&&this.Zh.addPt(this.Yh.p1),this.addCornerFillet(this.Hh,this.Yh.p1,this.Xh.p0,e,this.wh),this.Zh.addPt(this.Xh.p0))}},{key:"createSquare",value:function(t){this.Zh.addPt(new j(t.x+this.wh,t.y+this.wh)),this.Zh.addPt(new j(t.x+this.wh,t.y-this.wh)),this.Zh.addPt(new j(t.x-this.wh,t.y-this.wh)),this.Zh.addPt(new j(t.x-this.wh,t.y+this.wh)),this.Zh.closeRing()}},{key:"addSegments",value:function(t,e){this.Zh.addPts(t,e)}},{key:"addFirstSegment",value:function(){this.Zh.addPt(this.Xh.p0)}},{key:"addCornerFillet",value:function(t,e,n,i,r){var s=e.x-t.x,o=e.y-t.y,a=Math.atan2(o,s),u=n.x-t.x,h=n.y-t.y,l=Math.atan2(h,u);i===lt.CLOCKWISE?a<=l&&(a+=2*Math.PI):a>=l&&(a-=2*Math.PI),this.Zh.addPt(e),this.addDirectedFillet(t,a,l,i,r),this.Zh.addPt(n)}},{key:"addLastSegment",value:function(){this.Zh.addPt(this.Xh.p1)}},{key:"initSideSegments",value:function(t,e,n){this.Hh=t,this.Wh=e,this.Gh=n,this.Kh.setCoordinates(t,e),this.computeOffsetSegment(this.Kh,n,this.wh,this.Xh)}},{key:"addLimitedMitreJoin",value:function(t,e,n,i){var r=this.Vh.p1,s=xn.angle(r,this.Vh.p0),o=xn.angleBetweenOriented(this.Vh.p0,r,this.Kh.p1)/2,a=xn.normalize(s+o),u=xn.normalize(a+Math.PI),h=i*n,l=n-h*Math.abs(Math.sin(o)),c=r.x+h*Math.cos(u),f=r.y+h*Math.sin(u),d=new j(c,f),p=new fn(r,d),v=p.pointAlongOffset(1,l),m=p.pointAlongOffset(1,-l);this.Gh===Z.LEFT?(this.Zh.addPt(v),this.Zh.addPt(m)):(this.Zh.addPt(m),this.Zh.addPt(v))}},{key:"addDirectedFillet",value:function(t,e,n,i,r){var s=i===lt.CLOCKWISE?-1:1,o=Math.abs(e-n),a=Math.trunc(o/this.Jh+.5);if(a<1)return null;for(var u=o/a,h=new j,l=0;l<a;l++){var c=e+s*l*u;h.x=t.x+r*Math.cos(c),h.y=t.y+r*Math.sin(c),this.Zh.addPt(h)}}},{key:"computeOffsetSegment",value:function(t,e,n,i){var r=e===Z.LEFT?1:-1,s=t.p1.x-t.p0.x,o=t.p1.y-t.p0.y,a=Math.sqrt(s*s+o*o),u=r*n*s/a,h=r*n*o/a;i.p0.x=t.p0.x-h,i.p0.y=t.p0.y+u,i.p1.x=t.p1.x-h,i.p1.y=t.p1.y+u}},{key:"addInsideTurn",value:function(e,n){if(this.el.computeIntersection(this.Yh.p0,this.Yh.p1,this.Xh.p0,this.Xh.p1),this.el.hasIntersection())this.Zh.addPt(this.el.getIntersection(0));else if(this.nl=!0,this.Yh.p1.distance(this.Xh.p0)<this.wh*t.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR)this.Zh.addPt(this.Yh.p1);else{if(this.Zh.addPt(this.Yh.p1),this.il>0){var i=new j((this.il*this.Yh.p1.x+this.Hh.x)/(this.il+1),(this.il*this.Yh.p1.y+this.Hh.y)/(this.il+1));this.Zh.addPt(i);var r=new j((this.il*this.Xh.p0.x+this.Hh.x)/(this.il+1),(this.il*this.Xh.p0.y+this.Hh.y)/(this.il+1));this.Zh.addPt(r)}else this.Zh.addPt(this.Hh);this.Zh.addPt(this.Xh.p0)}}},{key:"createCircle",value:function(t){var e=new j(t.x+this.wh,t.y);this.Zh.addPt(e),this.addDirectedFillet(t,0,2*Math.PI,-1,this.wh),this.Zh.closeRing()}},{key:"addBevelJoin",value:function(t,e){this.Zh.addPt(t.p1),this.Zh.addPt(e.p0)}},{key:"init",value:function(e){this.wh=e,this.rl=e*(1-Math.cos(this.Jh/2)),this.Zh=new _n,this.Zh.setPrecisionModel(this.ku),this.Zh.setMinimumVertexDistance(e*t.CURVE_VERTEX_SNAP_DISTANCE_FACTOR)}},{key:"addCollinear",value:function(t){this.el.computeIntersection(this.Lh,this.Hh,this.Hh,this.Wh),this.el.getIntersectionNum()>=2&&(this.Qh.getJoinStyle()===y.JOIN_BEVEL||this.Qh.getJoinStyle()===y.JOIN_MITRE?(t&&this.Zh.addPt(this.Yh.p1),this.Zh.addPt(this.Xh.p0)):this.addCornerFillet(this.Hh,this.Yh.p1,this.Xh.p0,lt.CLOCKWISE,this.wh))}},{key:"closeRing",value:function(){this.Zh.closeRing()}},{key:"hasNarrowConcaveAngle",value:function(){return this.nl}}],[{key:"constructor_",value:function(){this.rl=0,this.Jh=null,this.il=1,this.Zh=null,this.wh=0,this.ku=null,this.Qh=null,this.el=null,this.Lh=null,this.Hh=null,this.Wh=null,this.Vh=new fn,this.Kh=new fn,this.Yh=new fn,this.Xh=new fn,this.Gh=0,this.nl=!1;var e=arguments[0],n=arguments[1],i=arguments[2];this.ku=e,this.Qh=n,this.el=new be,this.Jh=Math.PI/2/n.getQuadrantSegments(),n.getQuadrantSegments()>=8&&n.getJoinStyle()===y.JOIN_ROUND&&(this.il=t.MAX_CLOSING_SEG_LEN_FACTOR),this.init(i)}}])}();kn.OFFSET_SEGMENT_SEPARATION_FACTOR=.001,kn.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR=.001,kn.CURVE_VERTEX_SNAP_DISTANCE_FACTOR=1e-6,kn.MAX_CLOSING_SEG_LEN_FACTOR=80;var $n=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getOffsetCurve",value:function(t,e){if(this.wh=e,0===e)return null;var n=e<0,i=Math.abs(e),r=this.getSegGen(i);t.length<=1?this.computePointCurve(t[0],r):this.computeOffsetCurve(t,n,r);var s=r.getCoordinates();return n&&Gt.reverse(s),s}},{key:"computeSingleSidedBufferCurve",value:function(t,e,n){var i=this.simplifyTolerance(this.wh);if(e){n.addSegments(t,!0);var r=bn.simplify(t,-i),s=r.length-1;n.initSideSegments(r[s],r[s-1],Z.LEFT),n.addFirstSegment();for(var o=s-2;o>=0;o--)n.addNextSegment(r[o],!0)}else{n.addSegments(t,!1);var a=bn.simplify(t,i),u=a.length-1;n.initSideSegments(a[0],a[1],Z.LEFT),n.addFirstSegment();for(var h=2;h<=u;h++)n.addNextSegment(a[h],!0)}n.addLastSegment(),n.closeRing()}},{key:"computeRingBufferCurve",value:function(t,e,n){var i=this.simplifyTolerance(this.wh);e===Z.RIGHT&&(i=-i);var r=bn.simplify(t,i),s=r.length-1;n.initSideSegments(r[s-1],r[0],e);for(var o=1;o<=s;o++){var a=1!==o;n.addNextSegment(r[o],a)}n.closeRing()}},{key:"computeLineBufferCurve",value:function(t,e){var n=this.simplifyTolerance(this.wh),i=bn.simplify(t,n),r=i.length-1;e.initSideSegments(i[0],i[1],Z.LEFT);for(var s=2;s<=r;s++)e.addNextSegment(i[s],!0);e.addLastSegment(),e.addLineEndCap(i[r-1],i[r]);var o=bn.simplify(t,-n),a=o.length-1;e.initSideSegments(o[a],o[a-1],Z.LEFT);for(var u=a-2;u>=0;u--)e.addNextSegment(o[u],!0);e.addLastSegment(),e.addLineEndCap(o[1],o[0]),e.closeRing()}},{key:"computePointCurve",value:function(t,e){switch(this.Qh.getEndCapStyle()){case y.CAP_ROUND:e.createCircle(t);break;case y.CAP_SQUARE:e.createSquare(t)}}},{key:"getLineCurve",value:function(t,e){if(this.wh=e,this.isLineOffsetEmpty(e))return null;var n=Math.abs(e),i=this.getSegGen(n);if(t.length<=1)this.computePointCurve(t[0],i);else if(this.Qh.isSingleSided()){var r=e<0;this.computeSingleSidedBufferCurve(t,r,i)}else this.computeLineBufferCurve(t,i);return i.getCoordinates()}},{key:"getBufferParameters",value:function(){return this.Qh}},{key:"simplifyTolerance",value:function(t){return t*this.Qh.getSimplifyFactor()}},{key:"getRingCurve",value:function(e,n,i){if(this.wh=i,e.length<=2)return this.getLineCurve(e,i);if(0===i)return t.copyCoordinates(e);var r=this.getSegGen(i);return this.computeRingBufferCurve(e,n,r),r.getCoordinates()}},{key:"computeOffsetCurve",value:function(t,e,n){var i=this.simplifyTolerance(this.wh);if(e){var r=bn.simplify(t,-i),s=r.length-1;n.initSideSegments(r[s],r[s-1],Z.LEFT),n.addFirstSegment();for(var o=s-2;o>=0;o--)n.addNextSegment(r[o],!0)}else{var a=bn.simplify(t,i),u=a.length-1;n.initSideSegments(a[0],a[1],Z.LEFT),n.addFirstSegment();for(var h=2;h<=u;h++)n.addNextSegment(a[h],!0)}n.addLastSegment()}},{key:"isLineOffsetEmpty",value:function(t){return 0===t||t<0&&!this.Qh.isSingleSided()}},{key:"getSegGen",value:function(t){return new kn(this.ku,this.Qh,t)}}],[{key:"constructor_",value:function(){this.wh=0,this.ku=null,this.Qh=null;var t=arguments[0],e=arguments[1];this.ku=t,this.Qh=e}},{key:"copyCoordinates",value:function(t){for(var e=new Array(t.length).fill(null),n=0;n<e.length;n++)e[n]=new j(t[n]);return e}}])}(),Sn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"findStabbedSegments",value:function(){if(1===arguments.length){for(var t=arguments[0],e=new pt,n=this.sl.iterator();n.hasNext();){var i=n.next(),r=i.getEnvelope();t.y<r.getMinY()||t.y>r.getMaxY()||this.findStabbedSegments(t,i.getDirectedEdges(),e)}return e}if(3===arguments.length)if(it(arguments[2],et)&&arguments[0]instanceof j&&arguments[1]instanceof qe){for(var s=arguments[0],o=arguments[1],a=arguments[2],u=o.getEdge().getCoordinates(),h=0;h<u.length-1;h++)if(this.ol.p0=u[h],this.ol.p1=u[h+1],this.ol.p0.y>this.ol.p1.y&&this.ol.reverse(),!(Math.max(this.ol.p0.x,this.ol.p1.x)<s.x||this.ol.isHorizontal()||s.y<this.ol.p0.y||s.y>this.ol.p1.y||lt.index(this.ol.p0,this.ol.p1,s)===lt.RIGHT)){var l=o.getDepth(Z.LEFT);this.ol.p0.equals(u[h])||(l=o.getDepth(Z.RIGHT));var c=new Mn(this.ol,l);a.add(c)}}else if(it(arguments[2],et)&&arguments[0]instanceof j&&it(arguments[1],et))for(var f=arguments[0],d=arguments[2],p=arguments[1].iterator();p.hasNext();){var v=p.next();v.isForward()&&this.findStabbedSegments(f,v,d)}}},{key:"getDepth",value:function(t){var e=this.findStabbedSegments(t);return 0===e.size()?0:Ke.min(e).al}}],[{key:"constructor_",value:function(){this.sl=null,this.ol=new fn;var t=arguments[0];this.sl=t}}]),Mn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"compareTo",value:function(t){var e=t;if(this.ul.minX()>=e.ul.maxX())return 1;if(this.ul.maxX()<=e.ul.minX())return-1;var n=this.ul.orientationIndex(e.ul);return 0!==n||0!=(n=-1*e.ul.orientationIndex(this.ul))?n:this.ul.compareTo(e.ul)}},{key:"compareX",value:function(t,e){var n=t.p0.compareTo(e.p0);return 0!==n?n:t.p1.compareTo(e.p1)}},{key:"toString",value:function(){return this.ul.toString()}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.ul=null,this.al=null;var t=arguments[0],e=arguments[1];this.ul=new fn(t),this.al=e}}]);Sn.DepthSegment=Mn;var En=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,null,[{key:"constructor_",value:function(){w.constructor_.call(this,"Projective point not representable on the Cartesian plane.")}}])}(w),Cn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getY",value:function(){var t=this.y/this.w;if(z.isNaN(t)||z.isInfinite(t))throw new En;return t}},{key:"getX",value:function(){var t=this.x/this.w;if(z.isNaN(t)||z.isInfinite(t))throw new En;return t}},{key:"getCoordinate",value:function(){var t=new j;return t.x=this.getX(),t.y=this.getY(),t}}],[{key:"constructor_",value:function(){if(this.x=null,this.y=null,this.w=null,0===arguments.length)this.x=0,this.y=0,this.w=1;else if(1===arguments.length){var e=arguments[0];this.x=e.x,this.y=e.y,this.w=1}else if(2===arguments.length){if("number"==typeof arguments[0]&&"number"==typeof arguments[1]){var n=arguments[0],i=arguments[1];this.x=n,this.y=i,this.w=1}else if(arguments[0]instanceof t&&arguments[1]instanceof t){var r=arguments[0],s=arguments[1];this.x=r.y*s.w-s.y*r.w,this.y=s.x*r.w-r.x*s.w,this.w=r.x*s.y-s.x*r.y}else if(arguments[0]instanceof j&&arguments[1]instanceof j){var o=arguments[0],a=arguments[1];this.x=o.y-a.y,this.y=a.x-o.x,this.w=o.x*a.y-a.x*o.y}}else if(3===arguments.length){var u=arguments[0],h=arguments[1],l=arguments[2];this.x=u,this.y=h,this.w=l}else if(4===arguments.length){var c=arguments[0],f=arguments[1],d=arguments[2],p=arguments[3],v=c.y-f.y,m=f.x-c.x,y=c.x*f.y-f.x*c.y,w=d.y-p.y,g=p.x-d.x,b=d.x*p.y-p.x*d.y;this.x=m*b-g*y,this.y=w*y-v*b,this.w=v*g-w*m}}}])}(),An=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"area",value:function(){return t.area(this.p0,this.p1,this.p2)}},{key:"signedArea",value:function(){return t.signedArea(this.p0,this.p1,this.p2)}},{key:"interpolateZ",value:function(e){if(null===e)throw new g("Supplied point is null.");return t.interpolateZ(e,this.p0,this.p1,this.p2)}},{key:"longestSideLength",value:function(){return t.longestSideLength(this.p0,this.p1,this.p2)}},{key:"isAcute",value:function(){return t.isAcute(this.p0,this.p1,this.p2)}},{key:"circumcentre",value:function(){return t.circumcentre(this.p0,this.p1,this.p2)}},{key:"area3D",value:function(){return t.area3D(this.p0,this.p1,this.p2)}},{key:"centroid",value:function(){return t.centroid(this.p0,this.p1,this.p2)}},{key:"inCentre",value:function(){return t.inCentre(this.p0,this.p1,this.p2)}}],[{key:"constructor_",value:function(){this.p0=null,this.p1=null,this.p2=null;var t=arguments[0],e=arguments[1],n=arguments[2];this.p0=t,this.p1=e,this.p2=n}},{key:"area",value:function(t,e,n){return Math.abs(((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2)}},{key:"signedArea",value:function(t,e,n){return((n.x-t.x)*(e.y-t.y)-(e.x-t.x)*(n.y-t.y))/2}},{key:"det",value:function(t,e,n,i){return t*i-e*n}},{key:"interpolateZ",value:function(t,e,n,i){var r=e.x,s=e.y,o=n.x-r,a=i.x-r,u=n.y-s,h=i.y-s,l=o*h-a*u,c=t.x-r,f=t.y-s,d=(h*c-a*f)/l,p=(-u*c+o*f)/l;return e.getZ()+d*(n.getZ()-e.getZ())+p*(i.getZ()-e.getZ())}},{key:"longestSideLength",value:function(t,e,n){var i=t.distance(e),r=e.distance(n),s=n.distance(t),o=i;return r>o&&(o=r),s>o&&(o=s),o}},{key:"circumcentreDD",value:function(t,e,n){var i=at.valueOf(t.x).subtract(n.x),r=at.valueOf(t.y).subtract(n.y),s=at.valueOf(e.x).subtract(n.x),o=at.valueOf(e.y).subtract(n.y),a=at.determinant(i,r,s,o).multiply(2),u=i.sqr().add(r.sqr()),h=s.sqr().add(o.sqr()),l=at.determinant(r,u,o,h),c=at.determinant(i,u,s,h),f=at.valueOf(n.x).subtract(l.divide(a)).doubleValue(),d=at.valueOf(n.y).add(c.divide(a)).doubleValue();return new j(f,d)}},{key:"isAcute",value:function(t,e,n){return!!xn.isAcute(t,e,n)&&!!xn.isAcute(e,n,t)&&!!xn.isAcute(n,t,e)}},{key:"circumcentre",value:function(e,n,i){var r=i.x,s=i.y,o=e.x-r,a=e.y-s,u=n.x-r,h=n.y-s,l=2*t.det(o,a,u,h),c=t.det(a,o*o+a*a,h,u*u+h*h),f=t.det(o,o*o+a*a,u,u*u+h*h);return new j(r-c/l,s+f/l)}},{key:"perpendicularBisector",value:function(t,e){var n=e.x-t.x,i=e.y-t.y,r=new Cn(t.x+n/2,t.y+i/2,1),s=new Cn(t.x-i+n/2,t.y+n+i/2,1);return new Cn(r,s)}},{key:"angleBisector",value:function(t,e,n){var i=e.distance(t),r=i/(i+e.distance(n)),s=n.x-t.x,o=n.y-t.y;return new j(t.x+r*s,t.y+r*o)}},{key:"area3D",value:function(t,e,n){var i=e.x-t.x,r=e.y-t.y,s=e.getZ()-t.getZ(),o=n.x-t.x,a=n.y-t.y,u=n.getZ()-t.getZ(),h=r*u-s*a,l=s*o-i*u,c=i*a-r*o,f=h*h+l*l+c*c;return Math.sqrt(f)/2}},{key:"centroid",value:function(t,e,n){var i=(t.x+e.x+n.x)/3,r=(t.y+e.y+n.y)/3;return new j(i,r)}},{key:"inCentre",value:function(t,e,n){var i=e.distance(n),r=t.distance(n),s=t.distance(e),o=i+r+s,a=(i*t.x+r*e.x+s*n.x)/o,u=(i*t.y+r*e.y+s*n.y)/o;return new j(a,u)}}])}(),On=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"addRingSide",value:function(t,e,n,i,r){if(0===e&&t.length<jt.MINIMUM_VALID_SIZE)return null;var s=i,o=r;t.length>=jt.MINIMUM_VALID_SIZE&<.isCCW(t)&&(s=r,o=i,n=Z.opposite(n));var a=this.hl.getRingCurve(t,n,e);this.addCurve(a,s,o)}},{key:"addRingBothSides",value:function(t,e){this.addRingSide(t,e,Z.LEFT,W.EXTERIOR,W.INTERIOR),this.addRingSide(t,e,Z.RIGHT,W.INTERIOR,W.EXTERIOR)}},{key:"addPoint",value:function(t){if(this.wh<=0)return null;var e=t.getCoordinates(),n=this.hl.getLineCurve(e,this.wh);this.addCurve(n,W.EXTERIOR,W.INTERIOR)}},{key:"addPolygon",value:function(t){var e=this.wh,n=Z.LEFT;this.wh<0&&(e=-this.wh,n=Z.RIGHT);var i=t.getExteriorRing(),r=Gt.removeRepeatedPoints(i.getCoordinates());if(this.wh<0&&this.isErodedCompletely(i,this.wh))return null;if(this.wh<=0&&r.length<3)return null;this.addRingSide(r,e,n,W.EXTERIOR,W.INTERIOR);for(var s=0;s<t.getNumInteriorRing();s++){var o=t.getInteriorRingN(s),a=Gt.removeRepeatedPoints(o.getCoordinates());this.wh>0&&this.isErodedCompletely(o,-this.wh)||this.addRingSide(a,e,Z.opposite(n),W.INTERIOR,W.EXTERIOR)}}},{key:"isTriangleErodedCompletely",value:function(t,e){var n=new An(t[0],t[1],t[2]),i=n.inCentre();return bt.pointToSegment(i,n.p0,n.p1)<Math.abs(e)}},{key:"addLineString",value:function(t){if(this.hl.isLineOffsetEmpty(this.wh))return null;var e=Gt.removeRepeatedPoints(t.getCoordinates());if(Gt.isRing(e)&&!this.hl.getBufferParameters().isSingleSided())this.addRingBothSides(e,this.wh);else{var n=this.hl.getLineCurve(e,this.wh);this.addCurve(n,W.EXTERIOR,W.INTERIOR)}}},{key:"addCurve",value:function(t,e,n){if(null===t||t.length<2)return null;var i=new cn(t,new $e(0,W.BOUNDARY,e,n));this.ll.add(i)}},{key:"getCurves",value:function(){return this.add(this.cl),this.ll}},{key:"add",value:function(t){if(t.isEmpty())return null;if(t instanceof Ft)this.addPolygon(t);else if(t instanceof At)this.addLineString(t);else if(t instanceof It)this.addPoint(t);else if(t instanceof qt)this.addCollection(t);else if(t instanceof re)this.addCollection(t);else if(t instanceof Jt)this.addCollection(t);else{if(!(t instanceof Ut))throw new Y(t.getGeometryType());this.addCollection(t)}}},{key:"isErodedCompletely",value:function(t,e){var n=t.getCoordinates();if(n.length<4)return e<0;if(4===n.length)return this.isTriangleErodedCompletely(n,e);var i=t.getEnvelopeInternal(),r=Math.min(i.getHeight(),i.getWidth());return e<0&&2*Math.abs(e)>r}},{key:"addCollection",value:function(t){for(var e=0;e<t.getNumGeometries();e++){var n=t.getGeometryN(e);this.add(n)}}}],[{key:"constructor_",value:function(){this.cl=null,this.wh=null,this.hl=null,this.ll=new pt;var t=arguments[0],e=arguments[1],n=arguments[2];this.cl=t,this.wh=e,this.hl=n}}]),In=s((function t(){n(this,t)}),[{key:"locate",value:function(t){}}]),Tn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"next",value:function(){if(this.fl)return this.fl=!1,t.isAtomic(this.dl)&&this._index++,this.dl;if(null!==this.pl){if(this.pl.hasNext())return this.pl.next();this.pl=null}if(this._index>=this.vl)throw new G;var e=this.dl.getGeometryN(this._index++);return e instanceof Ut?(this.pl=new t(e),this.pl.next()):e}},{key:"remove",value:function(){throw new Y(this.getClass().getName())}},{key:"hasNext",value:function(){if(this.fl)return!0;if(null!==this.pl){if(this.pl.hasNext())return!0;this.pl=null}return!(this._index>=this.vl)}},{key:"interfaces_",get:function(){return[on]}}],[{key:"constructor_",value:function(){this.dl=null,this.fl=null,this.vl=null,this._index=null,this.pl=null;var t=arguments[0];this.dl=t,this.fl=!0,this._index=0,this.vl=t.getNumGeometries()}},{key:"isAtomic",value:function(t){return!(t instanceof Ut)}}])}(),zn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"locate",value:function(e){return t.locate(e,this.ml)}},{key:"interfaces_",get:function(){return[In]}}],[{key:"constructor_",value:function(){this.ml=null;var t=arguments[0];this.ml=t}},{key:"locatePointInPolygon",value:function(e,n){if(n.isEmpty())return W.EXTERIOR;var i=n.getExteriorRing(),r=t.locatePointInRing(e,i);if(r!==W.INTERIOR)return r;for(var s=0;s<n.getNumInteriorRing();s++){var o=n.getInteriorRingN(s),a=t.locatePointInRing(e,o);if(a===W.BOUNDARY)return W.BOUNDARY;if(a===W.INTERIOR)return W.EXTERIOR}return W.INTERIOR}},{key:"locatePointInRing",value:function(t,e){return e.getEnvelopeInternal().intersects(t)?xe.locateInRing(t,e.getCoordinates()):W.EXTERIOR}},{key:"containsPointInPolygon",value:function(e,n){return W.EXTERIOR!==t.locatePointInPolygon(e,n)}},{key:"locateInGeometry",value:function(e,n){if(n instanceof Ft)return t.locatePointInPolygon(e,n);if(n instanceof Ut)for(var i=new Tn(n);i.hasNext();){var r=i.next();if(r!==n){var s=t.locateInGeometry(e,r);if(s!==W.EXTERIOR)return s}}return W.EXTERIOR}},{key:"isContained",value:function(e,n){return W.EXTERIOR!==t.locate(e,n)}},{key:"locate",value:function(e,n){return n.isEmpty()?W.EXTERIOR:n.getEnvelopeInternal().intersects(e)?t.locateInGeometry(e,n):W.EXTERIOR}}])}(),Rn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getNextCW",value:function(t){this.getEdges();var e=this.yl.indexOf(t),n=e-1;return 0===e&&(n=this.yl.size()-1),this.yl.get(n)}},{key:"propagateSideLabels",value:function(t){for(var e=W.NONE,n=this.iterator();n.hasNext();){var i=n.next().getLabel();i.isArea(t)&&i.getLocation(t,Z.LEFT)!==W.NONE&&(e=i.getLocation(t,Z.LEFT))}if(e===W.NONE)return null;for(var r=e,s=this.iterator();s.hasNext();){var o=s.next(),a=o.getLabel();if(a.getLocation(t,Z.ON)===W.NONE&&a.setLocation(t,Z.ON,r),a.isArea(t)){var u=a.getLocation(t,Z.LEFT),h=a.getLocation(t,Z.RIGHT);if(h!==W.NONE){if(h!==r)throw new ft("side location conflict",o.getCoordinate());u===W.NONE&&D.shouldNeverReachHere("found single null side (at "+o.getCoordinate()+")"),r=u}else D.isTrue(a.getLocation(t,Z.LEFT)===W.NONE,"found single null side"),a.setLocation(t,Z.RIGHT,r),a.setLocation(t,Z.LEFT,r)}}}},{key:"getCoordinate",value:function(){var t=this.iterator();return t.hasNext()?t.next().getCoordinate():null}},{key:"print",value:function(t){wt.out.println("EdgeEndStar: "+this.getCoordinate());for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"isAreaLabelsConsistent",value:function(t){return this.computeEdgeEndLabels(t.getBoundaryNodeRule()),this.checkAreaLabelsConsistent(0)}},{key:"checkAreaLabelsConsistent",value:function(t){var e=this.getEdges();if(e.size()<=0)return!0;var n=e.size()-1,i=e.get(n).getLabel().getLocation(t,Z.LEFT);D.isTrue(i!==W.NONE,"Found unlabelled area edge");for(var r=i,s=this.iterator();s.hasNext();){var o=s.next().getLabel();D.isTrue(o.isArea(t),"Found non-area edge");var a=o.getLocation(t,Z.LEFT),u=o.getLocation(t,Z.RIGHT);if(a===u)return!1;if(u!==r)return!1;r=a}return!0}},{key:"findIndex",value:function(t){this.iterator();for(var e=0;e<this.yl.size();e++)if(this.yl.get(e)===t)return e;return-1}},{key:"iterator",value:function(){return this.getEdges().iterator()}},{key:"getEdges",value:function(){return null===this.yl&&(this.yl=new pt(this.wl.values())),this.yl}},{key:"getLocation",value:function(t,e,n){return this.gl[t]===W.NONE&&(this.gl[t]=zn.locate(e,n[t].getGeometry())),this.gl[t]}},{key:"toString",value:function(){var t=new rt;t.append("EdgeEndStar: "+this.getCoordinate()),t.append("\n");for(var e=this.iterator();e.hasNext();){var n=e.next();t.append(n),t.append("\n")}return t.toString()}},{key:"computeEdgeEndLabels",value:function(t){for(var e=this.iterator();e.hasNext();)e.next().computeLabel(t)}},{key:"computeLabelling",value:function(t){this.computeEdgeEndLabels(t[0].getBoundaryNodeRule()),this.propagateSideLabels(0),this.propagateSideLabels(1);for(var e=[!1,!1],n=this.iterator();n.hasNext();)for(var i=n.next().getLabel(),r=0;r<2;r++)i.isLine(r)&&i.getLocation(r)===W.BOUNDARY&&(e[r]=!0);for(var s=this.iterator();s.hasNext();)for(var o=s.next(),a=o.getLabel(),u=0;u<2;u++)if(a.isAnyNull(u)){var h=W.NONE;if(e[u])h=W.EXTERIOR;else{var l=o.getCoordinate();h=this.getLocation(u,l,t)}a.setAllLocationsIfNull(u,h)}}},{key:"getDegree",value:function(){return this.wl.size()}},{key:"insertEdgeEnd",value:function(t,e){this.wl.put(t,e),this.yl=null}}],[{key:"constructor_",value:function(){this.wl=new Pe,this.yl=null,this.gl=[W.NONE,W.NONE]}}]),Fn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"linkResultDirectedEdges",value:function(){this.getResultAreaEdges();for(var t=null,e=null,n=this._l,i=0;i<this.xl.size();i++){var r=this.xl.get(i),s=r.getSym();if(r.getLabel().isArea())switch(null===t&&r.isInResult()&&(t=r),n){case this._l:if(!s.isInResult())continue;e=s,n=this.kl;break;case this.kl:if(!r.isInResult())continue;e.setNext(r),n=this._l}}if(n===this.kl){if(null===t)throw new ft("no outgoing dirEdge found",this.getCoordinate());D.isTrue(t.isInResult(),"unable to link last incoming dirEdge"),e.setNext(t)}}},{key:"insert",value:function(t){var e=t;this.insertEdgeEnd(e,e)}},{key:"getRightmostEdge",value:function(){var t=this.getEdges(),e=t.size();if(e<1)return null;var n=t.get(0);if(1===e)return n;var i=t.get(e-1),r=n.getQuadrant(),s=i.getQuadrant();return Ne.isNorthern(r)&&Ne.isNorthern(s)?n:Ne.isNorthern(r)||Ne.isNorthern(s)?0!==n.getDy()?n:0!==i.getDy()?i:(D.shouldNeverReachHere("found two horizontal edges incident on node"),null):i}},{key:"print",value:function(t){wt.out.println("DirectedEdgeStar: "+this.getCoordinate());for(var e=this.iterator();e.hasNext();){var n=e.next();t.print("out "),n.print(t),t.println(),t.print("in "),n.getSym().print(t),t.println()}}},{key:"getResultAreaEdges",value:function(){if(null!==this.xl)return this.xl;this.xl=new pt;for(var t=this.iterator();t.hasNext();){var e=t.next();(e.isInResult()||e.getSym().isInResult())&&this.xl.add(e)}return this.xl}},{key:"updateLabelling",value:function(t){for(var e=this.iterator();e.hasNext();){var n=e.next().getLabel();n.setAllLocationsIfNull(0,t.getLocation(0)),n.setAllLocationsIfNull(1,t.getLocation(1))}}},{key:"linkAllDirectedEdges",value:function(){this.getEdges();for(var t=null,e=null,n=this.yl.size()-1;n>=0;n--){var i=this.yl.get(n),r=i.getSym();null===e&&(e=r),null!==t&&r.setNext(t),t=i}e.setNext(t)}},{key:"computeDepths",value:function(){if(1===arguments.length){var t=arguments[0],e=this.findIndex(t),n=t.getDepth(Z.LEFT),i=t.getDepth(Z.RIGHT),r=this.computeDepths(e+1,this.yl.size(),n);if(this.computeDepths(0,e,r)!==i)throw new ft("depth mismatch at "+t.getCoordinate())}else if(3===arguments.length){for(var s=arguments[1],o=arguments[2],a=arguments[0];a<s;a++){var u=this.yl.get(a);u.setEdgeDepths(Z.RIGHT,o),o=u.getDepth(Z.LEFT)}return o}}},{key:"mergeSymLabels",value:function(){for(var t=this.iterator();t.hasNext();){var e=t.next();e.getLabel().merge(e.getSym().getLabel())}}},{key:"linkMinimalDirectedEdges",value:function(t){for(var e=null,n=null,i=this._l,r=this.xl.size()-1;r>=0;r--){var s=this.xl.get(r),o=s.getSym();switch(null===e&&s.getEdgeRing()===t&&(e=s),i){case this._l:if(o.getEdgeRing()!==t)continue;n=o,i=this.kl;break;case this.kl:if(s.getEdgeRing()!==t)continue;n.setNextMin(s),i=this._l}}i===this.kl&&(D.isTrue(null!==e,"found null for first outgoing dirEdge"),D.isTrue(e.getEdgeRing()===t,"unable to link last incoming dirEdge"),n.setNextMin(e))}},{key:"getOutgoingDegree",value:function(){if(0===arguments.length){for(var t=0,e=this.iterator();e.hasNext();)e.next().isInResult()&&t++;return t}if(1===arguments.length){for(var n=arguments[0],i=0,r=this.iterator();r.hasNext();)r.next().getEdgeRing()===n&&i++;return i}}},{key:"getLabel",value:function(){return this.Nu}},{key:"findCoveredLineEdges",value:function(){for(var t=W.NONE,e=this.iterator();e.hasNext();){var n=e.next(),i=n.getSym();if(!n.isLineEdge()){if(n.isInResult()){t=W.INTERIOR;break}if(i.isInResult()){t=W.EXTERIOR;break}}}if(t===W.NONE)return null;for(var r=t,s=this.iterator();s.hasNext();){var o=s.next(),a=o.getSym();o.isLineEdge()?o.getEdge().setCovered(r===W.INTERIOR):(o.isInResult()&&(r=W.EXTERIOR),a.isInResult()&&(r=W.INTERIOR))}}},{key:"computeLabelling",value:function(t){f(i,"computeLabelling",this,1).call(this,t),this.Nu=new $e(W.NONE);for(var e=this.iterator();e.hasNext();)for(var n=e.next().getEdge().getLabel(),r=0;r<2;r++){var s=n.getLocation(r);s!==W.INTERIOR&&s!==W.BOUNDARY||this.Nu.setLocation(r,W.INTERIOR)}}}],[{key:"constructor_",value:function(){this.xl=null,this.Nu=null,this._l=1,this.kl=2}}])}(Rn),Pn=function(t){function i(){return n(this,i),e(this,i)}return h(i,t),s(i,[{key:"createNode",value:function(t){return new Ae(t,new Fn)}}])}(je),Dn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"compareTo",value:function(e){var n=e;return t.compareOriented(this.Fu,this.$l,n.Fu,n.$l)}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.Fu=null,this.$l=null;var e=arguments[0];this.Fu=e,this.$l=t.orientation(e)}},{key:"orientation",value:function(t){return 1===Gt.increasingDirection(t)}},{key:"compareOriented",value:function(t,e,n,i){for(var r=e?1:-1,s=i?1:-1,o=e?t.length:-1,a=i?n.length:-1,u=e?0:t.length-1,h=i?0:n.length-1;;){var l=t[u].compareTo(n[h]);if(0!==l)return l;var c=(u+=r)===o,f=(h+=s)===a;if(c&&!f)return-1;if(!c&&f)return 1;if(c&&f)return 0}}}])}(),Nn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"print",value:function(t){t.print("MULTILINESTRING ( ");for(var e=0;e<this.qu.size();e++){var n=this.qu.get(e);e>0&&t.print(","),t.print("(");for(var i=n.getCoordinates(),r=0;r<i.length;r++)r>0&&t.print(","),t.print(i[r].x+" "+i[r].y);t.println(")")}t.print(") ")}},{key:"addAll",value:function(t){for(var e=t.iterator();e.hasNext();)this.add(e.next())}},{key:"findEdgeIndex",value:function(t){for(var e=0;e<this.qu.size();e++)if(this.qu.get(e).equals(t))return e;return-1}},{key:"iterator",value:function(){return this.qu.iterator()}},{key:"getEdges",value:function(){return this.qu}},{key:"get",value:function(t){return this.qu.get(t)}},{key:"findEqualEdge",value:function(t){var e=new Dn(t.getCoordinates());return this.Sl.get(e)}},{key:"add",value:function(t){this.qu.add(t);var e=new Dn(t.getCoordinates());this.Sl.put(e,t)}}],[{key:"constructor_",value:function(){this.qu=new pt,this.Sl=new Pe}}]),Un=s((function t(){n(this,t)}),[{key:"processIntersections",value:function(t,e,n,i){}},{key:"isDone",value:function(){}}]),qn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"isTrivialIntersection",value:function(e,n,i,r){if(e===i&&1===this.el.getIntersectionNum()){if(t.isAdjacentSegments(n,r))return!0;if(e.isClosed()){var s=e.size()-1;if(0===n&&r===s||0===r&&n===s)return!0}}return!1}},{key:"getProperIntersectionPoint",value:function(){return this.Ml}},{key:"hasProperInteriorIntersection",value:function(){return this.El}},{key:"getLineIntersector",value:function(){return this.el}},{key:"hasProperIntersection",value:function(){return this.Cl}},{key:"processIntersections",value:function(t,e,n,i){if(t===n&&e===i)return null;this.numTests++;var r=t.getCoordinates()[e],s=t.getCoordinates()[e+1],o=n.getCoordinates()[i],a=n.getCoordinates()[i+1];this.el.computeIntersection(r,s,o,a),this.el.hasIntersection()&&(this.numIntersections++,this.el.isInteriorIntersection()&&(this.numInteriorIntersections++,this.Al=!0),this.isTrivialIntersection(t,e,n,i)||(this.Ol=!0,t.addIntersections(this.el,e,0),n.addIntersections(this.el,i,1),this.el.isProper()&&(this.numProperIntersections++,this.Cl=!0,this.El=!0)))}},{key:"hasIntersection",value:function(){return this.Ol}},{key:"isDone",value:function(){return!1}},{key:"hasInteriorIntersection",value:function(){return this.Al}},{key:"interfaces_",get:function(){return[Un]}}],[{key:"constructor_",value:function(){this.Ol=!1,this.Cl=!1,this.El=!1,this.Al=!1,this.Ml=null,this.el=null,this.Il=null,this.numIntersections=0,this.numInteriorIntersections=0,this.numProperIntersections=0,this.numTests=0;var t=arguments[0];this.el=t}},{key:"isAdjacentSegments",value:function(t,e){return 1===Math.abs(t-e)}}])}(),jn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getSegmentIndex",value:function(){return this.segmentIndex}},{key:"getCoordinate",value:function(){return this.coord}},{key:"print",value:function(t){t.print(this.coord),t.print(" seg # = "+this.segmentIndex),t.println(" dist = "+this.dist)}},{key:"compareTo",value:function(t){var e=t;return this.compare(e.segmentIndex,e.dist)}},{key:"isEndPoint",value:function(t){return 0===this.segmentIndex&&0===this.dist||this.segmentIndex===t}},{key:"toString",value:function(){return this.coord+" seg # = "+this.segmentIndex+" dist = "+this.dist}},{key:"getDistance",value:function(){return this.dist}},{key:"compare",value:function(t,e){return this.segmentIndex<t?-1:this.segmentIndex>t?1:this.dist<e?-1:this.dist>e?1:0}},{key:"interfaces_",get:function(){return[_]}}],[{key:"constructor_",value:function(){this.coord=null,this.segmentIndex=null,this.dist=null;var t=arguments[0],e=arguments[1],n=arguments[2];this.coord=new j(t),this.segmentIndex=e,this.dist=n}}]),Bn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"print",value:function(t){t.println("Intersections:");for(var e=this.iterator();e.hasNext();)e.next().print(t)}},{key:"iterator",value:function(){return this.Mh.values().iterator()}},{key:"addSplitEdges",value:function(t){this.addEndpoints();for(var e=this.iterator(),n=e.next();e.hasNext();){var i=e.next(),r=this.createSplitEdge(n,i);t.add(r),n=i}}},{key:"addEndpoints",value:function(){var t=this.edge.pts.length-1;this.add(this.edge.pts[0],0,0),this.add(this.edge.pts[t],t,0)}},{key:"createSplitEdge",value:function(t,e){var n=e.segmentIndex-t.segmentIndex+2,i=this.edge.pts[e.segmentIndex],r=e.dist>0||!e.coord.equals2D(i);r||n--;var s=new Array(n).fill(null),o=0;s[o++]=new j(t.coord);for(var a=t.segmentIndex+1;a<=e.segmentIndex;a++)s[o++]=this.edge.pts[a];return r&&(s[o]=e.coord),new Yn(s,new $e(this.edge.Nu))}},{key:"add",value:function(t,e,n){var i=new jn(t,e,n),r=this.Mh.get(i);return null!==r?r:(this.Mh.put(i,i),i)}},{key:"isIntersection",value:function(t){for(var e=this.iterator();e.hasNext();)if(e.next().coord.equals(t))return!0;return!1}}],[{key:"constructor_",value:function(){this.Mh=new Pe,this.edge=null;var t=arguments[0];this.edge=t}}]),Ln=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"isIntersects",value:function(){return!this.isDisjoint()}},{key:"isCovers",value:function(){return(t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])||t.isTrue(this.Tl[W.INTERIOR][W.BOUNDARY])||t.isTrue(this.Tl[W.BOUNDARY][W.INTERIOR])||t.isTrue(this.Tl[W.BOUNDARY][W.BOUNDARY]))&&this.Tl[W.EXTERIOR][W.INTERIOR]===Mt.FALSE&&this.Tl[W.EXTERIOR][W.BOUNDARY]===Mt.FALSE}},{key:"isCoveredBy",value:function(){return(t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])||t.isTrue(this.Tl[W.INTERIOR][W.BOUNDARY])||t.isTrue(this.Tl[W.BOUNDARY][W.INTERIOR])||t.isTrue(this.Tl[W.BOUNDARY][W.BOUNDARY]))&&this.Tl[W.INTERIOR][W.EXTERIOR]===Mt.FALSE&&this.Tl[W.BOUNDARY][W.EXTERIOR]===Mt.FALSE}},{key:"set",value:function(){if(1===arguments.length)for(var t=arguments[0],e=0;e<t.length;e++){var n=Math.trunc(e/3),i=e%3;this.Tl[n][i]=Mt.toDimensionValue(t.charAt(e))}else if(3===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2];this.Tl[r][s]=o}}},{key:"isContains",value:function(){return t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&this.Tl[W.EXTERIOR][W.INTERIOR]===Mt.FALSE&&this.Tl[W.EXTERIOR][W.BOUNDARY]===Mt.FALSE}},{key:"setAtLeast",value:function(){if(1===arguments.length)for(var t=arguments[0],e=0;e<t.length;e++){var n=Math.trunc(e/3),i=e%3;this.setAtLeast(n,i,Mt.toDimensionValue(t.charAt(e)))}else if(3===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2];this.Tl[r][s]<o&&(this.Tl[r][s]=o)}}},{key:"setAtLeastIfValid",value:function(t,e,n){t>=0&&e>=0&&this.setAtLeast(t,e,n)}},{key:"isWithin",value:function(){return t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&this.Tl[W.INTERIOR][W.EXTERIOR]===Mt.FALSE&&this.Tl[W.BOUNDARY][W.EXTERIOR]===Mt.FALSE}},{key:"isTouches",value:function(e,n){return e>n?this.isTouches(n,e):(e===Mt.A&&n===Mt.A||e===Mt.L&&n===Mt.L||e===Mt.L&&n===Mt.A||e===Mt.P&&n===Mt.A||e===Mt.P&&n===Mt.L)&&this.Tl[W.INTERIOR][W.INTERIOR]===Mt.FALSE&&(t.isTrue(this.Tl[W.INTERIOR][W.BOUNDARY])||t.isTrue(this.Tl[W.BOUNDARY][W.INTERIOR])||t.isTrue(this.Tl[W.BOUNDARY][W.BOUNDARY]))}},{key:"isOverlaps",value:function(e,n){return e===Mt.P&&n===Mt.P||e===Mt.A&&n===Mt.A?t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&t.isTrue(this.Tl[W.INTERIOR][W.EXTERIOR])&&t.isTrue(this.Tl[W.EXTERIOR][W.INTERIOR]):e===Mt.L&&n===Mt.L&&1===this.Tl[W.INTERIOR][W.INTERIOR]&&t.isTrue(this.Tl[W.INTERIOR][W.EXTERIOR])&&t.isTrue(this.Tl[W.EXTERIOR][W.INTERIOR])}},{key:"isEquals",value:function(e,n){return e===n&&t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&this.Tl[W.INTERIOR][W.EXTERIOR]===Mt.FALSE&&this.Tl[W.BOUNDARY][W.EXTERIOR]===Mt.FALSE&&this.Tl[W.EXTERIOR][W.INTERIOR]===Mt.FALSE&&this.Tl[W.EXTERIOR][W.BOUNDARY]===Mt.FALSE}},{key:"toString",value:function(){for(var t=new Xt("123456789"),e=0;e<3;e++)for(var n=0;n<3;n++)t.setCharAt(3*e+n,Mt.toDimensionSymbol(this.Tl[e][n]));return t.toString()}},{key:"setAll",value:function(t){for(var e=0;e<3;e++)for(var n=0;n<3;n++)this.Tl[e][n]=t}},{key:"get",value:function(t,e){return this.Tl[t][e]}},{key:"transpose",value:function(){var t=this.Tl[1][0];return this.Tl[1][0]=this.Tl[0][1],this.Tl[0][1]=t,t=this.Tl[2][0],this.Tl[2][0]=this.Tl[0][2],this.Tl[0][2]=t,t=this.Tl[2][1],this.Tl[2][1]=this.Tl[1][2],this.Tl[1][2]=t,this}},{key:"matches",value:function(e){if(9!==e.length)throw new g("Should be length 9: "+e);for(var n=0;n<3;n++)for(var i=0;i<3;i++)if(!t.matches(this.Tl[n][i],e.charAt(3*n+i)))return!1;return!0}},{key:"add",value:function(t){for(var e=0;e<3;e++)for(var n=0;n<3;n++)this.setAtLeast(e,n,t.get(e,n))}},{key:"isDisjoint",value:function(){return this.Tl[W.INTERIOR][W.INTERIOR]===Mt.FALSE&&this.Tl[W.INTERIOR][W.BOUNDARY]===Mt.FALSE&&this.Tl[W.BOUNDARY][W.INTERIOR]===Mt.FALSE&&this.Tl[W.BOUNDARY][W.BOUNDARY]===Mt.FALSE}},{key:"isCrosses",value:function(e,n){return e===Mt.P&&n===Mt.L||e===Mt.P&&n===Mt.A||e===Mt.L&&n===Mt.A?t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&t.isTrue(this.Tl[W.INTERIOR][W.EXTERIOR]):e===Mt.L&&n===Mt.P||e===Mt.A&&n===Mt.P||e===Mt.A&&n===Mt.L?t.isTrue(this.Tl[W.INTERIOR][W.INTERIOR])&&t.isTrue(this.Tl[W.EXTERIOR][W.INTERIOR]):e===Mt.L&&n===Mt.L&&0===this.Tl[W.INTERIOR][W.INTERIOR]}},{key:"interfaces_",get:function(){return[x]}}],[{key:"constructor_",value:function(){if(this.Tl=null,0===arguments.length)this.Tl=Array(3).fill().map((function(){return Array(3)})),this.setAll(Mt.FALSE);else if(1===arguments.length)if("string"==typeof arguments[0]){var e=arguments[0];t.constructor_.call(this),this.set(e)}else if(arguments[0]instanceof t){var n=arguments[0];t.constructor_.call(this),this.Tl[W.INTERIOR][W.INTERIOR]=n.Tl[W.INTERIOR][W.INTERIOR],this.Tl[W.INTERIOR][W.BOUNDARY]=n.Tl[W.INTERIOR][W.BOUNDARY],this.Tl[W.INTERIOR][W.EXTERIOR]=n.Tl[W.INTERIOR][W.EXTERIOR],this.Tl[W.BOUNDARY][W.INTERIOR]=n.Tl[W.BOUNDARY][W.INTERIOR],this.Tl[W.BOUNDARY][W.BOUNDARY]=n.Tl[W.BOUNDARY][W.BOUNDARY],this.Tl[W.BOUNDARY][W.EXTERIOR]=n.Tl[W.BOUNDARY][W.EXTERIOR],this.Tl[W.EXTERIOR][W.INTERIOR]=n.Tl[W.EXTERIOR][W.INTERIOR],this.Tl[W.EXTERIOR][W.BOUNDARY]=n.Tl[W.EXTERIOR][W.BOUNDARY],this.Tl[W.EXTERIOR][W.EXTERIOR]=n.Tl[W.EXTERIOR][W.EXTERIOR]}}},{key:"matches",value:function(){if(Number.isInteger(arguments[0])&&"string"==typeof arguments[1]){var e=arguments[0],n=arguments[1];return n===Mt.SYM_DONTCARE||n===Mt.SYM_TRUE&&(e>=0||e===Mt.TRUE)||n===Mt.SYM_FALSE&&e===Mt.FALSE||n===Mt.SYM_P&&e===Mt.P||n===Mt.SYM_L&&e===Mt.L||n===Mt.SYM_A&&e===Mt.A}if("string"==typeof arguments[0]&&"string"==typeof arguments[1]){var i=arguments[1];return new t(arguments[0]).matches(i)}}},{key:"isTrue",value:function(t){return t>=0||t===Mt.TRUE}}])}(),Hn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"size",value:function(){return this.Hi}},{key:"addAll",value:function(t){return null===t||0===t.length?null:(this.ensureCapacity(this.Hi+t.length),wt.arraycopy(t,0,this.Ve,this.Hi,t.length),void(this.Hi+=t.length))}},{key:"ensureCapacity",value:function(t){if(t<=this.Ve.length)return null;var e=Math.max(t,2*this.Ve.length);this.Ve=zt.copyOf(this.Ve,e)}},{key:"toArray",value:function(){var t=new Array(this.Hi).fill(null);return wt.arraycopy(this.Ve,0,t,0,this.Hi),t}},{key:"add",value:function(t){this.ensureCapacity(this.Hi+1),this.Ve[this.Hi]=t,++this.Hi}}],[{key:"constructor_",value:function(){if(this.Ve=null,this.Hi=0,0===arguments.length)t.constructor_.call(this,10);else if(1===arguments.length){var e=arguments[0];this.Ve=new Array(e).fill(null)}}}])}(),Wn=function(){function t(){n(this,t)}return s(t,[{key:"getChainStartIndices",value:function(t){var e=0,n=new Hn(Math.trunc(t.length/2));n.add(e);do{var i=this.findChainEnd(t,e);n.add(i),e=i}while(e<t.length-1);return n.toArray()}},{key:"findChainEnd",value:function(t,e){for(var n=Ne.quadrant(t[e],t[e+1]),i=e+1;i<t.length&&Ne.quadrant(t[i-1],t[i])===n;)i++;return i-1}},{key:"OLDgetChainStartIndices",value:function(e){var n=0,i=new pt;i.add(n);do{var r=this.findChainEnd(e,n);i.add(r),n=r}while(n<e.length-1);return t.toIntArray(i)}}],[{key:"toIntArray",value:function(t){for(var e=new Array(t.size()).fill(null),n=0;n<e.length;n++)e[n]=t.get(n).intValue();return e}}])}(),Vn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"getCoordinates",value:function(){return this.pts}},{key:"getMaxX",value:function(t){var e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e>n?e:n}},{key:"getMinX",value:function(t){var e=this.pts[this.startIndex[t]].x,n=this.pts[this.startIndex[t+1]].x;return e<n?e:n}},{key:"computeIntersectsForChain",value:function(){if(4===arguments.length){var t=arguments[0],e=arguments[1],n=arguments[2],i=arguments[3];this.computeIntersectsForChain(this.startIndex[t],this.startIndex[t+1],e,e.startIndex[n],e.startIndex[n+1],i)}else if(6===arguments.length){var r=arguments[0],s=arguments[1],o=arguments[2],a=arguments[3],u=arguments[4],h=arguments[5];if(s-r==1&&u-a==1)return h.addIntersections(this.e,r,o.e,a),null;if(!this.overlaps(r,s,o,a,u))return null;var l=Math.trunc((r+s)/2),c=Math.trunc((a+u)/2);r<l&&(a<c&&this.computeIntersectsForChain(r,l,o,a,c,h),c<u&&this.computeIntersectsForChain(r,l,o,c,u,h)),l<s&&(a<c&&this.computeIntersectsForChain(l,s,o,a,c,h),c<u&&this.computeIntersectsForChain(l,s,o,c,u,h))}}},{key:"overlaps",value:function(t,e,n,i,r){return L.intersects(this.pts[t],this.pts[e],n.pts[i],n.pts[r])}},{key:"getStartIndexes",value:function(){return this.startIndex}},{key:"computeIntersects",value:function(t,e){for(var n=0;n<this.startIndex.length-1;n++)for(var i=0;i<t.startIndex.length-1;i++)this.computeIntersectsForChain(n,t,i,e)}}],[{key:"constructor_",value:function(){this.e=null,this.pts=null,this.startIndex=null;var t=arguments[0];this.e=t,this.pts=t.getCoordinates();var e=new Wn;this.startIndex=e.getChainStartIndices(this.pts)}}]),Gn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"getDepth",value:function(t,e){return this.th[t][e]}},{key:"setDepth",value:function(t,e,n){this.th[t][e]=n}},{key:"isNull",value:function(){if(0===arguments.length){for(var e=0;e<2;e++)for(var n=0;n<3;n++)if(this.th[e][n]!==t.NULL_VALUE)return!1;return!0}if(1===arguments.length){var i=arguments[0];return this.th[i][1]===t.NULL_VALUE}if(2===arguments.length){var r=arguments[0],s=arguments[1];return this.th[r][s]===t.NULL_VALUE}}},{key:"normalize",value:function(){for(var t=0;t<2;t++)if(!this.isNull(t)){var e=this.th[t][1];this.th[t][2]<e&&(e=this.th[t][2]),e<0&&(e=0);for(var n=1;n<3;n++){var i=0;this.th[t][n]>e&&(i=1),this.th[t][n]=i}}}},{key:"getDelta",value:function(t){return this.th[t][Z.RIGHT]-this.th[t][Z.LEFT]}},{key:"getLocation",value:function(t,e){return this.th[t][e]<=0?W.EXTERIOR:W.INTERIOR}},{key:"toString",value:function(){return"A: "+this.th[0][1]+","+this.th[0][2]+" B: "+this.th[1][1]+","+this.th[1][2]}},{key:"add",value:function(){if(1===arguments.length)for(var e=arguments[0],n=0;n<2;n++)for(var i=1;i<3;i++){var r=e.getLocation(n,i);r!==W.EXTERIOR&&r!==W.INTERIOR||(this.isNull(n,i)?this.th[n][i]=t.depthAtLocation(r):this.th[n][i]+=t.depthAtLocation(r))}else if(3===arguments.length){var s=arguments[0],o=arguments[1];arguments[2]===W.INTERIOR&&this.th[s][o]++}}}],[{key:"constructor_",value:function(){this.th=Array(2).fill().map((function(){return Array(3)}));for(var e=0;e<2;e++)for(var n=0;n<3;n++)this.th[e][n]=t.NULL_VALUE}},{key:"depthAtLocation",value:function(e){return e===W.EXTERIOR?0:e===W.INTERIOR?1:t.NULL_VALUE}}])}();Gn.NULL_VALUE=-1;var Yn=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"getDepth",value:function(){return this.th}},{key:"getCollapsedEdge",value:function(){var t=new Array(2).fill(null);return t[0]=this.pts[0],t[1]=this.pts[1],new i(t,$e.toLineLabel(this.Nu))}},{key:"isIsolated",value:function(){return this.zl}},{key:"getCoordinates",value:function(){return this.pts}},{key:"setIsolated",value:function(t){this.zl=t}},{key:"setName",value:function(t){this.do=t}},{key:"equals",value:function(t){if(!(t instanceof i))return!1;var e=t;if(this.pts.length!==e.pts.length)return!1;for(var n=!0,r=!0,s=this.pts.length,o=0;o<this.pts.length;o++)if(this.pts[o].equals2D(e.pts[o])||(n=!1),this.pts[o].equals2D(e.pts[--s])||(r=!1),!n&&!r)return!1;return!0}},{key:"getCoordinate",value:function(){if(0===arguments.length)return this.pts.length>0?this.pts[0]:null;if(1===arguments.length){var t=arguments[0];return this.pts[t]}}},{key:"print",value:function(t){t.print("edge "+this.do+": "),t.print("LINESTRING (");for(var e=0;e<this.pts.length;e++)e>0&&t.print(","),t.print(this.pts[e].x+" "+this.pts[e].y);t.print(") "+this.Nu+" "+this.Rl)}},{key:"computeIM",value:function(t){i.updateIM(this.Nu,t)}},{key:"isCollapsed",value:function(){return!!this.Nu.isArea()&&3===this.pts.length&&!!this.pts[0].equals(this.pts[2])}},{key:"isClosed",value:function(){return this.pts[0].equals(this.pts[this.pts.length-1])}},{key:"getMaximumSegmentIndex",value:function(){return this.pts.length-1}},{key:"getDepthDelta",value:function(){return this.Rl}},{key:"getNumPoints",value:function(){return this.pts.length}},{key:"printReverse",value:function(t){t.print("edge "+this.do+": ");for(var e=this.pts.length-1;e>=0;e--)t.print(this.pts[e]+" ");t.println("")}},{key:"getMonotoneChainEdge",value:function(){return null===this.Fl&&(this.Fl=new Vn(this)),this.Fl}},{key:"getEnvelope",value:function(){if(null===this.fu){this.fu=new L;for(var t=0;t<this.pts.length;t++)this.fu.expandToInclude(this.pts[t])}return this.fu}},{key:"addIntersection",value:function(t,e,n,i){var r=new j(t.getIntersection(i)),s=e,o=t.getEdgeDistance(n,i),a=s+1;if(a<this.pts.length){var u=this.pts[a];r.equals2D(u)&&(s=a,o=0)}this.eiList.add(r,s,o)}},{key:"toString",value:function(){var t=new Xt;t.append("edge "+this.do+": "),t.append("LINESTRING (");for(var e=0;e<this.pts.length;e++)e>0&&t.append(","),t.append(this.pts[e].x+" "+this.pts[e].y);return t.append(") "+this.Nu+" "+this.Rl),t.toString()}},{key:"isPointwiseEqual",value:function(t){if(this.pts.length!==t.pts.length)return!1;for(var e=0;e<this.pts.length;e++)if(!this.pts[e].equals2D(t.pts[e]))return!1;return!0}},{key:"setDepthDelta",value:function(t){this.Rl=t}},{key:"getEdgeIntersectionList",value:function(){return this.eiList}},{key:"addIntersections",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++)this.addIntersection(t,e,n,i)}}],[{key:"constructor_",value:function(){if(this.pts=null,this.fu=null,this.eiList=new Bn(this),this.do=null,this.Fl=null,this.zl=!0,this.th=new Gn,this.Rl=0,1===arguments.length){var t=arguments[0];i.constructor_.call(this,t,null)}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.pts=e,this.Nu=n}}},{key:"updateIM",value:function(){if(!(2===arguments.length&&arguments[1]instanceof Ln&&arguments[0]instanceof $e))return f(i,"updateIM",this).apply(this,arguments);var t=arguments[0],e=arguments[1];e.setAtLeastIfValid(t.getLocation(0,Z.ON),t.getLocation(1,Z.ON),1),t.isArea()&&(e.setAtLeastIfValid(t.getLocation(0,Z.LEFT),t.getLocation(1,Z.LEFT),2),e.setAtLeastIfValid(t.getLocation(0,Z.RIGHT),t.getLocation(1,Z.RIGHT),2))}}])}(Ce),Kn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"setWorkingPrecisionModel",value:function(t){this.Pl=t}},{key:"insertUniqueEdge",value:function(e){var n=this.yl.findEqualEdge(e);if(null!==n){var i=n.getLabel(),r=e.getLabel();n.isPointwiseEqual(e)||(r=new $e(e.getLabel())).flip(),i.merge(r);var s=t.depthDelta(r),o=n.getDepthDelta()+s;n.setDepthDelta(o)}else this.yl.add(e),e.setDepthDelta(t.depthDelta(e.getLabel()))}},{key:"buildSubgraphs",value:function(t,e){for(var n=new pt,i=t.iterator();i.hasNext();){var r=i.next(),s=r.getRightmostCoordinate(),o=new Sn(n).getDepth(s);r.computeDepth(o),r.findResultEdges(),n.add(r),e.add(r.getDirectedEdges(),r.getNodes())}}},{key:"createSubgraphs",value:function(t){for(var e=new pt,n=t.getNodes().iterator();n.hasNext();){var i=n.next();if(!i.isVisited()){var r=new mt;r.create(i),e.add(r)}}return Ke.sort(e,Ke.reverseOrder()),e}},{key:"createEmptyResultGeometry",value:function(){return this.Dl.createPolygon()}},{key:"getNoder",value:function(t){if(null!==this.Nl)return this.Nl;var e=new wn,n=new be;return n.setPrecisionModel(t),e.setSegmentIntersector(new qn(n)),e}},{key:"buffer",value:function(t,e){var n=this.Pl;null===n&&(n=t.getPrecisionModel()),this.Dl=t.getFactory();var i=new $n(n,this.Qh),r=new On(t,e,i).getCurves();if(r.size()<=0)return this.createEmptyResultGeometry();this.computeNodedEdges(r,n),this.Ul=new Be(new Pn),this.Ul.addEdges(this.yl.getEdges());var s=this.createSubgraphs(this.Ul),o=new Le(this.Dl);this.buildSubgraphs(s,o);var a=o.getPolygons();return a.size()<=0?this.createEmptyResultGeometry():this.Dl.buildGeometry(a)}},{key:"computeNodedEdges",value:function(t,e){var n=this.getNoder(e);n.computeNodes(t);for(var i=n.getNodedSubstrings().iterator();i.hasNext();){var r=i.next(),s=r.getCoordinates();if(2!==s.length||!s[0].equals2D(s[1])){var o=r.getData(),a=new Yn(r.getCoordinates(),new $e(o));this.insertUniqueEdge(a)}}}},{key:"setNoder",value:function(t){this.Nl=t}}],[{key:"constructor_",value:function(){this.Qh=null,this.Pl=null,this.Nl=null,this.Dl=null,this.Ul=null,this.yl=new Nn;var t=arguments[0];this.Qh=t}},{key:"depthDelta",value:function(t){var e=t.getLocation(0,Z.LEFT),n=t.getLocation(0,Z.RIGHT);return e===W.INTERIOR&&n===W.EXTERIOR?1:e===W.EXTERIOR&&n===W.INTERIOR?-1:0}},{key:"convertSegStrings",value:function(t){for(var e=new se,n=new pt;t.hasNext();){var i=t.next(),r=e.createLineString(i.getCoordinates());n.add(r)}return e.buildGeometry(n)}}])}(),Xn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"rescale",value:function(){if(it(arguments[0],V))for(var t=arguments[0].iterator();t.hasNext();){var e=t.next();this.rescale(e.getCoordinates())}else if(arguments[0]instanceof Array){for(var n=arguments[0],i=0;i<n.length;i++)n[i].x=n[i].x/this.ql+this.jl,n[i].y=n[i].y/this.ql+this.Bl;2===n.length&&n[0].equals2D(n[1])&&wt.out.println(n)}}},{key:"scale",value:function(){if(it(arguments[0],V)){for(var t=arguments[0],e=new pt(t.size()),n=t.iterator();n.hasNext();){var i=n.next();e.add(new cn(this.scale(i.getCoordinates()),i.getData()))}return e}if(arguments[0]instanceof Array){for(var r=arguments[0],s=new Array(r.length).fill(null),o=0;o<r.length;o++)s[o]=new j(Math.round((r[o].x-this.jl)*this.ql),Math.round((r[o].y-this.Bl)*this.ql),r[o].getZ());return Gt.removeRepeatedPoints(s)}}},{key:"isIntegerPrecision",value:function(){return 1===this.ql}},{key:"getNodedSubstrings",value:function(){var t=this.Ll.getNodedSubstrings();return this.Hl&&this.rescale(t),t}},{key:"computeNodes",value:function(t){var e=t;this.Hl&&(e=this.scale(t)),this.Ll.computeNodes(e)}},{key:"interfaces_",get:function(){return[mn]}}],[{key:"constructor_",value:function(){if(this.Ll=null,this.ql=null,this.jl=null,this.Bl=null,this.Hl=!1,2===arguments.length){var e=arguments[0],n=arguments[1];t.constructor_.call(this,e,n,0,0)}else if(4===arguments.length){var i=arguments[0],r=arguments[1];this.Ll=i,this.ql=r,this.Hl=!this.isIntegerPrecision()}}}])}(),Qn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"checkEndPtVertexIntersections",value:function(){if(0===arguments.length)for(var t=this.Wl.iterator();t.hasNext();){var e=t.next().getCoordinates();this.checkEndPtVertexIntersections(e[0],this.Wl),this.checkEndPtVertexIntersections(e[e.length-1],this.Wl)}else if(2===arguments.length)for(var n=arguments[0],i=arguments[1].iterator();i.hasNext();)for(var r=i.next().getCoordinates(),s=1;s<r.length-1;s++)if(r[s].equals(n))throw new F("found endpt/interior pt intersection at index "+s+" :pt "+n)}},{key:"checkInteriorIntersections",value:function(){if(0===arguments.length)for(var t=this.Wl.iterator();t.hasNext();)for(var e=t.next(),n=this.Wl.iterator();n.hasNext();){var i=n.next();this.checkInteriorIntersections(e,i)}else if(2===arguments.length)for(var r=arguments[0],s=arguments[1],o=r.getCoordinates(),a=s.getCoordinates(),u=0;u<o.length-1;u++)for(var h=0;h<a.length-1;h++)this.checkInteriorIntersections(r,u,s,h);else if(4===arguments.length){var l=arguments[0],c=arguments[1],f=arguments[2],d=arguments[3];if(l===f&&c===d)return null;var p=l.getCoordinates()[c],v=l.getCoordinates()[c+1],m=f.getCoordinates()[d],y=f.getCoordinates()[d+1];if(this.el.computeIntersection(p,v,m,y),this.el.hasIntersection()&&(this.el.isProper()||this.hasInteriorIntersection(this.el,p,v)||this.hasInteriorIntersection(this.el,m,y)))throw new F("found non-noded intersection at "+p+"-"+v+" and "+m+"-"+y)}}},{key:"checkValid",value:function(){this.checkEndPtVertexIntersections(),this.checkInteriorIntersections(),this.checkCollapses()}},{key:"checkCollapses",value:function(){if(0===arguments.length)for(var t=this.Wl.iterator();t.hasNext();){var e=t.next();this.checkCollapses(e)}else if(1===arguments.length)for(var n=arguments[0].getCoordinates(),i=0;i<n.length-2;i++)this.checkCollapse(n[i],n[i+1],n[i+2])}},{key:"hasInteriorIntersection",value:function(t,e,n){for(var i=0;i<t.getIntersectionNum();i++){var r=t.getIntersection(i);if(!r.equals(e)&&!r.equals(n))return!0}return!1}},{key:"checkCollapse",value:function(e,n,i){if(e.equals(i))throw new F("found non-noded collapse at "+t.fact.createLineString([e,n,i]))}}],[{key:"constructor_",value:function(){this.el=new be,this.Wl=null;var t=arguments[0];this.Wl=t}}])}();Qn.fact=new se;var Zn=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"intersectsScaled",value:function(t,e){var n=Math.min(t.x,e.x),i=Math.max(t.x,e.x),r=Math.min(t.y,e.y),s=Math.max(t.y,e.y),o=this.Xo<n||this.Zo>i||this.Qo<r||this.Jo>s;if(o)return!1;var a=this.intersectsToleranceSquare(t,e);return D.isTrue(!(o&&a),"Found bad envelope test"),a}},{key:"initCorners",value:function(t){var e=.5;this.Zo=t.x-e,this.Xo=t.x+e,this.Jo=t.y-e,this.Qo=t.y+e,this.Vl[0]=new j(this.Xo,this.Qo),this.Vl[1]=new j(this.Zo,this.Qo),this.Vl[2]=new j(this.Zo,this.Jo),this.Vl[3]=new j(this.Xo,this.Jo)}},{key:"intersects",value:function(t,e){return 1===this.ql?this.intersectsScaled(t,e):(this.copyScaled(t,this.Gl),this.copyScaled(e,this.Yl),this.intersectsScaled(this.Gl,this.Yl))}},{key:"scale",value:function(t){return Math.round(t*this.ql)}},{key:"getCoordinate",value:function(){return this.Kl}},{key:"copyScaled",value:function(t,e){e.x=this.scale(t.x),e.y=this.scale(t.y)}},{key:"getSafeEnvelope",value:function(){if(null===this.Xl){var e=t.SAFE_ENV_EXPANSION_FACTOR/this.ql;this.Xl=new L(this.Kl.x-e,this.Kl.x+e,this.Kl.y-e,this.Kl.y+e)}return this.Xl}},{key:"intersectsPixelClosure",value:function(t,e){return this.el.computeIntersection(t,e,this.Vl[0],this.Vl[1]),!!(this.el.hasIntersection()||(this.el.computeIntersection(t,e,this.Vl[1],this.Vl[2]),this.el.hasIntersection()||(this.el.computeIntersection(t,e,this.Vl[2],this.Vl[3]),this.el.hasIntersection()||(this.el.computeIntersection(t,e,this.Vl[3],this.Vl[0]),this.el.hasIntersection()))))}},{key:"intersectsToleranceSquare",value:function(t,e){var n=!1,i=!1;return this.el.computeIntersection(t,e,this.Vl[0],this.Vl[1]),!!(this.el.isProper()||(this.el.computeIntersection(t,e,this.Vl[1],this.Vl[2]),this.el.isProper()||(this.el.hasIntersection()&&(n=!0),this.el.computeIntersection(t,e,this.Vl[2],this.Vl[3]),this.el.isProper()||(this.el.hasIntersection()&&(i=!0),this.el.computeIntersection(t,e,this.Vl[3],this.Vl[0]),this.el.isProper()||n&&i||t.equals(this.Ql)||e.equals(this.Ql)))))}},{key:"addSnappedNode",value:function(t,e){var n=t.getCoordinate(e),i=t.getCoordinate(e+1);return!!this.intersects(n,i)&&(t.addIntersection(this.getCoordinate(),e),!0)}}],[{key:"constructor_",value:function(){this.el=null,this.Ql=null,this.Kl=null,this.Zl=null,this.Gl=null,this.Yl=null,this.ql=null,this.Zo=null,this.Xo=null,this.Jo=null,this.Qo=null,this.Vl=new Array(4).fill(null),this.Xl=null;var t=arguments[0],e=arguments[1],n=arguments[2];if(this.Kl=t,this.Ql=t,this.ql=e,this.el=n,e<=0)throw new g("Scale factor must be non-zero");1!==e&&(this.Ql=new j(this.scale(t.x),this.scale(t.y)),this.Gl=new j,this.Yl=new j),this.initCorners(this.Ql)}}])}();Zn.SAFE_ENV_EXPANSION_FACTOR=.75;var Jn=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"select",value:function(){if(1===arguments.length);else if(2===arguments.length){var t=arguments[1];arguments[0].getLineSegment(t,this.selectedSegment),this.select(this.selectedSegment)}}}],[{key:"constructor_",value:function(){this.selectedSegment=new fn}}]),ti=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"snap",value:function(){if(1===arguments.length){var t=arguments[0];return this.snap(t,null,-1)}if(3===arguments.length){var e=arguments[0],i=arguments[1],r=arguments[2],o=e.getSafeEnvelope(),a=new ei(e,i,r);return this._index.query(o,new(s((function t(){n(this,t)}),[{key:"interfaces_",get:function(){return[Ze]}},{key:"visitItem",value:function(t){t.select(o,a)}}]))),a.isNodeAdded()}}}],[{key:"constructor_",value:function(){this._index=null;var t=arguments[0];this._index=t}}]),ei=function(t){function i(){var t;return n(this,i),t=e(this,i),i.constructor_.apply(t,arguments),t}return h(i,t),s(i,[{key:"isNodeAdded",value:function(){return this.Jl}},{key:"select",value:function(){if(!(2===arguments.length&&Number.isInteger(arguments[1])&&arguments[0]instanceof pn))return f(i,"select",this,1).apply(this,arguments);var t=arguments[1],e=arguments[0].getContext();if(this.tc===e&&(t===this.rc||t+1===this.rc))return null;this.Jl|=this.sc.addSnappedNode(e,t)}}],[{key:"constructor_",value:function(){this.sc=null,this.tc=null,this.rc=null,this.Jl=!1;var t=arguments[0],e=arguments[1],n=arguments[2];this.sc=t,this.tc=e,this.rc=n}}])}(Jn);ti.HotPixelSnapAction=ei;var ni=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"processIntersections",value:function(t,e,n,i){if(t===n&&e===i)return null;var r=t.getCoordinates()[e],s=t.getCoordinates()[e+1],o=n.getCoordinates()[i],a=n.getCoordinates()[i+1];if(this.el.computeIntersection(r,s,o,a),this.el.hasIntersection()&&this.el.isInteriorIntersection()){for(var u=0;u<this.el.getIntersectionNum();u++)this.oc.add(this.el.getIntersection(u));t.addIntersections(this.el,e,0),n.addIntersections(this.el,i,1)}}},{key:"isDone",value:function(){return!1}},{key:"getInteriorIntersections",value:function(){return this.oc}},{key:"interfaces_",get:function(){return[Un]}}],[{key:"constructor_",value:function(){this.el=null,this.oc=null;var t=arguments[0];this.el=t,this.oc=new pt}}]),ii=s((function t(){n(this,t),t.constructor_.apply(this,arguments)}),[{key:"checkCorrectness",value:function(t){var e=cn.getNodedSubstrings(t),n=new Qn(e);try{n.checkValid()}catch(t){if(!(t instanceof w))throw t;t.printStackTrace()}}},{key:"getNodedSubstrings",value:function(){return cn.getNodedSubstrings(this.Rh)}},{key:"snapRound",value:function(t,e){var n=this.findInteriorIntersections(t,e);this.computeIntersectionSnaps(n),this.computeVertexSnaps(t)}},{key:"findInteriorIntersections",value:function(t,e){var n=new ni(e);return this.Ll.setSegmentIntersector(n),this.Ll.computeNodes(t),n.getInteriorIntersections()}},{key:"computeVertexSnaps",value:function(){if(it(arguments[0],V))for(var t=arguments[0].iterator();t.hasNext();){var e=t.next();this.computeVertexSnaps(e)}else if(arguments[0]instanceof cn)for(var n=arguments[0],i=n.getCoordinates(),r=0;r<i.length;r++){var s=new Zn(i[r],this.ql,this.el);this.uc.snap(s,n,r)&&n.addIntersection(i[r],r)}}},{key:"computeNodes",value:function(t){this.Rh=t,this.Ll=new wn,this.uc=new ti(this.Ll.getIndex()),this.snapRound(t,this.el)}},{key:"computeIntersectionSnaps",value:function(t){for(var e=t.iterator();e.hasNext();){var n=e.next(),i=new Zn(n,this.ql,this.el);this.uc.snap(i)}}},{key:"interfaces_",get:function(){return[mn]}}],[{key:"constructor_",value:function(){this.lc=null,this.el=null,this.ql=null,this.Ll=null,this.uc=null,this.Rh=null;var t=arguments[0];this.lc=t,this.el=new be,this.el.setPrecisionModel(t),this.ql=t.getScale()}}]),ri=function(){function t(){n(this,t),t.constructor_.apply(this,arguments)}return s(t,[{key:"bufferFixedPrecision",value:function(t){var e=new Xn(new ii(new ne(1)),t.getScale()),n=new Kn(this.Qh);n.setWorkingPrecisionModel(t),n.setNoder(e),this.vc=n.buffer(this.yc,this.wh)}},{key:"bufferReducedPrecision",value:function(){if(0===arguments.length){for(var e=t.MAX_PRECISION_DIGITS;e>=0;e--){try{this.bufferReducedPrecision(e)}catch(t){if(!(t instanceof ft))throw t;this.wc=t}if(null!==this.vc)return null}throw this.wc}if(1===arguments.length){var n=arguments[0],i=t.precisionScaleFactor(this.yc,this.wh,n),r=new ne(i);this.bufferFixedPrecision(r)}}},{key:"computeGeometry",value:function(){if(this.bufferOriginalPrecision(),null!==this.vc)return null;var t=this.yc.getFactory().getPrecisionModel();t.getType()===ne.FIXED?this.bufferFixedPrecision(t):this.bufferReducedPrecision()}},{key:"setQuadrantSegments",value:function(t){this.Qh.setQuadrantSegments(t)}},{key:"bufferOriginalPrecision",value:function(){try{var t=new Kn(this.Qh);this.vc=t.buffer(this.yc,this.wh)}catch(t){if(!(t instanceof F))throw t;this.wc=t}}},{key:"getResultGeometry",value:function(t){return this.wh=t,this.computeGeometry(),this.vc}},{key:"setEndCapStyle",value:function(t){this.Qh.setEndCapStyle(t)}}],[{key:"constructor_",value:function(){if(this.yc=null,this.wh=null,this.Qh=new y,this.vc=null,this.wc=null,1===arguments.length){var t=arguments[0];this.yc=t}else if(2===arguments.length){var e=arguments[0],n=arguments[1];this.yc=e,this.Qh=n}}},{key:"bufferOp",value:function(){if(2===arguments.length){var e=arguments[1];return new t(arguments[0]).getResultGeometry(e)}if(3===arguments.length){if(Number.isInteger(arguments[2])&&arguments[0]instanceof H&&"number"==typeof arguments[1]){var n=arguments[1],i=arguments[2],r=new t(arguments[0]);return r.setQuadrantSegments(i),r.getResultGeometry(n)}if(arguments[2]instanceof y&&arguments[0]instanceof H&&"number"==typeof arguments[1]){var s=arguments[1];return new t(arguments[0],arguments[2]).getResultGeometry(s)}}else if(4===arguments.length){var o=arguments[1],a=arguments[2],u=arguments[3],h=new t(arguments[0]);return h.setQuadrantSegments(a),h.setEndCapStyle(u),h.getResultGeometry(o)}}},{key:"precisionScaleFactor",value:function(t,e,n){var i=t.getEnvelopeInternal(),r=gt.max(Math.abs(i.getMaxX()),Math.abs(i.getMaxY()),Math.abs(i.getMinX()),Math.abs(i.getMinY()))+2*(e>0?e:0),s=n-Math.trunc(Math.log(r)/Math.log(10)+1);return Math.pow(10,s)}}])}();ri.CAP_ROUND=y.CAP_ROUND,ri.CAP_BUTT=y.CAP_FLAT,ri.CAP_FLAT=y.CAP_FLAT,ri.CAP_SQUARE=y.CAP_SQUARE,ri.MAX_PRECISION_DIGITS=12;var si=["Point","MultiPoint","LineString","MultiLineString","Polygon","MultiPolygon"],oi=s((function t(e){n(this,t),this.geometryFactory=e||new se}),[{key:"read",value:function(t){var e,n=(e="string"==typeof t?JSON.parse(t):t).type;if(!ai[n])throw new Error("Unknown GeoJSON type: "+e.type);return-1!==si.indexOf(n)?ai[n].call(this,e.coordinates):"GeometryCollection"===n?ai[n].call(this,e.geometries):ai[n].call(this,e)}},{key:"write",value:function(t){var e=t.getGeometryType();if(!ui[e])throw new Error("Geometry is not supported");return ui[e].call(this,t)}}]),ai={Feature:function(t){var e={};for(var n in t)e[n]=t[n];if(t.geometry){var i=t.geometry.type;if(!ai[i])throw new Error("Unknown GeoJSON type: "+t.type);e.geometry=this.read(t.geometry)}return t.bbox&&(e.bbox=ai.bbox.call(this,t.bbox)),e},FeatureCollection:function(t){var e={};if(t.features){e.features=[];for(var n=0;n<t.features.length;++n)e.features.push(this.read(t.features[n]))}return t.bbox&&(e.bbox=this.parse.bbox.call(this,t.bbox)),e},coordinates:function(t){for(var e=[],n=0;n<t.length;++n){var r=t[n];e.push(i(j,d(r)))}return e},bbox:function(t){return this.geometryFactory.createLinearRing([new j(t[0],t[1]),new j(t[2],t[1]),new j(t[2],t[3]),new j(t[0],t[3]),new j(t[0],t[1])])},Point:function(t){var e=i(j,d(t));return this.geometryFactory.createPoint(e)},MultiPoint:function(t){for(var e=[],n=0;n<t.length;++n)e.push(ai.Point.call(this,t[n]));return this.geometryFactory.createMultiPoint(e)},LineString:function(t){var e=ai.coordinates.call(this,t);return this.geometryFactory.createLineString(e)},MultiLineString:function(t){for(var e=[],n=0;n<t.length;++n)e.push(ai.LineString.call(this,t[n]));return this.geometryFactory.createMultiLineString(e)},Polygon:function(t){for(var e=ai.coordinates.call(this,t[0]),n=this.geometryFactory.createLinearRing(e),i=[],r=1;r<t.length;++r){var s=t[r],o=ai.coordinates.call(this,s),a=this.geometryFactory.createLinearRing(o);i.push(a)}return this.geometryFactory.createPolygon(n,i)},MultiPolygon:function(t){for(var e=[],n=0;n<t.length;++n){var i=t[n];e.push(ai.Polygon.call(this,i))}return this.geometryFactory.createMultiPolygon(e)},GeometryCollection:function(t){for(var e=[],n=0;n<t.length;++n){var i=t[n];e.push(this.read(i))}return this.geometryFactory.createGeometryCollection(e)}},ui={coordinate:function(t){var e=[t.x,t.y];return t.z&&e.push(t.z),t.m&&e.push(t.m),e},Point:function(t){return{type:"Point",coordinates:ui.coordinate.call(this,t.getCoordinate())}},MultiPoint:function(t){for(var e=[],n=0;n<t.yu.length;++n){var i=t.yu[n],r=ui.Point.call(this,i);e.push(r.coordinates)}return{type:"MultiPoint",coordinates:e}},LineString:function(t){for(var e=[],n=t.getCoordinates(),i=0;i<n.length;++i){var r=n[i];e.push(ui.coordinate.call(this,r))}return{type:"LineString",coordinates:e}},MultiLineString:function(t){for(var e=[],n=0;n<t.yu.length;++n){var i=t.yu[n],r=ui.LineString.call(this,i);e.push(r.coordinates)}return{type:"MultiLineString",coordinates:e}},Polygon:function(t){var e=[],n=ui.LineString.call(this,t.vu);e.push(n.coordinates);for(var i=0;i<t.mu.length;++i){var r=t.mu[i],s=ui.LineString.call(this,r);e.push(s.coordinates)}return{type:"Polygon",coordinates:e}},MultiPolygon:function(t){for(var e=[],n=0;n<t.yu.length;++n){var i=t.yu[n],r=ui.Polygon.call(this,i);e.push(r.coordinates)}return{type:"MultiPolygon",coordinates:e}},GeometryCollection:function(t){for(var e=[],n=0;n<t.yu.length;++n){var i=t.yu[n],r=i.getGeometryType();e.push(ui[r].call(this,i))}return{type:"GeometryCollection",geometries:e}}};return{BufferOp:ri,GeoJSONReader:s((function t(e){n(this,t),this.parser=new oi(e||new se)}),[{key:"read",value:function(t){return this.parser.read(t)}}]),GeoJSONWriter:s((function t(){n(this,t),this.parser=new oi(this.geometryFactory)}),[{key:"write",value:function(t){return this.parser.write(t)}}])}}()),Hf.exports),Vf=Bf(Wf);function Gf(){return new Yf}function Yf(){this.reset()}Yf.prototype={constructor:Yf,reset:function(){this.s=this.t=0},add:function(t){Xf(Kf,t,this.t),Xf(this,Kf.s,this.s),this.s?this.t+=Kf.t:this.s=Kf.t},valueOf:function(){return this.s}};var Kf=new Yf;function Xf(t,e,n){var i=t.s=e+n,r=i-e,s=i-r;t.t=e-s+(n-r)}var Qf=1e-6,Zf=Math.PI,Jf=Zf/2,td=Zf/4,ed=2*Zf,nd=180/Zf,id=Zf/180,rd=Math.abs,sd=Math.atan,od=Math.atan2,ad=Math.cos,ud=Math.sin,hd=Math.sqrt;function ld(t){return t>1?0:t<-1?Zf:Math.acos(t)}function cd(t){return t>1?Jf:t<-1?-Jf:Math.asin(t)}function fd(){}function dd(t,e){t&&yd.hasOwnProperty(t.type)&&yd[t.type](t,e)}var pd,vd,md={Feature:function(t,e){dd(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)dd(n[i].geometry,e)}},yd={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)t=n[i],e.point(t[0],t[1],t[2])},LineString:function(t,e){wd(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)wd(n[i],e,0)},Polygon:function(t,e){gd(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)gd(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)dd(n[i],e)}};function wd(t,e,n){var i,r=-1,s=t.length-n;for(e.lineStart();++r<s;)i=t[r],e.point(i[0],i[1],i[2]);e.lineEnd()}function gd(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)wd(t[n],e,1);e.polygonEnd()}function bd(t){return[od(t[1],t[0]),cd(t[2])]}function _d(t){var e=t[0],n=t[1],i=ad(n);return[i*ad(e),i*ud(e),ud(n)]}function xd(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function kd(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function $d(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Sd(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Md(t){var e=hd(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}function Ed(t,e){function n(n,i){return n=t(n,i),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,i){return(n=e.invert(n,i))&&t.invert(n[0],n[1])}),n}function Cd(t,e){return[t>Zf?t-ed:t<-Zf?t+ed:t,e]}function Ad(t){return function(e,n){return[(e+=t)>Zf?e-ed:e<-Zf?e+ed:e,n]}}function Od(t){var e=Ad(t);return e.invert=Ad(-t),e}function Id(t,e){var n=ad(t),i=ud(t),r=ad(e),s=ud(e);function o(t,e){var o=ad(e),a=ad(t)*o,u=ud(t)*o,h=ud(e),l=h*n+a*i;return[od(u*r-l*s,a*n-h*i),cd(l*r+u*s)]}return o.invert=function(t,e){var o=ad(e),a=ad(t)*o,u=ud(t)*o,h=ud(e),l=h*r-u*s;return[od(u*r+h*s,a*n+l*i),cd(l*n-a*i)]},o}function Td(t,e){(e=_d(e))[0]-=t,Md(e);var n=ld(-e[1]);return((-e[2]<0?-n:n)+ed-Qf)%ed}function zd(){var t,e=[];return{point:function(e,n){t.push([e,n])},lineStart:function(){e.push(t=[])},lineEnd:fd,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Rd(t,e){return rd(t[0]-e[0])<Qf&&rd(t[1]-e[1])<Qf}function Fd(t,e,n,i){this.x=t,this.z=e,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Pd(t,e,n,i,r){var s,o,a=[],u=[];if(t.forEach((function(t){if(!((e=t.length-1)<=0)){var e,n,i=t[0],o=t[e];if(Rd(i,o)){for(r.lineStart(),s=0;s<e;++s)r.point((i=t[s])[0],i[1]);r.lineEnd()}else a.push(n=new Fd(i,t,null,!0)),u.push(n.o=new Fd(i,null,n,!1)),a.push(n=new Fd(o,t,null,!1)),u.push(n.o=new Fd(o,null,n,!0))}})),a.length){for(u.sort(e),Dd(a),Dd(u),s=0,o=u.length;s<o;++s)u[s].e=n=!n;for(var h,l,c=a[0];;){for(var f=c,d=!0;f.v;)if((f=f.n)===c)return;h=f.z,r.lineStart();do{if(f.v=f.o.v=!0,f.e){if(d)for(s=0,o=h.length;s<o;++s)r.point((l=h[s])[0],l[1]);else i(f.x,f.n.x,1,r);f=f.n}else{if(d)for(h=f.p.z,s=h.length-1;s>=0;--s)r.point((l=h[s])[0],l[1]);else i(f.x,f.p.x,-1,r);f=f.p}h=(f=f.o).z,d=!d}while(!f.v);r.lineEnd()}}}function Dd(t){if(e=t.length){for(var e,n,i=0,r=t[0];++i<e;)r.n=n=t[i],n.p=r,r=n;r.n=n=t[0],n.p=r}}function Nd(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function Ud(t){for(var e,n,i,r=t.length,s=-1,o=0;++s<r;)o+=t[s].length;for(n=new Array(o);--r>=0;)for(e=(i=t[r]).length;--e>=0;)n[--o]=i[e];return n}Gf(),Gf(),Gf(),Cd.invert=Cd,1===(pd=Nd).length&&(vd=pd,pd=function(t,e){return Nd(vd(t),e)});var qd=1e9,jd=-1e9,Bd=Gf();function Ld(t){return t}Gf(),Gf(),Gf();var Hd=1/0,Wd=Hd,Vd=-Hd,Gd=Vd,Yd={point:function(t,e){t<Hd&&(Hd=t),t>Vd&&(Vd=t),e<Wd&&(Wd=e),e>Gd&&(Gd=e)},lineStart:fd,lineEnd:fd,polygonStart:fd,polygonEnd:fd,result:function(){var t=[[Hd,Wd],[Vd,Gd]];return Vd=Gd=-(Wd=Hd=1/0),t}};function Kd(t,e,n,i){return function(r,s){var o,a,u,h=e(s),l=r.invert(i[0],i[1]),c=zd(),f=e(c),d=!1,p={point:v,lineStart:y,lineEnd:w,polygonStart:function(){p.point=g,p.lineStart=b,p.lineEnd=_,a=[],o=[]},polygonEnd:function(){p.point=v,p.lineStart=y,p.lineEnd=w,a=Ud(a);var t=function(t,e){var n=e[0],i=e[1],r=[ud(n),-ad(n),0],s=0,o=0;Bd.reset();for(var a=0,u=t.length;a<u;++a)if(l=(h=t[a]).length)for(var h,l,c=h[l-1],f=c[0],d=c[1]/2+td,p=ud(d),v=ad(d),m=0;m<l;++m,f=w,p=b,v=_,c=y){var y=h[m],w=y[0],g=y[1]/2+td,b=ud(g),_=ad(g),x=w-f,k=x>=0?1:-1,$=k*x,S=$>Zf,M=p*b;if(Bd.add(od(M*k*ud($),v*_+M*ad($))),s+=S?x+k*ed:x,S^f>=n^w>=n){var E=kd(_d(c),_d(y));Md(E);var C=kd(r,E);Md(C);var A=(S^x>=0?-1:1)*cd(C[2]);(i>A||i===A&&(E[0]||E[1]))&&(o+=S^x>=0?1:-1)}}return(s<-1e-6||s<Qf&&Bd<-1e-6)^1&o}(o,l);a.length?(d||(s.polygonStart(),d=!0),Pd(a,Qd,t,n,s)):t&&(d||(s.polygonStart(),d=!0),s.lineStart(),n(null,null,1,s),s.lineEnd()),d&&(s.polygonEnd(),d=!1),a=o=null},sphere:function(){s.polygonStart(),s.lineStart(),n(null,null,1,s),s.lineEnd(),s.polygonEnd()}};function v(e,n){var i=r(e,n);t(e=i[0],n=i[1])&&s.point(e,n)}function m(t,e){var n=r(t,e);h.point(n[0],n[1])}function y(){p.point=m,h.lineStart()}function w(){p.point=v,h.lineEnd()}function g(t,e){u.push([t,e]);var n=r(t,e);f.point(n[0],n[1])}function b(){f.lineStart(),u=[]}function _(){g(u[0][0],u[0][1]),f.lineEnd();var t,e,n,i,r=f.clean(),h=c.result(),l=h.length;if(u.pop(),o.push(u),u=null,l)if(1&r){if((e=(n=h[0]).length-1)>0){for(d||(s.polygonStart(),d=!0),s.lineStart(),t=0;t<e;++t)s.point((i=n[t])[0],i[1]);s.lineEnd()}}else l>1&&2&r&&h.push(h.pop().concat(h.shift())),a.push(h.filter(Xd))}return p}}function Xd(t){return t.length>1}function Qd(t,e){return((t=t.x)[0]<0?t[1]-Jf-Qf:Jf-t[1])-((e=e.x)[0]<0?e[1]-Jf-Qf:Jf-e[1])}Gf();var Zd=Kd((function(){return!0}),(function(t){var e,n=NaN,i=NaN,r=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(s,o){var a=s>0?Zf:-Zf,u=rd(s-n);rd(u-Zf)<Qf?(t.point(n,i=(i+o)/2>0?Jf:-Jf),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(s,i),e=0):r!==a&&u>=Zf&&(rd(n-r)<Qf&&(n-=r*Qf),rd(s-a)<Qf&&(s-=a*Qf),i=function(t,e,n,i){var r,s,o=ud(t-n);return rd(o)>Qf?sd((ud(e)*(s=ad(i))*ud(n)-ud(i)*(r=ad(e))*ud(t))/(r*s*o)):(e+i)/2}(n,i,s,o),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),e=0),t.point(n=s,i=o),r=a},lineEnd:function(){t.lineEnd(),n=i=NaN},clean:function(){return 2-e}}}),(function(t,e,n,i){var r;if(null==t)r=n*Jf,i.point(-Zf,r),i.point(0,r),i.point(Zf,r),i.point(Zf,0),i.point(Zf,-r),i.point(0,-r),i.point(-Zf,-r),i.point(-Zf,0),i.point(-Zf,r);else if(rd(t[0]-e[0])>Qf){var s=t[0]<e[0]?Zf:-Zf;r=n*s/2,i.point(-s,r),i.point(0,r),i.point(s,r)}else i.point(e[0],e[1])}),[-Zf,-Jf]);function Jd(t){return function(e){var n=new tp;for(var i in t)n[i]=t[i];return n.stream=e,n}}function tp(){}function ep(t,e,n){var i=e[1][0]-e[0][0],r=e[1][1]-e[0][1],s=t.clipExtent&&t.clipExtent();t.scale(150).translate([0,0]),null!=s&&t.clipExtent(null),function(t,e){t&&md.hasOwnProperty(t.type)?md[t.type](t,e):dd(t,e)}(n,t.stream(Yd));var o=Yd.result(),a=Math.min(i/(o[1][0]-o[0][0]),r/(o[1][1]-o[0][1])),u=+e[0][0]+(i-a*(o[1][0]+o[0][0]))/2,h=+e[0][1]+(r-a*(o[1][1]+o[0][1]))/2;return null!=s&&t.clipExtent(s),t.scale(150*a).translate([u,h])}tp.prototype={constructor:tp,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var np=ad(30*id);function ip(t,e){return+e?function(t,e){function n(i,r,s,o,a,u,h,l,c,f,d,p,v,m){var y=h-i,w=l-r,g=y*y+w*w;if(g>4*e&&v--){var b=o+f,_=a+d,x=u+p,k=hd(b*b+_*_+x*x),$=cd(x/=k),S=rd(rd(x)-1)<Qf||rd(s-c)<Qf?(s+c)/2:od(_,b),M=t(S,$),E=M[0],C=M[1],A=E-i,O=C-r,I=w*A-y*O;(I*I/g>e||rd((y*A+w*O)/g-.5)>.3||o*f+a*d+u*p<np)&&(n(i,r,s,o,a,u,E,C,S,b/=k,_/=k,x,v,m),m.point(E,C),n(E,C,S,b,_,x,h,l,c,f,d,p,v,m))}}return function(e){var i,r,s,o,a,u,h,l,c,f,d,p,v={point:m,lineStart:y,lineEnd:g,polygonStart:function(){e.polygonStart(),v.lineStart=b},polygonEnd:function(){e.polygonEnd(),v.lineStart=y}};function m(n,i){n=t(n,i),e.point(n[0],n[1])}function y(){l=NaN,v.point=w,e.lineStart()}function w(i,r){var s=_d([i,r]),o=t(i,r);n(l,c,h,f,d,p,l=o[0],c=o[1],h=i,f=s[0],d=s[1],p=s[2],16,e),e.point(l,c)}function g(){v.point=m,e.lineEnd()}function b(){y(),v.point=_,v.lineEnd=x}function _(t,e){w(i=t,e),r=l,s=c,o=f,a=d,u=p,v.point=w}function x(){n(l,c,h,f,d,p,r,s,i,o,a,u,16,e),v.lineEnd=g,g()}return v}}(t,e):function(t){return Jd({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var rp=Jd({point:function(t,e){this.stream.point(t*id,e*id)}});function sp(t){return function(e,n){var i=ad(e),r=ad(n),s=t(i*r);return[s*r*ud(e),s*ud(n)]}}function op(t){return function(e,n){var i=hd(e*e+n*n),r=t(i),s=ud(r),o=ad(r);return[od(e*s,i*o),cd(i&&n*s/i)]}}sp((function(t){return hd(2/(1+t))})).invert=op((function(t){return 2*cd(t/2)}));var ap=sp((function(t){return(t=ld(t))&&t/ud(t)}));function up(){return(t=ap,function(t){var e,n,i,r,s,o,a,u,h,l,c=150,f=480,d=250,p=0,v=0,m=0,y=0,w=0,g=null,b=Zd,_=null,x=Ld,k=.5,$=ip(E,k);function S(t){return[(t=s(t[0]*id,t[1]*id))[0]*c+n,i-t[1]*c]}function M(t){return(t=s.invert((t[0]-n)/c,(i-t[1])/c))&&[t[0]*nd,t[1]*nd]}function E(t,r){return[(t=e(t,r))[0]*c+n,i-t[1]*c]}function C(){s=Ed(r=function(t,e,n){return(t%=ed)?e||n?Ed(Od(t),Id(e,n)):Od(t):e||n?Id(e,n):Cd}(m,y,w),e);var t=e(p,v);return n=f-t[0]*c,i=d+t[1]*c,A()}function A(){return h=l=null,S}return S.stream=function(t){return h&&l===t?h:h=rp(b(r,$(x(l=t))))},S.clipAngle=function(t){return arguments.length?(b=+t?function(t,e){var n=ad(t),i=n>0,r=rd(n)>Qf;function s(t,e){return ad(t)*ad(e)>n}function o(t,e,i){var r=[1,0,0],s=kd(_d(t),_d(e)),o=xd(s,s),a=s[0],u=o-a*a;if(!u)return!i&&t;var h=n*o/u,l=-n*a/u,c=kd(r,s),f=Sd(r,h);$d(f,Sd(s,l));var d=c,p=xd(f,d),v=xd(d,d),m=p*p-v*(xd(f,f)-1);if(!(m<0)){var y=hd(m),w=Sd(d,(-p-y)/v);if($d(w,f),w=bd(w),!i)return w;var g,b=t[0],_=e[0],x=t[1],k=e[1];_<b&&(g=b,b=_,_=g);var $=_-b,S=rd($-Zf)<Qf;if(!S&&k<x&&(g=x,x=k,k=g),S||$<Qf?S?x+k>0^w[1]<(rd(w[0]-b)<Qf?x:k):x<=w[1]&&w[1]<=k:$>Zf^(b<=w[0]&&w[0]<=_)){var M=Sd(d,(-p+y)/v);return $d(M,f),[w,bd(M)]}}}function a(e,n){var r=i?t:Zf-t,s=0;return e<-r?s|=1:e>r&&(s|=2),n<-r?s|=4:n>r&&(s|=8),s}return Kd(s,(function(t){var e,n,u,h,l;return{lineStart:function(){h=u=!1,l=1},point:function(c,f){var d,p=[c,f],v=s(c,f),m=i?v?0:a(c,f):v?a(c+(c<0?Zf:-Zf),f):0;if(!e&&(h=u=v)&&t.lineStart(),v!==u&&(!(d=o(e,p))||Rd(e,d)||Rd(p,d))&&(p[0]+=Qf,p[1]+=Qf,v=s(p[0],p[1])),v!==u)l=0,v?(t.lineStart(),d=o(p,e),t.point(d[0],d[1])):(d=o(e,p),t.point(d[0],d[1]),t.lineEnd()),e=d;else if(r&&e&&i^v){var y;m&n||!(y=o(p,e,!0))||(l=0,i?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1])))}!v||e&&Rd(e,p)||t.point(p[0],p[1]),e=p,u=v,n=m},lineEnd:function(){u&&t.lineEnd(),e=null},clean:function(){return l|(h&&u)<<1}}}),(function(n,i,r,s){!function(t,e,n,i,r,s){if(n){var o=ad(e),a=ud(e),u=i*n;null==r?(r=e+i*ed,s=e-u/2):(r=Td(o,r),s=Td(o,s),(i>0?r<s:r>s)&&(r+=i*ed));for(var h,l=r;i>0?l>s:l<s;l-=u)h=bd([o,-a*ad(l),-a*ud(l)]),t.point(h[0],h[1])}}(s,t,e,r,n,i)}),i?[0,-t]:[-Zf,t-Zf])}(g=t*id,6*id):(g=null,Zd),A()):g*nd},S.clipExtent=function(t){return arguments.length?(x=null==t?(_=o=a=u=null,Ld):function(t,e,n,i){function r(r,s){return t<=r&&r<=n&&e<=s&&s<=i}function s(r,s,a,h){var l=0,c=0;if(null==r||(l=o(r,a))!==(c=o(s,a))||u(r,s)<0^a>0)do{h.point(0===l||3===l?t:n,l>1?i:e)}while((l=(l+a+4)%4)!==c);else h.point(s[0],s[1])}function o(i,r){return rd(i[0]-t)<Qf?r>0?0:3:rd(i[0]-n)<Qf?r>0?2:1:rd(i[1]-e)<Qf?r>0?1:0:r>0?3:2}function a(t,e){return u(t.x,e.x)}function u(t,e){var n=o(t,1),i=o(e,1);return n!==i?n-i:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(o){var u,h,l,c,f,d,p,v,m,y,w,g=o,b=zd(),_={point:x,lineStart:function(){_.point=k,h&&h.push(l=[]),y=!0,m=!1,p=v=NaN},lineEnd:function(){u&&(k(c,f),d&&m&&b.rejoin(),u.push(b.result())),_.point=x,m&&g.lineEnd()},polygonStart:function(){g=b,u=[],h=[],w=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,r=h.length;n<r;++n)for(var s,o,a=h[n],u=1,l=a.length,c=a[0],f=c[0],d=c[1];u<l;++u)s=f,o=d,f=(c=a[u])[0],d=c[1],o<=i?d>i&&(f-s)*(i-o)>(d-o)*(t-s)&&++e:d<=i&&(f-s)*(i-o)<(d-o)*(t-s)&&--e;return e}(),n=w&&e,r=(u=Ud(u)).length;(n||r)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),r&&Pd(u,a,e,s,o),o.polygonEnd()),g=o,u=h=l=null}};function x(t,e){r(t,e)&&g.point(t,e)}function k(s,o){var a=r(s,o);if(h&&l.push([s,o]),y)c=s,f=o,d=a,y=!1,a&&(g.lineStart(),g.point(s,o));else if(a&&m)g.point(s,o);else{var u=[p=Math.max(jd,Math.min(qd,p)),v=Math.max(jd,Math.min(qd,v))],b=[s=Math.max(jd,Math.min(qd,s)),o=Math.max(jd,Math.min(qd,o))];!function(t,e,n,i,r,s){var o,a=t[0],u=t[1],h=0,l=1,c=e[0]-a,f=e[1]-u;if(o=n-a,c||!(o>0)){if(o/=c,c<0){if(o<h)return;o<l&&(l=o)}else if(c>0){if(o>l)return;o>h&&(h=o)}if(o=r-a,c||!(o<0)){if(o/=c,c<0){if(o>l)return;o>h&&(h=o)}else if(c>0){if(o<h)return;o<l&&(l=o)}if(o=i-u,f||!(o>0)){if(o/=f,f<0){if(o<h)return;o<l&&(l=o)}else if(f>0){if(o>l)return;o>h&&(h=o)}if(o=s-u,f||!(o<0)){if(o/=f,f<0){if(o>l)return;o>h&&(h=o)}else if(f>0){if(o<h)return;o<l&&(l=o)}return h>0&&(t[0]=a+h*c,t[1]=u+h*f),l<1&&(e[0]=a+l*c,e[1]=u+l*f),!0}}}}}(u,b,t,e,n,i)?a&&(g.lineStart(),g.point(s,o),w=!1):(m||(g.lineStart(),g.point(u[0],u[1])),g.point(b[0],b[1]),a||g.lineEnd(),w=!1)}p=s,v=o,m=a}return _}}(_=+t[0][0],o=+t[0][1],a=+t[1][0],u=+t[1][1]),A()):null==_?null:[[_,o],[a,u]]},S.scale=function(t){return arguments.length?(c=+t,C()):c},S.translate=function(t){return arguments.length?(f=+t[0],d=+t[1],C()):[f,d]},S.center=function(t){return arguments.length?(p=t[0]%360*id,v=t[1]%360*id,C()):[p*nd,v*nd]},S.rotate=function(t){return arguments.length?(m=t[0]%360*id,y=t[1]%360*id,w=t.length>2?t[2]%360*id:0,C()):[m*nd,y*nd,w*nd]},S.precision=function(t){return arguments.length?($=ip(E,k=t*t),A()):hd(k)},S.fitExtent=function(t,e){return ep(S,t,e)},S.fitSize=function(t,e){return function(t,e,n){return ep(t,[[0,0],e],n)}(S,t,e)},function(){return e=t.apply(this,arguments),S.invert=e.invert&&M,C()}}((function(){return t}))()).scale(79.4188).clipAngle(179.999);var t}function hp(t,e){return[t,e]}ap.invert=op((function(t){return t})),hp.invert=hp;var{BufferOp:lp,GeoJSONReader:cp,GeoJSONWriter:fp}=Vf;function dp(t,e,n){var i=(n=n||{}).units||"kilometers",r=n.steps||8;if(!t)throw new Error("geojson is required");if("object"!=typeof n)throw new Error("options must be an object");if("number"!=typeof r)throw new Error("steps must be an number");if(void 0===e)throw new Error("radius is required");if(r<=0)throw new Error("steps must be greater than 0");var s=[];switch(t.type){case"GeometryCollection":return qf(t,(function(t){var n=pp(t,e,i,r);n&&s.push(n)})),cf(s);case"FeatureCollection":return Uf(t,(function(t){var n=pp(t,e,i,r);n&&Uf(n,(function(t){t&&s.push(t)}))})),cf(s)}return pp(t,e,i,r)}function pp(t,e,n,i){var r=t.properties||{},s="Feature"===t.type?t.geometry:t;if("GeometryCollection"===s.type){var o=[];return qf(t,(function(t){var r=pp(t,e,n,i);r&&o.push(r)})),cf(o)}var a=function(t){var e=function(t,e={}){const n=function(t,e={}){if(null!=t.bbox&&!0!==e.recompute)return t.bbox;const n=[1/0,1/0,-1/0,-1/0];return Nf(t,(t=>{n[0]>t[0]&&(n[0]=t[0]),n[1]>t[1]&&(n[1]=t[1]),n[2]<t[0]&&(n[2]=t[0]),n[3]<t[1]&&(n[3]=t[1])})),n}(t);return lf([(n[0]+n[2])/2,(n[1]+n[3])/2],e.properties,e)}(t).geometry.coordinates,n=[-e[0],-e[1]];return up().rotate(n).scale(af)}(s),u={type:s.type,coordinates:mp(s.coordinates,a)},h=(new cp).read(u),l=ff(df(e,n),"meters"),c=lp.bufferOp(h,l,i);if(!vp((c=(new fp).write(c)).coordinates))return hf({type:c.type,coordinates:yp(c.coordinates,a)},r)}function vp(t){return Array.isArray(t[0])?vp(t[0]):isNaN(t[0])}function mp(t,e){return"object"!=typeof t[0]?e(t):t.map((function(t){return mp(t,e)}))}function yp(t,e){return"object"!=typeof t[0]?e.invert(t):t.map((function(t){return yp(t,e)}))}var wp=dp;function gp(t,e){var n=yf(t);if(2===n.length&&!bp(n[0],n[1]))return n;var i=[],r=n.length-1,s=i.length;i.push(n[0]);for(var o=1;o<r;o++){var a=i[i.length-1];n[o][0]===a[0]&&n[o][1]===a[1]||(i.push(n[o]),(s=i.length)>2&&_p(i[s-3],i[s-1],i[s-2])&&i.splice(i.length-2,1))}if(i.push(n[n.length-1]),s=i.length,("Polygon"===e||"MultiPolygon"===e)&&bp(n[0],n[n.length-1])&&s<4)throw new Error("invalid polygon");return"LineString"===e&&s<3||_p(i[s-3],i[s-1],i[s-2])&&i.splice(i.length-2,1),i}function bp(t,e){return t[0]===e[0]&&t[1]===e[1]}function _p(t,e,n){var i=n[0],r=n[1],s=t[0],o=t[1],a=e[0],u=e[1],h=a-s,l=u-o;return 0==(i-s)*l-(r-o)*h&&(Math.abs(h)>=Math.abs(l)?h>0?s<=i&&i<=a:a<=i&&i<=s:l>0?o<=r&&r<=u:u<=r&&r<=o)}function xp(t,e,n){var i=e[0],r=e[1],s=n[0]-i,o=n[1]-r;if(0!==s||0!==o){var a=((t[0]-i)*s+(t[1]-r)*o)/(s*s+o*o);a>1?(i=n[0],r=n[1]):a>0&&(i+=s*a,r+=o*a)}return(s=t[0]-i)*s+(o=t[1]-r)*o}function kp(t,e,n,i,r){for(var s,o=i,a=e+1;a<n;a++){var u=xp(t[a],t[e],t[n]);u>o&&(s=a,o=u)}o>i&&(s-e>1&&kp(t,e,s,i,r),r.push(t[s]),n-s>1&&kp(t,s,n,i,r))}function $p(t,e){var n=t.length-1,i=[t[0]];return kp(t,0,n,e,i),i.push(t[n]),i}function Sp(t,e,n){if(t.length<=2)return t;var i=void 0!==e?e*e:1;return t=n?t:function(t,e){for(var n,i,r,s,o,a=t[0],u=[a],h=1,l=t.length;h<l;h++)r=a,(s=(i=n=t[h])[0]-r[0])*s+(o=i[1]-r[1])*o>e&&(u.push(n),a=n);return a!==n&&u.push(n),u}(t,i),$p(t,i)}function Mp(t,e,n){return t.map((function(t){if(t.length<4)throw new Error("invalid polygon");let i=e,r=Sp(t,i,n);for(;!Ep(r);)i-=.01*i,r=Sp(t,i,n);return r[r.length-1][0]===r[0][0]&&r[r.length-1][1]===r[0][1]||r.push(r[0]),r}))}function Ep(t){return!(t.length<3||3===t.length&&t[2][0]===t[0][0]&&t[2][1]===t[0][1])}class Cp extends Il{gc;Hn;un;sn=!0;me=!1;_c;xc=.1;$c=1/0;Sc=-1/0;Mc;Ec;Cc;Ac={enable:!1,color:new r.Color(1,1,1),intensity:1,direction:new r.Cartesian3(1,1,1)};$n={enable:!1,ambientColor:new r.Color(.9,.9,.9),lightColor:new r.Color(1,1,1),lightIntensity:1,lightDirection:new r.Cartesian3(-1,-1,-1)};Oc={metallic:0,roughness:.8};vs=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];constructor(t){super();const e=t.viewer;this.Hn=e;const n=e.scene;this.gc=new Qc({fs:t.lodFactor||1,ks:t.cacheSize||2e3,Ds:t.cacheMemorySize,cs:t.loadBuffer||0,ps:t.renderBuffer||10,Oe:t.url||"",fe:n.context,Or:t.entityInfos||[],Es:t.tileSetData||null,vs:this.vs,ys:t.maxLevelRange,Ir:t.workers,Ms:t.cacheNetworkSize,_scene:n}),this.gc.on("configloaded",(()=>{this.emit("configloaded",this.gc.Is());const t=this.gc.Is();if(t){const{enuCenter:e,bbox:n}=t,i=Math.sqrt(Math.pow(n[3]-n[0],2)+Math.pow(n[4]-n[1],2)+Math.pow(n[5]-n[2],2))/2;new r.BoundingSphere(r.Cartesian3.fromDegrees(e[0],e[1],e[2]),i)}})),this.gc.on("todrawtile",(t=>{this.emit("todrawtile",t)})),this.Oc=Object.assign(this.Oc,t.material),this.Ac=Object.assign(this.Ac,t.sunLight),this.$n=Object.assign(this.$n,t.light),t.maxPitch&&this.setMaxPitch(t.maxPitch),(t.minHeight||t.minRange||t.maxRange)&&this.setMinHeight(t.minHeight,t.minRange,t.maxRange),this.un=new zl({scene:n,ln:t.depthTest||!1,Bt:this.gc.Bt,_n:t.pass,xn:t.filter,$n:this.$n,kn:t.material,Mn:t.modelColor||new r.Color(0,0,0,0)}),this.un.on("renderfirstframe",(t=>{this.emit("renderfirstframe",t)})),t.monomerConfig&&(this.Mc=new tf({name:"单体化图层",viewer:e,tiles:[],api_url:t.monomerConfig.api_url}),this.Cc=t.monomerConfig.highlight_color),this.gc.ss=t=>{this.un.Ln(t)},this.gc.us=()=>{this.Hn?.scene.requestRender()};let i=!1;n.preRender.addEventListener((async(t,e)=>{if(this.sn&&!this.me){if(!i){i=!0;try{const e=await this.gc.Hs(t);e?.length?(this.Ic(e),this.Mc&&this.Tc(e),this.un._show()):this.un.qn(),await this.gc.Qs()}finally{i=!1}}this.gc.Ks(t),this.un.Un()}}),this);const s=n.globe.render;n.globe.render=t=>{s.call(n.globe,t),this.zc(t)}}preLoad(t,e=1e3,n){if(this.Hn){this.gc.clear("preloadComplete"),this.gc.on("preloadComplete",(()=>{this.gc.clear("preloadComplete"),n&&n()}));const i=this.getCameraPos();this.gc.Is()?this.gc.Ys(t||[i.lng,i.lat,i.height],e):this.gc.on("configloaded",(()=>{this.gc.Ys(t||[i.lng,i.lat,i.height],e)}))}}set lodFactor(t){this.gc.fs=Math.max(1e-5,Math.min(300,t)),this.Hn?.scene.requestRender()}set light(t){this.$n=t,this.un.Rn(t)}get light(){return this.$n}set material(t){this.Oc=t,this.un.Fn(t)}get material(){return this.Oc}set sunLight(t){this.Ac={enable:t.enable,direction:this.Rc()||new r.Cartesian3(1,1,1),color:t.color||this.Ac&&this.Ac.color,intensity:t.intensity},this.updateSunLight()}get sunLight(){return this.Ac}getIndexDB(){return this.gc.zs()}updateSunLight(){this.Ac&&this.Ac.enable&&(this.Ac.direction=this.Rc()||new r.Cartesian3(1,1,1),this.un.Rn({enable:!0,ambientColor:this.$n?.ambientColor||new r.Color(1,1,1),lightColor:this.Ac.color,lightIntensity:this.Ac.intensity,lightDirection:this.Ac.direction}))}setEnuCenter(t){this.un.Tn(t)}setScaleByLod(t){this.vs=t,this.gc.As(t)}Rc(){if(!this.Hn||!this.Hn.clock)return;const t=this.getEnuCenter();if(!t)return;const e=new r.Cartesian3,n=new r.Cartesian3,i=this.Hn.clock.currentTime;r.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(i,e);const s=r.Transforms.computeTemeToPseudoFixedMatrix(i);return r.Matrix3.multiplyByVector(s,e,e),r.Cartesian3.normalize(Fc(e,t,new r.Cartesian3),n),n}Ic(t){}zc(t){const e=t.commandList,n=[],i=[];for(const t of e)t.Pn?n.push(t):i.push(t);t.commandList=[...i,...n]}Tc(t){const e=[];if(t.length>0)for(let n of t){const t=n.Ti;if(!t)continue;const i=t[0];if(14===i)e.push(t.join("_"));else{const n=i-14,r=[t[0]-n,t[1]>>n,t[2]>>n];e.push(r.join("_"))}}const n=[...new Set(e)];this.Mc&&this.Mc.update(n)}getTileSetUrl(){return this.gc.Oe}getEnuCenter(){return this.gc.Is()?.enuCenter}getLimitBounds(){return this.gc.Is()?.limitBounds}getBaseHeight(){const t=this.gc.Is();return t?Math.max(0,t.bbox[2]+t.enuCenter[2]):0}getSimplyPolygon(){const t=this.gc.Is(),n=new Set,i=t=>{if(t.children?.length)t.children.forEach((t=>{i(t)}));else{const e=200*Math.round((t.bbox[0]+t.bbox[3])/2/200)+"_"+200*Math.round((t.bbox[1]+t.bbox[4])/2/200);n.add(e)}};i(t);const r=[];n.forEach((n=>{const[i,s]=n.split("_").map((t=>parseInt(t))),o=Pc(new e.Cartesian3(i,s,0),t.enuCenter);r.push(lf([180*o[0]/Math.PI,180*o[1]/Math.PI]))}));const s=function(t,e,n={}){!0!==n.mutate&&(t=ef(t));const i=n.minPoints||3,r=function(t,e){return function(t){return t%(2*Math.PI)*180/Math.PI}(df(t,e))}(e,n.units);var s=new Df(t.features.length),o=t.features.map((t=>!1)),a=t.features.map((t=>!1)),u=t.features.map((t=>!1)),h=t.features.map((t=>-1));s.load(t.features.map(((t,e)=>{var[n,i]=t.geometry.coordinates;return{minX:n,minY:i,maxX:n,maxY:i,index:e}})));const l=n=>{const i=t.features[n],[o,a]=i.geometry.coordinates,u=Math.max(a-r,-90),h=Math.min(a+r,90),l=u<0&&h>0?r:Math.abs(u)<Math.abs(h)?r/Math.cos(pf(h)):r/Math.cos(pf(u)),c={minX:Math.max(o-l,-360),minY:u,maxX:Math.min(o+l,360),maxY:h};return s.search(c).filter((n=>{const r=n.index,s=t.features[r];return wf(i,s,{units:"kilometers"})<=e}))};var c=0;return t.features.forEach(((t,e)=>{if(o[e])return;const n=l(e);if(n.length>=i){const t=c;c++,o[e]=!0,((t,e)=>{for(var n=0;n<e.length;n++){const r=e[n].index;if(!o[r]){o[r]=!0;const t=l(r);t.length>=i&&e.push(...t)}a[r]||(a[r]=!0,h[r]=t)}})(t,n)}else u[e]=!0})),t.features.forEach(((e,n)=>{var i=t.features[n];i.properties||(i.properties={}),h[n]>=0?(i.properties.dbscan=u[n]?"edge":"core",i.properties.cluster=h[n]):i.properties.dbscan="noise"})),t}(cf(r),.3),o=[];s.features.forEach((t=>{const e=t.properties.cluster;void 0!==e&&(o[e]||(o[e]=[]),o[e].push(t.geometry.coordinates))}));const a=o.map((t=>{const e=dp(function(t,e={}){var n,i,r,s;if(null===(s=e=null!=e?e:{})||"object"!=typeof s||Array.isArray(s))throw new Error("options is invalid");const o=null!=(n=e.tolerance)?n:1,a=null!=(i=e.highQuality)&&i,u=null!=(r=e.mutate)&&r;if(!t)throw new Error("geojson is required");if(o&&o<0)throw new Error("invalid tolerance");return!0!==u&&(t=ef(t)),qf(t,(function(t){!function(t,e,n){const i=t.type;if("Point"===i||"MultiPoint"===i)return t;if(function(t,e={}){var n="object"==typeof e?e.mutate:e;if(!t)throw new Error("geojson is required");var i=function(t){return"FeatureCollection"===t.type?"FeatureCollection":"GeometryCollection"===t.type?"GeometryCollection":"Feature"===t.type&&null!==t.geometry?t.geometry.type:t.type}(t),r=[];switch(i){case"LineString":r=gp(t,i);break;case"MultiLineString":case"Polygon":yf(t).forEach((function(t){r.push(gp(t,i))}));break;case"MultiPolygon":yf(t).forEach((function(t){var e=[];t.forEach((function(t){e.push(gp(t,i))})),r.push(e)}));break;case"Point":return t;case"MultiPoint":var s={};yf(t).forEach((function(t){var e=t.join("-");({}).hasOwnProperty.call(s,e)||(r.push(t),s[e]=!0)}));break;default:throw new Error(i+" geometry not supported")}t.coordinates?!0===n&&(t.coordinates=r):!0===n?t.geometry.coordinates=r:hf({type:i,coordinates:r},t.properties,{bbox:t.bbox,id:t.id})}(t,{mutate:!0}),"GeometryCollection"!==i)switch(i){case"LineString":t.coordinates=Sp(t.coordinates,e,n);break;case"MultiLineString":t.coordinates=t.coordinates.map((t=>Sp(t,e,n)));break;case"Polygon":t.coordinates=Mp(t.coordinates,e,n);break;case"MultiPolygon":t.coordinates=t.coordinates.map((t=>Mp(t,e,n)))}}(t,o,a)})),t}(dp(function(t,e,n={}){return hf({type:"MultiPoint",coordinates:t},void 0,n)}(t),.4,{steps:2}),{tolerance:.005}),-.4,{steps:1});let n;if(e)return n="Polygon"==e.geometry.type?e.geometry.coordinates[0]:e.geometry.coordinates[0][0],n.map((t=>[parseFloat(t[0].toFixed(6)),parseFloat(t[1].toFixed(6))]))}));return a.filter((t=>!!t))}setMaxPitch(t){void 0!==t?(t=t*Math.PI/180,this._c=t,this.Hn.camera.rotateUp=function(e){t&&(e&&this.pitch+e>t+.2*Math.PI/180&&(e=t-this.pitch),r.Camera.prototype.rotateUp.call(this,e))}):(this._c=void 0,this.Hn.camera.rotateUp=r.Camera.prototype.rotateUp)}getMaxPitch(){return this._c||0}setMinHeight(t,n,i){if(void 0!==t||void 0!==n||void 0!==i){this.xc=t,this.$c=n,this.Sc=i;const s=this.Hn.scene,o=this.Hn;this.Hn.camera.move=function(a,u){let h;const l=s.pickFromRay({direction:a,origin:this.positionWC});if(l&&l.position?h=l.position:o?.trackedEntity&&(h=o.trackedEntity.position?.getValue(o.clock.currentTime)),h){const r=e.Cartesian3.distance(h,this.positionWC);t&&u>0&&r*Math.cos(this.pitch+Math.PI/2)<t&&(u=0),n&&u>0&&r<n&&(u=0),i&&u<0&&r>i&&(u=0)}r.Camera.prototype.move.call(this,a,u)}}else this.xc=void 0,this.$c=void 0,this.Sc=void 0,this.Hn.camera.move=r.Camera.prototype.move}getMinHeight(){return this.xc||0}set depthTest(t){this.un.ln=t}get depthTest(){return this.un.ln}setVisibility(t,e){this.gc.Zs(t,e)}hide(){this.sn=!1,this.un.qn()}show(){this.sn=!0,this.un._show()}destroy(){this.setMaxPitch(),this.setMinHeight(),this.gc._destroy(),this.un._destroy(),this.me=!0,this.Hn=void 0,this.me=!0}destoy(){this.destroy()}pickPosition(t){const e=this.Hn.scene.pickPosition(t);if(r.defined(e)){var n=r.Cartographic.fromCartesian(e),i=r.Math.toDegrees(n.longitude),s=r.Math.toDegrees(n.latitude),o=n.height;return{lnglat:{lng:Cc(i,6),lat:Cc(s,6),alt:Cc(o,1)},ecef:e,target:this}}return null}pickEntity(t){const e=this.Hn.scene.pickPosition(t);if(r.defined(e)){var n=r.Cartographic.fromCartesian(e),i=r.Math.toDegrees(n.longitude),s=r.Math.toDegrees(n.latitude),o=n.height;return this.gc.Js([i,s,o])}return null}selectedEntity(t,e){this.gc.Ke(t,e),1==this.gc.Pe&&this.un.Ln(this.gc.qe)}getCameraPos(){if(this.Hn){var t=r.Cartographic.fromCartesian(this.Hn.camera.position),e=this.Hn.camera;return{lng:r.Math.toDegrees(t.longitude),lat:r.Math.toDegrees(t.latitude),height:t.height,heading:r.Math.toDegrees(e.heading),pitch:r.Math.toDegrees(e.pitch),roll:0}}}Ii(){return this.gc.eo()}pickMonomer(t){const e=this.Hn;if(e){const n=this.gc.eo();let i=[];const s=e.camera.getPickRay(t.position);for(let t of n){const e=t.Bs,n=t.Mr;this.Fc(s,n,e)&&i.push(t.Ti)}let o=[];for(let t of i){const e=t[0];if(e>14){const n=e-14,i=t[1]>>n,r=t[2]>>n;o.push("14_"+i+"_"+r)}14===e&&o.push(t.join("_"))}const a=[...new Set(o)];if(e.camera.pickEllipsoid(new r.Cartesian2(t.position.x,t.position.y))&&this.Mc){const t=this.Mc.pick(s,a);if(t){this.Ec&&e.entities.remove(this.Ec);let n=[];const i=t.contours;for(let e of i){const i=parseFloat(e[0]),r=parseFloat(e[1]),s=t.max_height;n.push(i),n.push(r),n.push(s)}let s="RGBA(255,0,0,0.3)";return this.Cc&&(s=this.Cc),this.Ec=e.entities.add({name:"polygon",polygon:{hierarchy:r.Cartesian3.fromDegreesArrayHeights(n),material:r.Color.fromCssColorString(s),extrudedHeight:t.min_height,perPositionHeight:!0}}),{id:t.id,contours:t.contours,max_height:t.max_height,min_height:t.min_height}}}}}Fc(t,n,i){const s=[],o=Dc(new e.Cartesian3(n[0],n[1],n[2]),i),a=Dc(new e.Cartesian3(n[3],n[1],n[2]),i),u=Dc(new e.Cartesian3(n[3],n[4],n[2]),i),h=Dc(new e.Cartesian3(n[0],n[4],n[2]),i),l=Dc(new e.Cartesian3(n[0],n[1],n[5]),i),c=Dc(new e.Cartesian3(n[3],n[1],n[5]),i),f=Dc(new e.Cartesian3(n[3],n[4],n[5]),i),d=Dc(new e.Cartesian3(n[0],n[4],n[5]),i);s.push([o,a,u]),s.push([o,u,h]),s.push([l,c,f]),s.push([l,f,d]),s.push([o,a,c]),s.push([o,c,l]),s.push([h,u,f]),s.push([h,f,d]),s.push([o,l,h]),s.push([d,l,h]),s.push([a,f,u]),s.push([a,f,c]);for(let e of s)if(r.IntersectionTests.rayTriangle(t,e[0],e[1],e[2]))return!0;return!1}pickMonomerReset(){const t=this.Hn;t&&this.Ec&&t.entities.remove(this.Ec)}}const Ap=new r.Cartesian3,Op=new r.Cartesian3,Ip=new r.Cartesian3,Tp=new r.Cartesian3(0,0,1);class zp{Pc;Dc;constructor(t=1,e=1,n=.1){this.Pc=new r.Cartesian3(t,e,n),this.Dc=0}Nc(t,e){const n=r.Cartesian3.subtract(e,t,new r.Cartesian3);n.z<0?this.Dc=r.Cartesian3.magnitude(r.Cartesian3.divideComponents(n,this.Pc,n)):this.Dc=r.Cartesian3.magnitude(new r.Cartesian3(n.x,n.y,0))}Uc(t,e=!1){t=r.Cartesian3.divideComponents(t,this.Pc,t),t=r.Cartesian3.normalize(t,t),t=r.Cartesian3.multiplyComponents(t,this.Pc,t);const n=new r.Cartesian3;if(r.Cartesian3.multiplyByScalar(t,this.Dc,n),e&&n.z>0){const t=r.Cartesian3.dot(n,Tp);r.Cartesian3.multiplyByScalar(Tp,t,Ap),r.Cartesian3.multiplyByScalar(r.Cartesian3.normalize(r.Cartesian3.fromElements(n.x,n.y,0,Ip),Ip),this.Dc,Ip),r.Cartesian3.add(n,r.Cartesian3.multiplyByScalar(r.Cartesian3.subtract(r.Cartesian3.add(Ip,Ap,Op),n,Op),2,Op),Op),n.x=Op.x,n.y=Op.y}return n.x=Math.round(100*n.x)/100,n.y=Math.round(100*n.y)/100,n.z=Math.round(100*n.z)/100,n}}var Rp,Fp,Pp;class Dp{Je;sn=!1;me=!1;_texture;qc;constructor(t,e){this._texture=t,this.qc=e}update(t){this.me||this.sn&&(this.qc.jc()||(this._texture.Bc(),t.commandList.unshift(this.Je)))}isDestroyed(){return this.me}show(){0==this.sn&&(this.sn=!0)}hide(){this.sn&&(this.sn=!1)}destroy(){this.me=!0,this.Je.vertexArray.getAttribute(0).vertexBuffer.destroy(),this.Je.vertexArray.cn=[],this.Je.vertexArray.destroy()}}class Np{bo;Lc;Hc;Wc;Vc;Gc;Yc;sn=!0;Kc;Xc=!0;destroyed=!1;constructor(e){e.autoHide=null==e.autoHide?t.AUTOHIDE_MODE.AUTO:e.autoHide,e.autoHideDistance=null==e.autoHideDistance?50:e.autoHideDistance,e.autoHideAngle=null==e.autoHideAngle?15:e.autoHideAngle;const n=e.viewer;this.Kc=new zp(1,1,1),this.bo=e,n.scene,this.Lc=r.Cartesian3.fromDegrees(this.bo.pos[0],this.bo.pos[1],this.bo.pos[2]),this.Wc=r.Transforms.localFrameToFixedFrameGenerator("north","west"),(t=>new Promise(((e,n)=>{!function n(){t.terrainProvider?setTimeout((()=>{e()}),2e3):setTimeout(n,300)}()})))(this.bo.viewer).then((async()=>{this.Yc=(await r.sampleTerrain(this.bo.viewer.terrainProvider,13,[r.Cartographic.fromCartesian(this.Lc)]))[0]?.height||0,this.Qc(),this.Zc()}))}jc(){if(this.bo.autoHide==t.AUTOHIDE_MODE.NO)return!1;if(this.bo.autoHide==t.AUTOHIDE_MODE.ALL||this.bo.autoHide==t.AUTOHIDE_MODE.AUTO&&!this.Xc){const t=this.bo.viewer.camera;if(r.Cartesian3.distance(t.positionWC,this.Lc)>this.bo.autoHideDistance)return!0;if(Math.abs(r.Math.toDegrees(t.heading)-this.bo.heading)>this.bo.autoHideAngle)return!0;if(Math.abs(r.Math.toDegrees(t.pitch)-this.bo.pitch)>this.bo.autoHideAngle)return!0}return!1}getPosition(){return this.Lc}async setPos(t){this.bo.pos=t,this.Lc=r.Cartesian3.fromDegrees(t[0],t[1],t[2]),this.Yc=(await r.sampleTerrain(this.bo.viewer.terrainProvider,13,[r.Cartographic.fromCartesian(this.Lc)]))[0]?.height||0,this.Qc()}setOpacity(t){"number"==typeof t&&(this.bo.opacity=t)}setInternalParams(t,e,n){this.bo.resolution=t,this.bo.fov_vertical=e,this.bo.fov_horizontal=n,this.Qc()}setHeadingAndPitch(t,e){const n=typeof t,i=typeof e;"number"!=n&&"undefined"!=n||"number"!=i&&"undefined"!=i||this.Qc(t,e)&&(void 0!==t&&(this.bo.heading=t),void 0!==e&&(this.bo.pitch=e))}Qc(t,n){const i=this.bo.resolution[0]/this.bo.resolution[1];var s=r.Math.toRadians(this.bo.fov_vertical),o=this.bo.fov_horizontal?r.Math.toRadians(this.bo.fov_vertical):2*Math.atan(Math.tan(s/2)*i);t=r.Math.toRadians(null==t?this.bo.heading:t),n=r.Math.toRadians(null==n?this.bo.pitch:n),this.Jc(t,n,0,0,0);const a=this.Lc,u=new r.Camera(this.bo.viewer.scene);u.position=this.Lc;let h=new r.HeadingPitchRoll(t,n,0),l=r.Transforms.headingPitchRollToFixedFrame(this.Lc,h,r.Ellipsoid.WGS84,this.Wc),c=r.Matrix4.multiplyByPointAsVector(l,r.Cartesian3.UNIT_X,new r.Cartesian3);u.direction=c,u.frustum.aspectRatio=i,u.frustum.fov=i>1?o:s,u.frustum.near=1,u.frustum.far=1e4,u.setView({destination:this.Lc,orientation:{heading:t,pitch:n,roll:0}});var f=u.frustum.projectionMatrix,d=r.Matrix4.multiply(u.viewMatrix,r.Matrix4.fromTranslation(a),new r.Matrix4),p=r.Matrix4.multiply(f,d,new r.Matrix4);this.Gc=p;const v=[],m=16;if(this.bo.mode){const i=this.bo.pos[2]-this.Yc,r=new e.Cartesian3(0,0,0),u=new e.Cartesian3(0,0,-i);this.Kc.Nc(r,u);let h=-o/2,l=s/2,c=(-s/2-l)/m;for(let e=0;e<=m;e+=1){const i=this.tf(t,n,0,h,l+c*e);v.push(i.x-a.x,i.y-a.y,i.z-a.z)}h=o/2;for(let e=0;e<=m;e+=1){const i=this.tf(t,n,0,h,l+c*e);v.push(i.x-a.x,i.y-a.y,i.z-a.z)}}else{let i=-s/2,r=(s/2-i)/m,u=-o/2,h=e.Cartesian3.fromDegrees(this.bo.pos[0],this.bo.pos[1],this.Yc);for(let e=0;e<=m;e+=1){const s=this.ef(t,n,0,u,i+r*e);let o=this.nf(s);o?h=o:(o=this.if(h,s),this.Xc=!1),v.push(o.x-a.x,o.y-a.y,o.z-a.z)}u=o/2;for(let e=0;e<=m;e+=1){const s=this.ef(t,n,0,u,i+r*e);let o=this.nf(s);o?h=o:(o=this.if(h,s),this.Xc=!1),v.push(o.x-a.x,o.y-a.y,o.z-a.z)}}if(this.Vc=v,this.Hc?.Je){const t=this.Hc.Je.vertexArray.getAttribute(0).vertexBuffer;t?.copyFromArrayView(new Float32Array(v))}return!0}if(t,n){const i=new e.Cartesian3(0,0,0),r=Fc(t,this.bo.pos);return this.Kc.Nc(i,r),Dc(this.Kc.Uc(n),this.bo.pos)}nf(t){let n=Dc(t,this.bo.pos);n=e.Cartesian3.subtract(n,this.Lc,new e.Cartesian3);var i=new r.Ray(this.Lc,n),s=new r.Ellipsoid(r.Ellipsoid.WGS84.radii.x+this.Yc,r.Ellipsoid.WGS84.radii.y+this.Yc,r.Ellipsoid.WGS84.radii.z+this.Yc),o=r.IntersectionTests.rayEllipsoid(i,s);return o?r.Ray.getPoint(i,o.start):null}ef(t,n,i,s,o){s=Math.tan(s),o=Math.tan(o);let a=new r.Cartesian3;a=r.Cartesian3.normalize(new e.Cartesian3(s,1,o),a);let u=r.Matrix3.fromRotationX(n),h=r.Matrix3.fromRotationZ(-t),l=r.Matrix3.fromColumnMajorArray([a.x,a.y,a.z,0,0,0,0,0,0]);return l=r.Matrix3.multiply(u,l,new r.Matrix3),l=r.Matrix3.multiply(h,l,new r.Matrix3),r.Matrix3.getColumn(l,0,new e.Cartesian3)}tf(t,e,n,i,r){const s=this.ef(t,e,n,i,r);return Dc(this.Kc.Uc(s),this.bo.pos)}hide(){this.sn=!1,this.Hc?.hide()}show(){this.sn=!0,this.Hc?.show()}destroy(){this.Hc?.destroy(),this.Hc=void 0,this.Gc=void 0,this.destroyed=!0}focus(t,e){(e||this.bo.viewer).camera.setView({destination:this.Lc,orientation:{heading:r.Math.toRadians(this.bo.heading),pitch:r.Math.toRadians(this.bo.pitch),roll:0}}),t&&this.show()}Jc(t,n,i,s,o){let a=new r.HeadingPitchRoll(t,n,i),u=r.Transforms.headingPitchRollToFixedFrame(this.Lc,a,r.Ellipsoid.WGS84,this.Wc);s=Math.tan(s),o=Math.tan(o);let h=new r.Cartesian3;h=r.Cartesian3.normalize(new e.Cartesian3(1,s,o),h);let l=r.Matrix4.multiplyByPointAsVector(u,h,new r.Cartesian3);var c=new r.Ray(this.Lc,l),f=this.Yc,d=new r.Ellipsoid(r.Ellipsoid.WGS84.radii.x+f,r.Ellipsoid.WGS84.radii.y+f,r.Ellipsoid.WGS84.radii.z+f),p=r.IntersectionTests.rayEllipsoid(c,d);return p?r.Ray.getPoint(c,p.start):null}Zc(){var t=document.createElement("video");t.style.cssText="position:fixed;top:0;right:0",t.width=400,t.muted=!0,t.autoplay=!0,t.loop=!0,t.style.display="none",document.body.appendChild(t),t.src=this.bo.url,t.crossOrigin="anonymous",t.load(),t.play();const e=[];for(let t=0;t<16;t+=1)e.push(t,t+16+1,t+16+2),e.push(t,t+16+2,t+1);var n=new Uint16Array(e);t.addEventListener("loadeddata",(()=>{const e=this.bo.viewer.scene.context,i=r.FeatureDetection.supportsWebgl2&&r.FeatureDetection.supportsWebgl2(this.bo.viewer.scene),s=r.ShaderProgram.fromCache({context:e,vertexShaderSource:i?"#version 300 es\nprecision highp int;precision highp float;in vec3 position;out vec3 pos;uniform vec3 u_delta;uniform mat4 u_vp2;void main(){gl_Position=u_vp2*vec4(position,1.0f);pos=position;}":"#version 300 es\nprecision highp int;precision highp float;in vec3 position;in vec2 coord;out vec2 texCoord;void main(){gl_Position=czm_modelViewProjection*vec4(position,1.0f);texCoord=coord;}",fragmentShaderSource:i?"#version 300 es\nprecision highp float;uniform highp sampler2D u_video;uniform mat4 u_vp;uniform float u_opacity;in vec3 pos;void main(){vec4 proj=(u_vp*vec4(pos,1.0f));vec2 uv=proj.xy/proj.w+vec2(1,1);vec4 c=texture(u_video,uv/2.0f);c.a=u_opacity;out_FragColor=c;}":"#version 300 es\nprecision highp float;in vec2 texCoord;uniform highp sampler2D u_video;void main(){highp vec4 c=texelFetch(u_video,texCoord,0.0f);out_FragColor=c;}",attributeLocations:{position:0}}),o={enabled:!0,equationRgb:r.BlendEquation.ADD,equationAlpha:r.BlendEquation.ADD,functionSourceRgb:r.BlendFunction.SOURCE_ALPHA,functionDestinationRgb:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA,functionSourceAlpha:r.BlendFunction.ONE,functionDestinationAlpha:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA},a=r.RenderState.fromCache({depthTest:{enabled:!1},blending:o,depthMask:!0,colorMask:{red:!0,green:!0,blue:!0,alpha:!0}}),u=(()=>{const n=new r.Texture({name:"camera",context:e,source:t,flipY:!0,sampler:new r.Sampler({minificationFilter:r.TextureMinificationFilter.NEAREST,magnificationFilter:r.TextureMagnificationFilter.LINEAR})});return n.Bc=()=>{n.copyFrom({source:t})},n})();this.Hc=new Dp(u,this),this.sn||this.Hc.hide();const h={u_video:()=>u,u_vp:()=>this.Gc,u_vp2:()=>{let t=this.bo.viewer.camera.frustum.projectionMatrix;var e=r.Matrix4.multiply(this.bo.viewer.camera.viewMatrix,r.Matrix4.fromTranslation(this.Lc),new r.Matrix4);return r.Matrix4.multiply(t,e,new r.Matrix4)},u_delta:()=>this.Lc,u_opacity:()=>void 0!==this.bo.opacity?this.bo.opacity:1},l=new r.VertexArray({name:"camera",context:e,attributes:[{index:0,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:new Float32Array(this.Vc),context:e}),componentsPerAttribute:3,componentDatatype:r.ComponentDatatype.FLOAT}],indexBuffer:r.Buffer.createIndexBuffer({context:e,typedArray:n,usage:r.BufferUsage.STATIC_DRAW,indexDatatype:r.IndexDatatype.UNSIGNED_SHORT})}),c=new r.DrawCommand({vertexArray:l,shaderProgram:s,uniformMap:h,renderState:a,pass:r.Pass.OPAQUE,count:96});this.Hc.Je=c,this.bo.viewer.scene.primitives.add(this.Hc),this.sn&&this.Hc.show()}))}}t.AUTOHIDE_MODE=void 0,(Rp=t.AUTOHIDE_MODE||(t.AUTOHIDE_MODE={}))[Rp.NO=0]="NO",Rp[Rp.ALL=1]="ALL",Rp[Rp.AUTO=2]="AUTO";class Up extends r.Event{rf="https://et-api.amap.com";bo={viewer:void 0,adCodes:[],areas:[],clientKey:"",clientSecret:"",time:(new Date).getTime(),style:{slightColor:"#ffff00",severeColor:"#ff0000",slightWidth:5,severeWidth:5}};sf={};af=[];uf=[];hf;lf;constructor(t){super(),this.bo.viewer=t.viewer||this.bo.viewer,this.bo.time=t.time||this.bo.time,this.bo.adCodes=t.adCodes||this.bo.adCodes,this.bo.areas=t.areas||this.bo.areas,this.bo.clientKey=t.clientKey||this.bo.clientKey,this.bo.clientSecret=t.clientSecret||this.bo.clientSecret,this.bo.style=Object.assign(this.bo.style,t.style),this.bo.viewer&&this.cf()}getLines(){return{severe:this.hf,slight:this.lf}}destroy(){this.hf?.destroy(),this.lf?.destroy(),this.af=[],this.uf=[],this.sf=[]}show(){this.hf&&(this.hf.show=!0),this.lf&&(this.lf.show=!0)}hide(){this.hf&&(this.hf.show=!1),this.lf&&(this.lf.show=!1)}update(){this.cf()}async cf(){this.sf=await this.ff(),0!==this.sf.length&&(this.df(),this.pf())}vf(){if(!this.bo.viewer)return;const t=this.bo.viewer;t.scene.preRender.addEventListener((()=>{var e=new r.EllipsoidGeodesic;let n=t.scene,i=n.canvas.clientWidth,s=n.canvas.clientHeight,o=n.camera.getPickRay(new r.Cartesian2(0,s/2)),a=n.camera.getPickRay(new r.Cartesian2(i,s/2));if(o&&a){let t=n.globe,i=t.pick(o,n),r=t.pick(a,n);if(!i)return;if(!r)return;let s=t.ellipsoid.cartesianToCartographic(i),u=t.ellipsoid.cartesianToCartographic(r);e.setEndPoints(s,u),e.surfaceDistance,this.hf}}))}pf(){this.bo.viewer&&(0!==this.af.length&&(this.hf=this.mf(this.af,this.bo.style.severeColor,this.bo.style.severeWidth),this.bo.viewer.scene.primitives.add(this.hf)),0!==this.uf.length&&(this.lf=this.mf(this.uf,this.bo.style.slightColor,this.bo.style.slightWidth),this.bo.viewer.scene.primitives.add(this.lf)),this.raiseEvent("loaded"))}mf(t,e,n){const i=[];return t.forEach((t=>{const s=wp({type:"LineString",coordinates:t.lngLats},n/2,{units:"meters"}),o=s?.geometry.coordinates;o&&i.push(new r.GeometryInstance({geometry:new r.PolygonGeometry({polygonHierarchy:new r.PolygonHierarchy(r.Cartesian3.fromDegreesArray(o.flat(3)))}),attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(r.Color.fromCssColorString(e))}}))})),new r.GroundPrimitive({geometryInstances:i,asynchronous:!1})}yf(t,e,n){const i=[];t.forEach((t=>{const e=r.Cartesian3.fromDegreesArray(t.lngLats.flat()),s=new r.GroundPolylineGeometry({positions:e,width:n});s&&i.push(new r.GeometryInstance({geometry:s}))}));const s=new r.PolylineMaterialAppearance({translucent:!1});return s.material=new r.Material({fabric:{type:"Color",uniforms:{color:r.Color.fromCssColorString(e)}}}),new r.GroundPolylinePrimitive({geometryInstances:i,appearance:s,asynchronous:!1})}df(){this.sf.forEach((t=>{t.linkList.forEach((t=>{const e=t.lngLats.split(";").map((t=>{const e=t.split(",");return[+e[0],+e[1]]}));4===t.state?this.af.push({roadName:t.roadName,roadType:t.roadType,lngLats:e}):this.uf.push({roadName:t.roadName,roadType:t.roadType,lngLats:e})}))}))}async ff(){const t=Math.round((new Date).getTime()/1e3),e=`${this.bo.adCodes.join("")}${this.bo.clientKey}${t}`;let n=await async function(t,e){const n=new TextEncoder,i=n.encode(e),r=n.encode(t),s=await crypto.subtle.importKey("raw",i,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),o=await crypto.subtle.sign("HMAC",s,r);return Array.from(new Uint8Array(o)).map((t=>t.toString(16).padStart(2,"0"))).join("")}(e,this.bo.clientSecret);const i=await fetch(`${this.rf}/congestion/history?clientKey=${this.bo.clientKey}×tamp=${t}&digest=${n.toString()}&adCodes=${this.bo.adCodes.join()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({adCodes:this.bo.adCodes,areas:this.bo.areas,startTime:this.bo.time/1e3,endTime:this.bo.time/1e3+3600,pageSize:9999,queryList:[{duration:"4",roadType:"0",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"1",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"2",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"3",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"4",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"5",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"6",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"7",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"8",distance:"200",congestRate:"0",congestType:"0"},{duration:"4",roadType:"9",distance:"200",congestRate:"0",congestType:"0"}]})}),r=await i.json();if(0!==r.code)throw new Error("路况数据获取失败:",r.message);return r.data.list}}class qp extends r.Entity{bo;wf;gf=0;bf=0;_f;xf;kf;constructor(t){t.eyeOffset=t.eyeOffset||[0,0,0],t.controlOptions=t.controlOptions||{speed:10,steeringSpeed:15};const e=r.Cartesian3.fromDegrees(t.position[0],t.position[1],t.position[2]),n=new r.HeadingPitchRoll(r.Math.toRadians(t.heading-90),0,0);super({position:e,orientation:r.Transforms.headingPitchRollQuaternion(e,n),model:{uri:t.uri,scale:t.scale||1,runAnimations:t.runAnimations}}),this.bo=t}$f(){const t=r.Cartesian3.fromDegrees(-123.0744619,44.0503706,5e3),e=new r.HeadingPitchRoll,n=r.Transforms.localFrameToFixedFrameGenerator("north","west");r.Transforms.headingPitchRollToFixedFrame(t,e,r.Ellipsoid.WGS84,n)}static Sf=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","KeyA","KeyS","KeyD","KeyW"];static Mf;static Ef=[];static Cf=0;static Af(t){const e=-1!==qp.Sf.indexOf(t.code);e&&-1==qp.Ef.indexOf(t.code)&&qp.Ef.push(t.code),e&&!qp.Cf&&(qp.Cf=requestAnimationFrame(qp.Of),qp.Mf&&(qp.Mf.xf=(new Date).getTime()))}static If(t){const e=-1!==qp.Sf.indexOf(t.code),n=qp.Ef.indexOf(t.code);e&&-1!==n&&qp.Ef.splice(n,1)}static Of(){qp.Cf=0;const t=qp.Mf;if(t)if(qp.Ef.length){const e=(new Date).getTime();if(t.xf&&e-t.xf){const n=(e-t.xf)/1e3/3600*1e3*t.bo.controlOptions.speed,i=(e-t.xf)/1e3*t.bo.controlOptions.steeringSpeed;if(t.gf<=1){t.model.runAnimations=!0;let e=0;switch(qp.Ef.sort().join(",")){case"ArrowUp":case"KeyW":e=0;break;case"ArrowDown":case"KeyS":e=180;break;case"ArrowLeft":case"KeyA":e=-90;break;case"ArrowRight":case"KeyD":e=90;break;case"ArrowDown,ArrowLeft":case"KeyA,KeyS":e=-135;break;case"ArrowDown,ArrowRight":case"KeyD,KeyS":e=135;break;case"ArrowLeft,ArrowUp":case"KeyA,KeyW":e=-45;break;case"ArrowRight,ArrowUp":case"KeyD,KeyW":e=45}const i=180*t.bo.viewer.camera.heading/Math.PI+e,s=new r.HeadingPitchRoll(r.Math.toRadians(i-90),0,0);t.bo.heading=i;const o=Math.sin(i*Math.PI/180)*n,a=Math.cos(i*Math.PI/180)*n,u=Dc(new r.Cartesian3(o,a,0),t.bo.position),h=r.Cartographic.fromCartesian(u),l=r.Math.toDegrees(h.longitude),c=r.Math.toDegrees(h.latitude);t.bo.position=[l,c,t.bo.position[2]];const f=r.Cartesian3.fromDegrees(l,c,t.bo.position[2]);t.position=f;const d=r.Transforms.headingPitchRollQuaternion(f,s);t.orientation=d}else{t.model.runAnimations=!1;let e=0,s=0;switch(qp.Ef.sort().join(",")){case"ArrowUp":case"KeyW":s=1;break;case"ArrowDown":case"KeyS":s=-1;break;case"ArrowLeft":case"KeyA":e=-1;break;case"ArrowRight":case"KeyD":e=1;break;case"ArrowDown,ArrowLeft":case"KeyA,KeyS":e=1,s=-1;break;case"ArrowDown,ArrowRight":case"KeyD,KeyS":e=-1,s=-1;break;case"ArrowLeft,ArrowUp":case"KeyA,KeyW":e=-1,s=1;break;case"ArrowRight,ArrowUp":case"KeyD,KeyW":e=1,s=1}const o=180*t.bo.viewer.camera.heading/Math.PI+i*e,a=new r.HeadingPitchRoll(r.Math.toRadians(o-90),0,0);t.bo.heading=o;const u=Math.sin(o*Math.PI/180)*n*s,h=Math.cos(o*Math.PI/180)*n*s,l=Dc(new r.Cartesian3(u,h,0),t.bo.position),c=r.Cartographic.fromCartesian(l),f=r.Math.toDegrees(c.longitude),d=r.Math.toDegrees(c.latitude);t.bo.position=[f,d,t.bo.position[2]];const p=r.Cartesian3.fromDegrees(f,d,t.bo.position[2]);t.position=p;const v=r.Transforms.headingPitchRollQuaternion(p,a);t.orientation=v;const m=Dc(new r.Cartesian3(t.bo.eyeOffset[0],t.bo.eyeOffset[1],t.bo.eyeOffset[2]),t.bo.position);t.bo.viewer.camera.setView({destination:m,orientation:{heading:r.Math.toRadians(t.bo.heading),pitch:t.bo.viewer.camera.pitch}})}}qp.Cf=requestAnimationFrame(qp.Of),t.xf=e}else t.model.runAnimations=!1,t.xf=void 0}Tf(){this.getPrimitive().Rf.zf.forEach((t=>{t.runtimeChannels.forEach((t=>{t.animate(0)}))}))}getPrimitive(){if(this.wf)return this.wf;{const t=this.bo.viewer.scene.primitives.length;for(let e=0;e<t;e+=1){const t=this.bo.viewer.scene.primitives.get(e);if(t.id==this)return this.wf=t,t}}}startControlModel(t=0){this.bf||qp.Mf!==this&&(qp.Mf&&qp.Mf.stopControlModel(),qp.Mf=this,document.addEventListener("keydown",qp.Af),document.addEventListener("keyup",qp.If),qp.Cf=requestAnimationFrame(qp.Of),this.switchTrackingMode(t))}setControlOptions(t){this.bo.controlOptions=t}switchTrackingMode(t){qp.Mf==this&&(this.bo.viewer.trackedEntity=void 0,this.gf=t,0==t?(this.viewFrom=void 0,this.show=!0):1==t?(this.show=!0,this.bo.viewFrom?this.viewFrom=new e.Cartesian3(this.bo.viewFrom[0],this.bo.viewFrom[1],this.bo.viewFrom[2]):this.viewFrom=void 0,this.bo.viewer.trackedEntity=this):(this.bo.viewer.trackedEntity=this,this.show=!1,requestAnimationFrame((()=>{const t=Dc(new r.Cartesian3(this.bo.eyeOffset[0],this.bo.eyeOffset[1],this.bo.eyeOffset[2]),this.bo.position);this.bo.viewer.camera.setView({destination:t,orientation:{heading:r.Math.toRadians(this.bo.heading),pitch:0}})}))))}stopControlModel(){document.removeEventListener("keydown",qp.Af),document.removeEventListener("keyup",qp.If),qp.Cf&&(cancelAnimationFrame(qp.Cf),qp.Cf=0),qp.Mf=void 0,qp.Ef=[],this.gf=0,this.xf=void 0}moveAlong(t,n,i,s,o,a){if(qp.Mf!==this&&this.stopControlModel(),s=s||t.Ff(),this.bf)return;n&&(this.bo.viewFrom&&(this.viewFrom=new e.Cartesian3(this.bo.viewFrom[0],this.bo.viewFrom[1],this.bo.viewFrom[2])),this.bo.viewer.trackedEntity=this);const u=this;u.position=t.Pf.getValue(s);let h=(new Date).getTime(),l=-1;this._f=s;const c=()=>{let n=(new Date).getTime()-h;const d=r.JulianDate.addSeconds(s,n/1e3,new r.JulianDate);this._f=d;const p=t.Pf.getValue(d);u.position=p;const v=t.Df.getValue(d);if(u.orientation=v,p&&this.kf){const t=(this.kf?.steeringSpeed||30)*Math.PI/180,n=r.Matrix3.fromQuaternion(v),i=r.Matrix4.fromRotation(n),s=new e.Cartesian3(-this.kf.range*Math.cos(this.kf.pitch*Math.PI/180),0,-this.kf.range*Math.sin(this.kf.pitch*Math.PI/180));var m=new r.Cartesian4(s.x,s.y,s.z,1),y=r.Matrix4.multiplyByVector(i,m,new r.Cartesian4),w=new r.Cartesian3(y.x,y.y,y.z);const o=e.Cartesian3.add(p,w,new e.Cartesian3);let a=this.bo.viewer.camera.pitch,u=this.bo.viewer.camera.heading;const h=Nc(o),l=Nc(p),c=Math.atan2(l.lng-h.lng,l.lat-h.lat),d=this.kf.pitch*Math.PI/180;let g=u,b=a;const _=(new Date).getTime(),x=(_-f)/1e3*t;f=_,Math.abs(d-a)<x?b=d:d>a?b+=x:b-=x;const k=Uc(u,c);Math.abs(k)<x?g=c:k>0?g+=x:g-=x,this.bo.viewer.camera.lookAt(p,new r.HeadingPitchRange(g,b,this.kf.range))}if(n>=t.Nf)i?(h=(new Date).getTime(),this.bf=requestAnimationFrame(c)):(this._f=void 0,this.bf=0),l!==t.Uf.length-1&&a?.call(u,{index:t.Uf.length-1}),o?.call(u,{index:t.Uf.length-1});else{if(a){const e=t.qf(d);-1!==e&&e!==l&&(l=e,a?.call(u,{index:e}))}this.bf=requestAnimationFrame(c)}};let f=(new Date).getTime();this.bf=requestAnimationFrame(c)}follow(t){this.kf=t?{pitch:-90,range:100,steeringSpeed:30,...t}:void 0}stopFollow(){this.kf=void 0}stopMoveAlong(){if(this.bf)return cancelAnimationFrame(this.bf),this.bf=0,this.bo.viewer.trackedEntity==this&&(this.bo.viewer.trackedEntity=void 0),this._f}}class jp{Pf;Uf=[];Nf;jf;Df;constructor(t){this.jf=t;const e=new r.SampledPositionProperty;this.Nf=t[t.length-1].time.getTime()-t[0].time.getTime();for(let n=0,i=t.length;n<i;n+=1){const i=t[n],s=r.JulianDate.fromDate(i.time);this.Uf.push(s);const o=r.Cartesian3.fromDegrees(i.position[0],i.position[1],i.position[2]);e.addSample(s,o)}this.Df=new r.VelocityOrientationProperty(e),this.Pf=e}Ff(){return this.Uf[0]}qf(t){for(let e=0;e<this.Uf.length;e+=1)if(r.JulianDate.equalsEpsilon(this.Uf[e],t,.1))return e;return-1}Bf(t){return this.jf[t]}}function Bp(t,e={}){return function(t){var n=0;return function(t){!function(t,e){qf(t,(function(t,n,i,r,s){var o,a=null===t?null:t.type;switch(a){case null:case"Point":case"LineString":case"Polygon":return!1!==e(hf(t,i,{bbox:r,id:s}),n,0)&&void 0}switch(a){case"MultiPoint":o="Point";break;case"MultiLineString":o="LineString";break;case"MultiPolygon":o="Polygon"}for(var u=0;u<t.coordinates.length;u++){var h=t.coordinates[u];if(!1===e(hf({type:o,coordinates:h},i),n,u))return!1}}))}(t,(function(t,i,r){if(t.geometry){var s=t.geometry.type;if("Point"!==s&&"MultiPoint"!==s){var o,a=0,u=0,h=0;return!1!==Nf(t,(function(r,s,l,c,f){if(void 0===o||i>a||c>u||f>h)return o=r,a=i,u=c,h=f,void 0;var d=function(t,e,n={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return hf({type:"LineString",coordinates:t},e,n)}([o,r],t.properties);if(!1===function(t){n=((t,n)=>{const i=n.geometry.coordinates;return t+wf(i[0],i[1],e)})(n,t)}(d))return!1;o=r}))&&void 0}}}))}(t),n}(t)}class Lp{Hn;Lf;Hf;Wf;Vf=0;Jn={};Gf=this.Yf.bind(this);Kf=this.Xf.bind(this);Qf=this.Zf.bind(this);Jf="";td=this.ed.bind(this);nd=this.rd.bind(this);sd=this.od.bind(this);ad=!1;constructor(t){this.Hn=t.viewer,this.Lf=t.line,this.Hf=t.moveSpeed,this.Wf=0,this.cf()}lock(){var t=this.Hn.scene.screenSpaceCameraController;this.Jn={enableTranslate:t.enableTranslate,enableZoom:t.enableZoom,enableRotate:t.enableRotate,enableTilt:t.enableTilt,enableLook:t.enableLook,inertiaSpin:t.inertiaSpin,inertiaTranslate:t.inertiaTranslate,inertiaZoom:t.inertiaZoom},t.enableTranslate=!1,t.enableRotate=!1,t.enableZoom=!1,t.enableLook=!1,t.enableTilt=!1,t.inertiaSpin=0,t.inertiaTranslate=0,t.inertiaZoom=0,this.ud()}unlock(){var t=this.Hn.scene.screenSpaceCameraController;t.enableTranslate=this.Jn.enableTranslate,t.enableZoom=this.Jn.enableZoom,t.enableRotate=this.Jn.enableRotate,t.enableTilt=this.Jn.enableTilt,t.enableLook=this.Jn.enableLook,t.inertiaSpin=this.Jn.inertiaSpin,t.inertiaTranslate=this.Jn.inertiaTranslate,t.inertiaZoom=this.Jn.inertiaZoom}destroy(){this.unlock(),document.removeEventListener("keydown",this.Gf),document.removeEventListener("keyup",this.Kf);let t=new r.ScreenSpaceEventHandler(this.Hn.scene.canvas);t.removeInputAction(r.ScreenSpaceEventType.MIDDLE_DOWN),t.removeInputAction(r.ScreenSpaceEventType.MOUSE_MOVE),t.removeInputAction(r.ScreenSpaceEventType.MIDDLE_UP)}move(t){"forward"===t?(this.Wf+=this.Hf,this.Wf=Math.min(this.Wf,this.Vf)):(this.Wf-=this.Hf,this.Wf=Math.max(this.Wf,0)),this.hd()}cf(){this.Vf=1e3*Bp({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:this.Lf}},{units:"kilometers"}),document.addEventListener("keydown",this.Gf),document.addEventListener("keyup",this.Kf),this.lock(),this.Zf()}ud(){let t=new r.ScreenSpaceEventHandler(this.Hn.scene.canvas);t.setInputAction(this.td,r.ScreenSpaceEventType.MIDDLE_DOWN),t.setInputAction(this.nd,r.ScreenSpaceEventType.MOUSE_MOVE),t.setInputAction(this.sd,r.ScreenSpaceEventType.MIDDLE_UP)}ed(t){this.ad=!0}rd(t){if(!this.ad)return;const e=t.endPosition.x-t.startPosition.x,n=t.endPosition.y-t.startPosition.y;this.Hn.camera.setView({destination:this.Hn.camera.position,orientation:{heading:this.Hn.camera.heading-e/1e3,pitch:this.Hn.camera.pitch+n/1e3,roll:0}})}od(t){this.ad=!1}hd(){const t=this.ld(this.Lf,this.Wf);if(t){const e=r.Cartesian3.fromDegrees(t[0],t[1],t[2]);this.Hn.camera.setView({destination:e,orientation:{heading:this.Hn.camera.heading,pitch:this.Hn.camera.pitch,roll:0}})}}Yf(t){"KeyW"===t.code?this.Jf="W":"KeyS"===t.code&&(this.Jf="S")}Xf(t){"KeyW"!==t.code&&"KeyS"!==t.code||(this.Jf="")}Zf(){requestAnimationFrame(this.Qf),this.Jf&&("W"===this.Jf&&(this.Wf+=this.Hf,this.Wf=Math.min(this.Wf,this.Vf)),"S"===this.Jf&&(this.Wf-=this.Hf,this.Wf=Math.max(this.Wf,0)),this.hd())}ld(t,e){let n=0;for(let i=1;i<t.length;i++){const r=t[i-1],s=t[i],o=1e3*wf({type:"Point",coordinates:r},{type:"Point",coordinates:s},{units:"kilometers"});if(n<=e&&n+o>e){const t=(e-n)/o;return[r[0]+(s[0]-r[0])*t,r[1]+(s[1]-r[1])*t,r[2]+(s[2]-r[2])*t]}n+=o}}}class Hp{Hn;bo={viewer:void 0,moveRate:1,rotateRate:1};fd=!1;dd={moveForward:!1,moveBackward:!1,moveLeft:!1,moveRight:!1,moveUp:!1,moveDown:!1,lookUp:!1,lookDown:!1,lookLeft:!1,lookRight:!1,twistLeft:!1,twistRight:!1,zoomIn:!1,zoomOut:!1};pd=this.Af.bind(this);vd=this.If.bind(this);md=this.yd.bind(this);constructor(t){t.viewer&&(this.Hn=t.viewer,this.bo=Object.assign(this.bo,t),this.wd())}destroy(){const t=this.Hn;t&&(t.clock.onTick.removeEventListener(this.md),document.removeEventListener("keydown",this.pd,!1),document.removeEventListener("keyup",this.vd,!1),t.scene.screenSpaceCameraController.enableRotate=!0,t.scene.screenSpaceCameraController.enableTranslate=!0,t.scene.screenSpaceCameraController.enableZoom=!0,t.scene.screenSpaceCameraController.enableTilt=!0,t.scene.screenSpaceCameraController.enableLook=!0)}wd(){this.Hn&&(document.addEventListener("keydown",this.pd,!1),document.addEventListener("keyup",this.vd,!1),this.Hn.clock.onTick.addEventListener(this.md),this.gd())}bd(t){switch(t){case 87:return"moveForward";case 83:return"moveBackward";case 68:return"moveRight";case 65:return"moveLeft";case 81:return"moveUp";case 69:return"moveDown";case 38:return"lookUp";case 40:return"lookDown";case 37:return"lookLeft";case 39:return"lookRight";case 96:return"twistLeft";case 110:return"twistRight";case 107:return"zoomIn";case 109:return"zoomOut";default:return}}Af(t){let e=this.bd(t.keyCode);void 0!==e&&(this.dd[e]=!0)}If(t){let e=this.bd(t.keyCode);void 0!==e&&(this.dd[e]=!1)}yd(){if(!this.Hn)return;let t=this.Hn.camera,e=this.Hn.scene.globe.ellipsoid.cartesianToCartographic(t.position).height,n=e/40*this.bo.moveRate;const i=this.dd;i.moveForward&&t.moveForward(n),i.moveBackward&&t.moveBackward(n),i.moveLeft&&t.moveLeft(n),i.moveRight&&t.moveRight(n),i.moveUp&&t.moveUp(n),i.moveDown&&t.moveDown(n),i.lookUp&&t.lookUp(),i.lookDown&&t.lookDown(),i.lookLeft&&t.lookLeft(),i.lookRight&&t.lookRight(),i.twistLeft&&t.twistLeft(),i.twistRight&&t.twistRight(),i.zoomIn&&t.zoomIn(e/2),i.zoomOut&&t.zoomOut(e/2)}gd(){if(!this.Hn)return;const t=this.Hn;t.scene.screenSpaceCameraController.enableRotate=!1,t.scene.screenSpaceCameraController.enableTranslate=!1,t.scene.screenSpaceCameraController.enableZoom=!1,t.scene.screenSpaceCameraController.enableTilt=!1,t.scene.screenSpaceCameraController.enableLook=!1,t.screenSpaceEventHandler.setInputAction(this._d,r.ScreenSpaceEventType.LEFT_DOWN),t.screenSpaceEventHandler.setInputAction(this.xd,r.ScreenSpaceEventType.MOUSE_MOVE),t.screenSpaceEventHandler.setInputAction(this.kd,r.ScreenSpaceEventType.LEFT_UP)}_d=()=>{this.fd=!0};kd=()=>{this.fd=!1};xd=t=>{if(this.Hn&&this.fd){const{startPosition:e,endPosition:n}=t,i=(n.x-e.x)/100*this.bo.rotateRate,r=-(n.y-e.y)/100*this.bo.rotateRate;this.Hn.camera.setView({orientation:{heading:this.Hn.camera.heading+i,pitch:this.Hn.camera.pitch+r,roll:this.Hn.camera.roll}})}}}class Wp{static runningAnimation;bo;status=t.CameraAnimationStatus.stop;$d;Sd=0;Md;Ed=-1;constructor(t){this.bo=t}start(e){Wp.runningAnimation!==this&&Wp.runningAnimation?.stop();const n=this.bo.path;if(e=e||n.Ff(),this.status==t.CameraAnimationStatus.running)return;const i=this.bo.viewer,r=n.Pf.getValue(e),s=n.Cd.getValue(e);i.camera.setView({destination:r,orientation:{heading:s.x,pitch:s.y,roll:s.z}}),this.Md=(new Date).getTime(),this.Ed=0,this.$d=e,this.status=t.CameraAnimationStatus.running,this.Sd=requestAnimationFrame(this.$f),e.equals(n.Ff())&&this.bo.onReachKeyNode&&this.bo.onReachKeyNode?.call(this,{index:0})}$f=()=>{const t=this.bo.path,e=(new Date).getTime();let n=e-this.Md,i=r.JulianDate.addSeconds(this.$d,n/1e3,new r.JulianDate);this.$d=i;const s=this.bo.viewer;if(i>=t.Ad())this.bo.repeat?(this.Md=e,this.$d=t.Ff(),i=this.$d,this.Sd=requestAnimationFrame(this.$f)):(i=t.Ad(),this.$d=void 0,this.Sd=0),this.Ed!==t.Uf.length-1&&this.bo.onReachKeyNode?.call(this,{index:t.Uf.length-1}),this.bo.onEnd?.call(this,{index:t.Uf.length-1});else{if(this.bo.onReachKeyNode){const e=t.qf(i);-1!==e&&e!==this.Ed&&(this.Ed=e,this.bo.onReachKeyNode?.call(this,{index:e}))}this.Md=e,this.Sd=requestAnimationFrame(this.$f)}const o=t.Pf.getValue(i),a=t.Cd.getValue(i);s.camera.setView({destination:o,orientation:{heading:a.x,pitch:a.y,roll:a.z}})};stop(){if(this.status===t.CameraAnimationStatus.running)return this.Sd&&cancelAnimationFrame(this.Sd),this.status=t.CameraAnimationStatus.stop,this.$d}pause(){if(this.status===t.CameraAnimationStatus.running)return this.Sd&&cancelAnimationFrame(this.Sd),this.status=t.CameraAnimationStatus.paused,this.$d}resume(e){this.status==t.CameraAnimationStatus.paused&&(this.status=t.CameraAnimationStatus.running,this.$d=e,this.Md=(new Date).getTime(),this.Sd=requestAnimationFrame(this.$f))}}class Vp{Pf;Cd;Uf=[];jf;constructor(t,e,n){let i;i=t[0].pos?t:t.map((t=>({pos:t}))),e&&n&&this.Od(i,e,n),this.jf=i;const s=new r.SampledPositionProperty,o=new r.SampledProperty(r.Cartesian3);let a;for(let t=0,e=i.length;t<e;t+=1){const e=i[t],n=r.JulianDate.fromDate(e.time);this.Uf.push(n);const u=r.Cartesian3.fromDegrees(e.pos.lng,e.pos.lat,e.pos.height);s.addSample(n,u);let h=r.Math.toRadians(e.pos.heading);const l=2*Math.PI;h=(h%l+l)%l,a&&(h=a+Uc(a,h)),a=h;const c=new r.Cartesian3(a,r.Math.toRadians(e.pos.pitch),r.Math.toRadians(e.pos.roll));o.addSample(n,c)}this.Pf=s,this.Cd=o}Od(t,n,i){let r=(new Date).getTime();t.forEach(((s,o)=>{let a=s;if(o>0){const s=e.Cartesian3.distance(e.Cartesian3.fromDegrees(a.pos.lng,a.pos.lat,a.pos.height),e.Cartesian3.fromDegrees(t[o-1].pos.lng,t[o-1].pos.lat,t[o-1].pos.height)),u=180*Uc(t[o-1].pos.heading,a.pos.heading)/Math.PI;r+=1e3*Math.round(Math.max(s/n,Math.abs(u)/i,Math.abs(a.pos.pitch-t[o-1].pos.pitch)/i))}t[o].time=new Date(r)}))}Ff(){return this.Uf[0]}Ad(){return this.Uf[this.Uf.length-1]}qf(t){for(let e=0;e<this.Uf.length;e+=1)if(r.JulianDate.equalsEpsilon(this.Uf[e],t,.1))return e;return-1}Bf(t){return this.jf[t]}}t.CameraAnimationStatus=void 0,(Fp=t.CameraAnimationStatus||(t.CameraAnimationStatus={}))[Fp.stop=0]="stop",Fp[Fp.running=1]="running",Fp[Fp.paused=2]="paused";class Gp{bo;Hc=new Yp;constructor(t){this.bo=t,this.Id()}Id(){const t=this.bo.viewer.scene.context,e=r.ShaderProgram.fromCache({context:t,vertexShaderSource:"#version 300 es\nprecision highp int;precision highp float;in vec3 position;uniform mat4 u_vp2;void main(){gl_Position=u_vp2*vec4(position,1.0f);}",fragmentShaderSource:"#version 300 es\nprecision highp float;void main(){out_FragColor=vec4(1,0,0,0.3);}",attributeLocations:{position:0}}),n={enabled:!0,equationRgb:r.BlendEquation.ADD,equationAlpha:r.BlendEquation.ADD,functionSourceRgb:r.BlendFunction.SOURCE_ALPHA,functionDestinationRgb:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA,functionSourceAlpha:r.BlendFunction.ONE,functionDestinationAlpha:r.BlendFunction.ONE_MINUS_SOURCE_ALPHA},i=r.RenderState.fromCache({depthTest:{enabled:!0},blending:n,depthMask:!0,colorMask:{red:!1,green:!1,blue:!1,alpha:!1}}),s=r.Cartesian3.fromDegrees(this.bo.enuCenter[0],this.bo.enuCenter[1],this.bo.enuCenter[2]),o={u_vp2:()=>{let t=this.bo.viewer.camera.frustum.projectionMatrix;const e=r.Transforms.eastNorthUpToFixedFrame(s);var n=r.Matrix4.multiply(this.bo.viewer.camera.viewMatrix,e,new r.Matrix4);return r.Matrix4.multiply(t,n,new r.Matrix4)}},a=new r.VertexArray({name:"glbDepth",context:t,attributes:[{index:0,vertexBuffer:r.Buffer.createVertexBuffer({usage:r.BufferUsage.STATIC_DRAW,typedArray:new Float32Array(this.bo.vertices),context:t}),componentsPerAttribute:3,componentDatatype:r.ComponentDatatype.FLOAT}],indexBuffer:r.Buffer.createIndexBuffer({context:t,typedArray:new Uint32Array(this.bo.faces),usage:r.BufferUsage.STATIC_DRAW,indexDatatype:r.IndexDatatype.UNSIGNED_INT})}),u=new r.DrawCommand({vertexArray:a,shaderProgram:e,uniformMap:o,renderState:i,pass:r.Pass.OPAQUE,count:this.bo.faces.length});this.Hc.Je=u,this.bo.viewer.scene.primitives.add(this.Hc)}}class Yp{Je;sn=!0;me=!1;constructor(){}update(t){this.me||this.sn&&t.commandList.push(this.Je)}isDestroyed(){return this.me}show(){0==this.sn&&(this.sn=!0)}hide(){this.sn&&(this.sn=!1)}destroy(){this.me=!0,this.Je.vertexArray.getAttribute(1).vertexBuffer.destroy(),this.Je.vertexArray.cn=[],this.Je.vertexArray.destroy()}}class Kp extends r.Event{bo={viewer:void 0,uri:"",adcode:"110000",bounds:[-90,-180,180,90],startTime:"20240901102940",endTime:"20240908102940",meshUri:"",meshEnuCenter:[120.14099999999999,30.240000000000002,0],meshHeight:0,style:{modelUri:"",modelScale:1}};sf={};Td=[];zd;constructor(t){super(),this.bo.viewer=t.viewer||this.bo.viewer,this.bo.meshEnuCenter=t.meshEnuCenter||this.bo.meshEnuCenter,this.bo.uri=t.uri||this.bo.uri,this.bo.meshUri=t.meshUri||this.bo.meshUri,this.bo.startTime=t.startTime||this.bo.startTime,this.bo.adcode=t.adcode||this.bo.adcode,this.bo.bounds=t.bounds||this.bo.bounds,this.bo.meshHeight=t.meshHeight||this.bo.meshHeight,this.bo.style=Object.assign(this.bo.style,t.style),this.bo.viewer&&this.cf()}destroy(){this.sf=[],this.Td.forEach((t=>{this.bo.viewer?.entities.remove(t)}))}show(){this.Td.forEach((t=>{t.show=!0}))}hide(){this.Td.forEach((t=>{t.show=!1}))}update(){this.cf()}async cf(){this.sf=await this.ff(),this.Rd(),this.Fd()}Rd(){const t=this.bo.viewer;if(!t)return;const e=["./car0.glb","./car1.glb","./car4.glb","./car5.glb","./car6.glb","./car13.glb"];for(let n=0;n<this.sf.length;n++){const i=this.sf[n],s=r.Cartesian3.fromDegrees(i[0].point[0],i[0].point[1],this.bo.meshHeight),o=t.entities.add({name:`Model ${n}`,position:s,orientation:r.Transforms.headingPitchRollQuaternion(s,new r.HeadingPitchRoll(0,0,0)),model:{uri:this.bo.style.modelUri||e[0],scale:this.bo.style.modelScale||1,heightReference:r.HeightReference.RELATIVE_TO_TERRAIN}});this.Td.push(o)}}Fd(){const t=this.bo.viewer;if(!t)return;let e=1/0,n=0;for(let t=0;t<this.sf.length;t++){const i=this.sf[t];e=Math.min(e,i[0].time),n=Math.max(n,i[i.length-1].time)}const i=r.JulianDate.now();for(let t=0;t<this.sf.length;t++){const e=this.sf[t],n=new r.SampledPositionProperty;for(let t=1;t<e.length;t++){const s=e[t].point,o=e[t].time,a=r.JulianDate.addSeconds(i,o,new r.JulianDate),u=r.Cartesian3.fromDegrees(s[0],s[1],this.bo.meshHeight);n.addSample(a,u)}const s=this.Td[t];s.position=n;const o=new r.VelocityOrientationProperty(n,r.Ellipsoid.WGS84);s.orientation=o}const s=t.clock;s.shouldAnimate=!0,s.startTime=r.JulianDate.addSeconds(i,e,new r.JulianDate),s.currentTime=s.startTime,s.stopTime=r.JulianDate.addSeconds(i,n,new r.JulianDate),s.clockRange=r.ClockRange.LOOP_STOP,s.multiplier=1}async ff(){const t=await fetch(this.bo.uri,{method:"GET"}),e=await t.json();if(0!==e.code)throw new Error("浮动车数据获取失败:"+e.message);return e.data.trackPoint}async Pd(){if(!this.bo.viewer)return;const t=await this.Dd();this.zd=new Gp({viewer:this.bo.viewer,enuCenter:this.bo.meshEnuCenter,vertices:t.vertices,faces:t.faces})}async Dd(){const t=await fetch(this.bo.meshUri,{method:"GET"}),e=await t.json();if(!e.faces||!e.vertices)throw new Error("Mesh 模型数据获取失败:"+e.message);return e}}!function(t){t[t.distance=0]="distance",t[t.groundArea=1]="groundArea"}(Pp||(Pp={}));class Xp{Nd=Pp.distance;Ud;qd;jd=[];Os="closed";Bd=[];Ld;Xn=[];Hn;bo;me=!1;constructor(t,n){this.bo={unit:"米",precision:.1,...n},this.Hn=t;const i=e=>{let n;return this.Nd===Pp.distance?n=t.entities.add({polyline:{positions:e,width:5,material:new r.PolylineOutlineMaterialProperty({color:new r.Color(0,98/255,254/255,1),outlineColor:r.Color.WHITE,outlineWidth:2}),depthFailMaterial:new r.PolylineOutlineMaterialProperty({color:new r.Color(0,98/255,254/255,1),outlineColor:r.Color.WHITE,outlineWidth:2})}}):this.Nd===Pp.groundArea&&(n=t.entities.add({polygon:{hierarchy:e,material:new r.ColorMaterialProperty(new r.Color(0,98/255,254/255,.3))}})),t.scene.requestRender(),n};this.Ud=new e.ScreenSpaceEventHandler(t.canvas);const s=e=>{let n=t.scene.pickPosition(e);if(!n){const i=t.scene.pick(e,1,1);!i||i.id!=this.Ld&&-1===this.Xn.indexOf(i.id)||(n=i.id.position.getValue(r.JulianDate.now()))}return n};this.Ud.setInputAction((t=>{if("open"!==this.Os)return;const e=s(t.position);if(r.defined(e))if(this.qd){this.Bd.pop();const t=this.Bd[this.Bd.length-1];if(this.Bd.push(e,e),this.Nd==Pp.distance){let n=r.Cartesian3.distance(e,t);const i=this.bo.unit;if("分米"==i&&(n*=10),"厘米"==i&&(n*=100),"毫米"==i&&(n*=1e3),"dm"==i&&(n*=10),"cm"==i&&(n*=100),"mm"==i&&(n*=1e3),this.bo.precision<=1){const t=Math.round(1/this.bo.precision);n=Math.round(n*t)/t}else n=Math.round(n/this.bo.precision)*this.bo.precision;const s=new r.Cartesian3;r.Cartesian3.add(t,e,s),r.Cartesian3.divideByScalar(s,2,s),this.Xn.push(this.Hd(s,n+" "+i))}this.Xn.push(this.Wd(e))}else{this.Ld=this.Wd(e);const t=[e,e],n=new r.CallbackProperty((()=>{if(this.qd)return this.Nd===Pp.groundArea?new r.PolygonHierarchy(this.Bd):this.Bd}),!1);this.qd=i(n),this.Bd=t,this.Xn.push(this.Wd(e))}}),r.ScreenSpaceEventType.LEFT_CLICK),this.Ud.setInputAction((t=>{if("open"===this.Os)if(r.defined(this.Ld)){const e=s(t.endPosition);r.defined(e)&&(this.Ld.position.setValue(e),this.Bd.pop(),this.Bd.push(e),this.Hn.scene.requestRender())}else{const e=s(t.endPosition);if(!r.defined(e))return;this.Ld=this.Wd(e)}}),r.ScreenSpaceEventType.MOUSE_MOVE),this.Ud.setInputAction((t=>{this.Vd()}),r.ScreenSpaceEventType.RIGHT_CLICK)}destroy(){this.stop(!0),this.Ud.destroy(),this.me=!0}Gd(){if(this.qd)if(this.Nd===Pp.distance)this.qd.polyline.positions=this.Bd,this.Bd.length<2?(this.Hn.entities.remove(this.qd),this.Xn.forEach((t=>{this.Hn.entities.remove(t)}))):(this.jd.push(this.qd),this.jd.push.apply(this.jd,this.Xn),this.Xn=[]);else if(this.Nd===Pp.groundArea)if(this.qd.polygon.hierarchy=new r.PolygonHierarchy(this.Bd),this.Bd.length<3)this.Hn.entities.remove(this.qd),this.Xn.forEach((t=>{this.Hn.entities.remove(t)}));else{this.jd.push(this.qd),this.jd.push.apply(this.jd,this.Xn);const t=new r.Cartesian3;this.Bd.forEach((e=>{t.x+=e.x,t.y+=e.y,t.z+=e.z})),r.Cartesian3.divideByScalar(t,this.Bd.length,t),this.jd.push(this.Hd(t,"100")),this.Xn=[]}return this.Hn.scene.requestRender(),this.qd}Wd(t){const e=this.Hn.entities.add({position:t,point:{color:new r.Color(0,98/255,254/255,1),outlineColor:r.Color.WHITE,outlineWidth:1.5,pixelSize:5}});return this.Hn.scene.requestRender(),e}Hd(t,e){const n=this.Hn.entities.add({position:t,label:{text:e,font:"12px sans-serif",horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.CENTER,fillColor:r.Color.GHOSTWHITE,showBackground:!0,backgroundColor:new r.Color(0,98/255,254/255,1),backgroundPadding:new r.Cartesian2(4,4),pixelOffset:new r.Cartesian2(0,-20),disableDepthTestDistance:Number.POSITIVE_INFINITY}});return this.Hn.scene.requestRender(),n}Vd(){"open"===this.Os&&(this.Bd.pop(),this.Hn.entities.remove(this.Ld),this.Ld=void 0,this.Gd(),this.qd=void 0,this.Bd=[])}Yd(){this.me||(this.Os="open")}distance(t=!1){this.qd&&this.Vd(),this.Nd=Pp.distance,this.Yd()}area(t=!1){this.qd&&this.Vd(),this.Nd=Pp.groundArea,this.Yd()}stop(t){this.Os="closed",t&&this.clear()}clear(){this.Vd(),this.Ld&&this.Hn.entities.remove(this.Ld),this.Xn.forEach((t=>{this.Hn.entities.remove(t)})),this.qd&&this.Hn.entities.remove(this.qd),this.jd.forEach((t=>{this.Hn.entities.remove(t)})),this.Hn.scene.requestRender()}}Math.PI;const Qp=180/Math.PI,Zp=6378137,Jp=20037508.342789244,tv=t=>{const e=t[0],n=t[1];return[e/Zp*Qp,(2*Math.atan(Math.exp(n/Zp))-Math.PI/2)*Qp]},ev=t=>2*Jp/2**t,nv=tv,iv=(t,e,n)=>{const i=[-20037508.342789244,-20037508.342789244,20037508.342789244,20037508.342789244];let r;return r=void 0===n?40075016.68557849:256*Math.pow(2,n),[t=(t/r-.5)*i[2]*2,e=-(e/r-.5)*i[2]*2]},rv=t=>tv((t=>{const e=t[0],n=ev(e),i=t[1],r=t[2];return[(i+.5)*n-Jp,Jp-(r+.5)*n]})(t)),sv=(t,e=!1)=>{const n=t[0],i=ev(n),r=t[1],s=t[2],o=r*i-Jp,a=o+i,u=Jp-s*i,h=tv([o,u-i]),l=tv([a,u]),c=[h[0],h[1],l[0],l[1]];return e?[h,[l[0],h[1]],l,[h[0],l[1]]]:c};class ov{fo;do="栅格图";po=!1;vo;mo;yo;_show=!0;wo;Hn;Kd;Xd;Qd=0;Zd=0;bo;constructor(t){this.bo=t,this.Hn=t.viewer,this.vo=new r.Event,this.mo=new r.Event,this.Xd=new Gc({Hi:100,Bi:(t,e)=>{e.entity&&this.fo.remove(e.entity)}}),this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this.Kd=[[4,11,5],[4,12,5],[4,13,5],[4,11,6],[4,12,6],[4,13,6],[4,12,7],[4,13,7]]}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}update(){const t=(new Date).getTime();if(t-this.Qd<1e3)return!0;this.Qd=t;const e=this.fo,n=this.Hn,i=n.scene.canvas,s=new r.Cartesian2(i.clientWidth/2,i.clientHeight/2),o=n.scene.pickPosition(s);if(o){const i=n.scene.camera,s=r.Cartesian3.distance(i.positionWC,o),a=Math.min(this.bo.zooms[1],Math.round(Math.log2(2400/s))+16);if(a>=this.bo.zooms[0]&&this.show){const n=r.Cartographic.fromCartesian(o).height;if(n>=-400){if(e.suspendEvents(),e.removeAll(),this.bo.forceUpdateTime&&this.Zd){const e=Math.floor(t/(1e3*this.bo.forceUpdateTime));e!==this.Zd&&(this.Xd.xe(),this.Zd=e)}const s=i.frustum.computeCullingVolume(i.positionWC,i.directionWC,i.upWC).planes;(new Date).getTime();const o=[],u=t=>{let e=!1,h=!1;const l=sv(t),c=rv(t);let f=[c[0],c[1],n];const d=f[0],p=f[1],v=f[2],m=Ic([l[0],l[1],n],f),y=Ic([l[2],l[3],n],f),w=[m.x,m.y,m.z,y.x,y.y,Math.max(n,y.z)],g=4800*2**(16-t[0]),b=r.Cartesian3.fromDegrees(d,p,v),_=r.Transforms.eastNorthUpToFixedFrame(b),x=r.Matrix4.inverse(_,new r.Matrix4),k=s.map((t=>{const e=new r.Cartesian3(t.x,t.y,t.z),n=t.w,i=r.Matrix4.multiplyByPointAsVector(x,e,new r.Cartesian3),s=r.Cartesian3.multiplyByScalar(e,-n,new r.Cartesian3),o=r.Matrix4.multiplyByPoint(x,s,new r.Cartesian3),a=-r.Cartesian3.dot(i,o);return new r.Cartesian4(i.x,i.y,i.z,a)})),$=new r.Cartesian3(w[0],w[1],w[2]),S=new r.Cartesian3(w[3],w[4],w[5]),M=new r.AxisAlignedBoundingBox($,S);if(e=new r.CullingVolume(k).computeVisibility(M)!==r.Intersect.OUTSIDE,e){const e=((t,e,n)=>{const i=Fc(t,n);return((t,e,n,i,r,s,o,a,u)=>{let h=Math.max(t-o,0,o-i),l=Math.max(e-a,0,a-r),c=Math.max(n-u,0,u-s);return Math.sqrt(h*h+l*l+c*c)})(e[0],e[1],e[2],e[3],e[4],e[5],i.x,i.y,i.z)})(i.positionWC,w,f);if(h=e<=g,h)if(t[0]<a){const e=t[0]+1,n=[[e,t[1]<<1,t[2]<<1],[e,t[1]<<1,1+(t[2]<<1)],[e,1+(t[1]<<1),t[2]<<1],[e,1+(t[1]<<1),1+(t[2]<<1)]];for(let t=0;t<n.length;t+=1){const e=n[t];u(e)}}else o.push(t)}return[e,h,!1,!1]};for(let t=0;t<this.Kd.length;t+=1){const e=this.Kd[t];u(e)}o.forEach((t=>{t.join("_");const n=this.bo.getTileUrl(t,new Date),i=this.Xd.nr(n,!1);if(i)"loaded"==i.status&&(e.contains(i.entity)||(e.add(i.entity),this.bo.viewer.scene.requestRender()));else{const i=document.createElement("img");i.crossOrigin="anonymous",i.src=n;const s=sv(t);i.onload=()=>{const o=new r.Entity({id:n,rectangle:{coordinates:r.Rectangle.fromDegrees(s[0],s[1],s[2],s[3]),material:new r.ImageMaterialProperty({image:i}),zIndex:t[0]}});e.add(o),this.bo.viewer.scene.requestRender();const a=this.Xd.nr(n,!0);a.entity=o,a.status="loaded"},i.onerror=()=>{this.Xd.nr(n,!0).status="error"};const o={status:"loading",entity:null};this.Xd.rr(n,o)}})),e.resumeEvents()}}else e.removeAll()}return!0}}class av{Hn;Co;me=!1;constructor(t){const e=t.viewer;this.Hn=e,this.Co=new ov(t),e.dataSources.add(this.Co)}setVisibility(t,e){this.Co&&(this.Co.show=e)}hide(){this.Co&&(this.Co.show=!1)}show(){this.Co&&(this.Co.show=!0)}destory(){this.Co&&(this.Co.entities.removeAll(),this.Hn?.dataSources.remove(this.Co),this.Co=void 0),this.me=!0,this.Hn=void 0}}class uv extends av{constructor(t){super({name:"交通预测栅格图",viewer:t,forceUpdateTime:300,zooms:[8,17],getTileUrl:(t,e)=>`https://history.traffic.amap.com/traffic?type=2&day=${e.getDay()}&hh=${e.getHours()}&mm=${5*Math.floor(e.getMinutes()/5)}&x=${t[1]}&y=${t[2]}&z=${t[0]}`})}}class hv extends av{constructor(t){super({name:"路网栅格图",viewer:t,forceUpdateTime:0,zooms:[3,18],getTileUrl:t=>`https://wprd0${(t[1]+t[2])%4+1}.is.autonavi.com/appmaptile?x=${t[1]}&y=${t[2]}&z=${t[0]}&lang=zh_cn&size=1&scl=1&style=8`})}}class lv{fo;do="矢量实时路况";po=!1;vo;mo;yo;_show=!0;wo;Hn;Kd;Xd;Qd=0;Zd=0;bo;constructor(t){this.bo=t,this.Hn=t.viewer,this.vo=new r.Event,this.mo=new r.Event,this.Xd=new Gc({Hi:100,Bi:(t,e)=>{e.entity&&this.fo.remove(e.entity)}}),this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this.Kd=[[4,11,5],[4,12,5],[4,13,5],[4,11,6],[4,12,6],[4,13,6],[4,12,7],[4,13,7]]}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}update(){const t={0:"fff93a43",1:"fffcac19",2:"ff20a962",3:"ff83171c",4:"ffadadad"},e=(new Date).getTime();if(e-this.Qd<1e3)return!0;this.Qd=e;const n=this.fo,i=this.Hn,s=i.scene.canvas,o=new r.Cartesian2(s.clientWidth/2,s.clientHeight/2),a=i.scene.pickPosition(o);if(a){const s=i.scene.camera,o=r.Cartesian3.distance(s.positionWC,a),u=Math.min(this.bo.zooms[1],Math.round(Math.log2(2400/o))+16);if(u>=this.bo.zooms[0]&&this.show){const i=10;r.Cartographic.fromCartesian(a).height;{n.suspendEvents(),n.removeAll();const o=Math.floor(e/12e4);o!==this.Zd&&(this.Zd=o);const a=s.frustum.computeCullingVolume(s.positionWC,s.directionWC,s.upWC).planes;(new Date).getTime();const h=[],l=t=>{let e=!1,n=!1;const o=sv(t),c=rv(t);let f=[c[0],c[1],i];const d=f[0],p=f[1],v=f[2],m=Ic([o[0],o[1],i],f),y=Ic([o[2],o[3],i],f),w=[m.x,m.y,m.z,y.x,y.y,Math.max(i,y.z)],g=4800*2**(16-t[0]),b=r.Cartesian3.fromDegrees(d,p,v),_=r.Transforms.eastNorthUpToFixedFrame(b),x=r.Matrix4.inverse(_,new r.Matrix4),k=a.map((t=>{const e=new r.Cartesian3(t.x,t.y,t.z),n=t.w,i=r.Matrix4.multiplyByPointAsVector(x,e,new r.Cartesian3),s=r.Cartesian3.multiplyByScalar(e,-n,new r.Cartesian3),o=r.Matrix4.multiplyByPoint(x,s,new r.Cartesian3),a=-r.Cartesian3.dot(i,o);return new r.Cartesian4(i.x,i.y,i.z,a)})),$=new r.Cartesian3(w[0],w[1],w[2]),S=new r.Cartesian3(w[3],w[4],w[5]),M=new r.AxisAlignedBoundingBox($,S);if(e=new r.CullingVolume(k).computeVisibility(M)!==r.Intersect.OUTSIDE,e){const e=((t,e,n)=>{const i=Fc(t,n);return((t,e,n,i,r,s,o,a,u)=>{let h=Math.max(t-o,0,o-i),l=Math.max(e-a,0,a-r),c=Math.max(n-u,0,u-s);return Math.sqrt(h*h+l*l+c*c)})(e[0],e[1],e[2],e[3],e[4],e[5],i.x,i.y,i.z)})(s.positionWC,w,f);if(n=e<=g,n)if(t[0]<u){const e=t[0]+1,n=[[e,t[1]<<1,t[2]<<1],[e,t[1]<<1,1+(t[2]<<1)],[e,1+(t[1]<<1),t[2]<<1],[e,1+(t[1]<<1),1+(t[2]<<1)]];for(let t=0;t<n.length;t+=1){const e=n[t];l(e)}}else h.push(t)}return[e,n,!1,!1]};for(let t=0;t<this.Kd.length;t+=1){const e=this.Kd[t];l(e)}h.forEach((e=>{const i=function(t,e,n){let i,r,s,o,a,u;return o=Math.floor(n/2),s=n-o,i=(1<<o)-1<<s,r=(1<<s)-1,u=e&i|t&r,a=t&i|e&r,[n,a,u]}(e[1],e[2],e[0]),s="https://vdata.amap.com/traffic?key="+this.bo.key+"&v=YunJingCesium&t="+i,o=s+"&w="+12e4*this.Zd;let a=this.Xd.nr(s,!1),u=!1;a?("loaded"==a.status&&(a.entities.forEach((t=>{n.add(t)})),this.bo.viewer.scene.requestRender()),a.Zd!==this.Zd&&(u=!0)):(u=!0,a={status:"loading",entities:[]},this.Xd.rr(s,a)),u&&fetch(o).then((n=>{try{n.json().then((n=>{const a=this.Xd.nr(s,!1);if(a&&(a.status="loaded",a.entities=[],n.data)){n=(n=n.data)[i.join("_")];const s=(u=e[0],2*Jp/256/Math.pow(2,u));for(let i=0,u=n.length;i<u;i++){const u=n[i],h=Bc(t[i]);for(let t=0,n=u.length;t<n;t++){const n=u[t],i=.6*n[0]*this.bo.lineWidthFactor;for(let t=0,u=n[1].length;t<u;t++){const u=[],l=Lc(n[1][t]);for(let t=0,n=l.length;t<n;t+=2){const n=s*(256*e[1]+l[t]),i=s*(256*e[2]+l[t+1]),o=nv(iv(n,i)),a=r.Cartesian3.fromDegrees(o[0],o[1],0);u.push(a)}const c=new r.Entity({id:o+"_"+a.entities.length,polyline:{positions:u,clampToGround:!0,material:new r.Color(...h),zIndex:e[0],width:3*i}});a.entities.push(c)}}}a.Zd=this.Zd}var u}))}catch(t){const e=this.Xd.nr(s,!1);if(e)return void(e.status="loaded")}}))})),n.resumeEvents()}}else n.removeAll()}return!0}}class cv{Hn;Co;me=!1;constructor(t){t.zooms=t.zooms||[7,17],t.zooms=[Math.max(7,t.zooms[0]),Math.min(17,t.zooms[1])],t.lineWidthFactor=t.lineWidthFactor||1;const e=t.viewer;this.Hn=e,this.Co=new lv(t),e.dataSources.add(this.Co)}setVisibility(t,e){this.Co&&(this.Co.show=e)}hide(){this.Co&&(this.Co.show=!1)}show(){this.Co&&(this.Co.show=!0)}destroy(){this.Co&&(this.Co.entities.removeAll(),this.Hn?.dataSources.remove(this.Co),this.Co=void 0),this.me=!0,this.Hn=void 0}}class fv{fo;do="单体化图层";po=!1;vo;mo;yo;_show=!0;wo;Hn;bo;_o;qt;xo;ko;$o;So;Eo;constructor(t){this.bo=t,this.Eo=t.cb,this.Hn=t.viewer,this.qt=t.tiles,this._o=t.api_url,this.So={},this.xo=t.data,this.ko={},this.$o=new Gc({Hi:10,Bi:this.onDrop}),this.vo=new r.Event,this.mo=new r.Event,this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this.init()}init(){for(let t of this.xo)this.drawMonomer(this.fo,t,this.So);this.Eo&&this.Eo(this.fo)}drawMonomer(t,e,n){const i=e.id.toString().split("@")[0];if(void 0!==n[i])return;let s=[],o=e.min_height;const a=e.contours;for(let t of a){const n=parseFloat(t[0]),i=parseFloat(t[1]);s.push(n),s.push(i),s.push(e.max_height)}t.add({name:"polygon",polygon:{hierarchy:r.Cartesian3.fromDegreesArrayHeights(s),material:r.Color.BLUE.withAlpha(.3),extrudedHeight:o,perPositionHeight:!0}}),n[i]=e}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}onDrop=(t,e)=>{delete this.ko[t],this.So=[],this.xo=[],this.fo.removeAll();for(let t in this.ko)this.xo=this.xo.concat(this.ko[t]);for(let t of this.xo)this.drawMonomer(this.fo,t,this.So);return!0};updateData(t){for(let e of t)this.$o.ar(e)||(this.$o.rr(e,"1"),fetch(this._o+e+".json").then((t=>t.json())).then((t=>{this.ko[e]=t,this.xo=[];for(let t in this.ko)this.xo=this.xo.concat(this.ko[t]);for(let t of this.xo)this.drawMonomer(this.fo,t,this.So)})).catch((t=>{})));return!0}update(){return!0}pick(t){var e=this.Hn.scene.pick(t);return e?null!=e?.id?.id?this.So[e.id.id]:void 0:null}}class dv{Hn;Co;me=!1;constructor(t){const e=t.viewer;this.Hn=e,this.Co=new fv(t),e.dataSources.add(this.Co)}setVisibility(t,e){this.Co&&(this.Co.show=e)}hide(){this.Co&&(this.Co.entities.show=!1)}show(){this.Co&&(this.Co.entities.show=!0)}destory(){this.Co&&(this.Co.entities.removeAll(),this.Hn?.dataSources.remove(this.Co),this.Co=void 0),this.me=!0,this.Hn=void 0}getEntities(){return this.Co?.entities}update(t){return this.Co?.updateData(t)}pick(t){return this.Co?.pick(t)}}var pv,vv,mv=function(){if(vv)return pv;vv=1,pv=function(n,i){i||(i={});var r,s,o,a,u,h,l,c,f,d,p,v=null==i.cutoff?.25:i.cutoff,m=null==i.radius?8:i.radius,y=i.channel||0;if(ArrayBuffer.isView(n)||Array.isArray(n)){if(!i.width||!i.height)throw Error("For raw data width and height should be provided by options");r=i.width,s=i.height,a=n,h=i.stride?i.stride:Math.floor(n.length/r/s)}else window.HTMLCanvasElement&&n instanceof window.HTMLCanvasElement?(l=(c=n).getContext("2d"),r=c.width,s=c.height,a=(f=l.getImageData(0,0,r,s)).data,h=4):window.CanvasRenderingContext2D&&n instanceof window.CanvasRenderingContext2D?(l=n,r=(c=n.canvas).width,s=c.height,a=(f=l.getImageData(0,0,r,s)).data,h=4):window.ImageData&&n instanceof window.ImageData&&(f=n,r=n.width,s=n.height,a=f.data,h=4);if(o=Math.max(r,s),window.Uint8ClampedArray&&a instanceof window.Uint8ClampedArray||window.Uint8Array&&a instanceof window.Uint8Array)for(u=a,a=Array(r*s),d=0,p=Math.floor(u.length/h);d<p;d++)a[d]=u[d*h+y]/255;else if(1!==h)throw Error("Raw data can have only 1 value per pixel");var w=Array(r*s),g=Array(r*s),b=Array(o),_=Array(o),x=Array(o+1),k=Array(o);for(d=0,p=r*s;d<p;d++){var $=a[d];w[d]=1===$?0:0===$?t:Math.pow(Math.max(0,.5-$),2),g[d]=1===$?t:0===$?0:Math.pow(Math.max(0,$-.5),2)}e(w,r,s,b,_,k,x),e(g,r,s,b,_,k,x);var S=window.Float32Array?new Float32Array(r*s):new Array(r*s);for(d=0,p=r*s;d<p;d++)S[d]=Math.min(Math.max(1-((w[d]-g[d])/m+v),0),1);return S};var t=1e20;function e(t,e,i,r,s,o,a){for(var u=0;u<e;u++){for(var h=0;h<i;h++)r[h]=t[h*e+u];for(n(r,s,o,a,i),h=0;h<i;h++)t[h*e+u]=s[h]}for(h=0;h<i;h++){for(u=0;u<e;u++)r[u]=t[h*e+u];for(n(r,s,o,a,e),u=0;u<e;u++)t[h*e+u]=Math.sqrt(s[u])}}function n(t,e,n,i,r){n[0]=0,i[0]=-1e20,i[1]=1e20;for(var s=1,o=0;s<r;s++){for(var a=(t[s]+s*s-(t[n[o]]+n[o]*n[o]))/(2*s-2*n[o]);a<=i[o];)o--,a=(t[s]+s*s-(t[n[o]]+n[o]*n[o]))/(2*s-2*n[o]);n[++o]=s,i[o]=a,i[o+1]=1e20}for(s=0,o=0;s<r;s++){for(;i[o+1]<s;)o++;e[s]=(s-n[o])*(s-n[o])+t[n[o]]}}return pv}(),yv=Bf(mv);function wv(t){return t===e.HeightReference.CLAMP_TO_GROUND||t===e.HeightReference.CLAMP_TO_3D_TILE||t===e.HeightReference.CLAMP_TO_TERRAIN}const gv=e.Billboard.SHOW_INDEX,bv=e.Billboard.POSITION_INDEX,_v=e.Billboard.PIXEL_OFFSET_INDEX,xv=e.Billboard.EYE_OFFSET_INDEX,kv=e.Billboard.HORIZONTAL_ORIGIN_INDEX,$v=e.Billboard.VERTICAL_ORIGIN_INDEX,Sv=e.Billboard.SCALE_INDEX,Mv=e.Billboard.IMAGE_INDEX_INDEX,Ev=e.Billboard.COLOR_INDEX,Cv=e.Billboard.ROTATION_INDEX,Av=e.Billboard.ALIGNED_AXIS_INDEX,Ov=e.Billboard.SCALE_BY_DISTANCE_INDEX,Iv=e.Billboard.TRANSLUCENCY_BY_DISTANCE_INDEX,Tv=e.Billboard.PIXEL_OFFSET_SCALE_BY_DISTANCE_INDEX,zv=e.Billboard.DISTANCE_DISPLAY_CONDITION,Rv=e.Billboard.DISABLE_DEPTH_DISTANCE,Fv=e.Billboard.TEXTURE_COORDINATE_BOUNDS,Pv=e.Billboard.SDF_INDEX,Dv=e.Billboard.NUMBER_OF_PROPERTIES;let Nv;const Uv={positionHighAndScale:0,positionLowAndRotation:1,compressedAttribute0:2,compressedAttribute1:3,compressedAttribute2:4,eyeOffset:5,scaleByDistance:6,pixelOffsetScaleByDistance:7,compressedAttribute3:8,textureCoordinateBoundsOrLabelTranslate:9,a_batchId:10,sdf:11},qv={direction:0,positionHighAndScale:1,positionLowAndRotation:2,compressedAttribute0:3,compressedAttribute1:4,compressedAttribute2:5,eyeOffset:6,scaleByDistance:7,pixelOffsetScaleByDistance:8,compressedAttribute3:9,textureCoordinateBoundsOrLabelTranslate:10,a_batchId:11,sdf:12,roadDirection:13};function jv(t){t=e.defaultValue(t,e.defaultValue.EMPTY_OBJECT),this._scene=t.scene,this._batchTable=t.batchTable,this._textureAtlas=void 0,this._textureAtlasGUID=void 0,this._destroyTextureAtlas=!0,this._sp=void 0,this._spTranslucent=void 0,this._rsOpaque=void 0,this._rsTranslucent=void 0,this._vaf=void 0,this._billboards=[],this._billboardsToUpdate=[],this._billboardsToUpdateIndex=0,this._billboardsRemoved=!1,this._createVertexArray=!1,this._shaderRotation=!1,this._compiledShaderRotation=!1,this._shaderAlignedAxis=!1,this._compiledShaderAlignedAxis=!1,this._shaderScaleByDistance=!1,this._compiledShaderScaleByDistance=!1,this._shaderTranslucencyByDistance=!1,this._compiledShaderTranslucencyByDistance=!1,this._shaderPixelOffsetScaleByDistance=!1,this._compiledShaderPixelOffsetScaleByDistance=!1,this._shaderDistanceDisplayCondition=!1,this._compiledShaderDistanceDisplayCondition=!1,this._shaderDisableDepthDistance=!1,this._compiledShaderDisableDepthDistance=!1,this._shaderClampToGround=!1,this._compiledShaderClampToGround=!1,this._propertiesChanged=new Uint32Array(Dv),this._maxSize=0,this._maxEyeOffset=0,this._maxScale=1,this._maxPixelOffset=0,this._allHorizontalCenter=!0,this._allVerticalCenter=!0,this._allSizedInMeters=!0,this._baseVolume=new e.BoundingSphere,this._baseVolumeWC=new e.BoundingSphere,this._baseVolume2D=new e.BoundingSphere,this._boundingVolume=new e.BoundingSphere,this._boundingVolumeDirty=!1,this._colorCommands=[],this.show=e.defaultValue(t.show,!0),this.modelMatrix=e.Matrix4.clone(e.defaultValue(t.modelMatrix,e.Matrix4.IDENTITY)),this._modelMatrix=e.Matrix4.clone(e.Matrix4.IDENTITY),this.debugShowBoundingVolume=e.defaultValue(t.debugShowBoundingVolume,!1),this.debugShowTextureAtlas=e.defaultValue(t.debugShowTextureAtlas,!1),this.blendOption=e.defaultValue(t.blendOption,e.BlendOption.OPAQUE_AND_TRANSLUCENT),this._blendOption=void 0,this._mode=e.SceneMode.SCENE3D,this._buffersUsage=[e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW,e.BufferUsage.STATIC_DRAW],this._highlightColor=e.Color.clone(e.Color.WHITE);const n=this;this._uniforms={u_atlas:function(){return n._textureAtlas.texture},u_highlightColor:function(){return n._highlightColor}};const i=this._scene;e.defined(i)&&e.defined(i.terrainProviderChanged)&&(this._removeCallbackFunc=i.terrainProviderChanged.addEventListener((function(){const t=this._billboards,n=t.length;for(let i=0;i<n;++i)e.defined(t[i])&&t[i]._updateClamping()}),this))}function Bv(t){const e=t.length;for(let n=0;n<e;++n)t[n]&&t[n]._destroy()}function Lv(t){if(t._billboardsRemoved){t._billboardsRemoved=!1;const n=[],i=t._billboards,r=i.length;for(let t=0,s=0;t<r;++t){const r=i[t];e.defined(r)&&(r._index=s++,n.push(r))}t._billboards=n}}let Hv;function Wv(t){let n=t.cache.billboardCollection_indexBufferBatched;if(e.defined(n))return n;const i=new Uint16Array(98298);for(let t=0,e=0;t<98298;t+=6,e+=4)i[t]=e,i[t+1]=e+1,i[t+2]=e+2,i[t+3]=e+0,i[t+4]=e+2,i[t+5]=e+3;return n=e.Buffer.createIndexBuffer({context:t,typedArray:i,usage:e.BufferUsage.STATIC_DRAW,indexDatatype:e.IndexDatatype.UNSIGNED_SHORT}),n.vertexArrayDestroyable=!1,t.cache.billboardCollection_indexBufferBatched=n,n}function Vv(t){let n=t.cache.billboardCollection_indexBufferInstanced2;return e.defined(n)||(n=e.Buffer.createIndexBuffer({context:t,typedArray:new Uint16Array([0,1,2,0,2,3]),usage:e.BufferUsage.STATIC_DRAW,indexDatatype:e.IndexDatatype.UNSIGNED_SHORT}),n.vertexArrayDestroyable=!1,t.cache.billboardCollection_indexBufferInstanced2=n),n}function Gv(t){let n=t.cache.billboardCollection_vertexBufferInstanced2;return e.defined(n)||(n=e.Buffer.createVertexBuffer({context:t,typedArray:new Float32Array([0,0,1,0,1,1,0,1]),usage:e.BufferUsage.STATIC_DRAW}),n.vertexArrayDestroyable=!1,t.cache.billboardCollection_vertexBufferInstanced2=n),n}Object.defineProperties(jv.prototype,{length:{get:function(){return Lv(this),this._billboards.length}},textureAtlas:{get:function(){return this._textureAtlas},set:function(t){this._textureAtlas!==t&&(this._textureAtlas=this._destroyTextureAtlas&&this._textureAtlas&&this._textureAtlas.destroy(),this._textureAtlas=t,this._createVertexArray=!0)}},destroyTextureAtlas:{get:function(){return this._destroyTextureAtlas},set:function(t){this._destroyTextureAtlas=t}}}),jv.prototype.add=function(t){const n=new e.Billboard(t,this);return n._index=this._billboards.length,this._billboards.push(n),this._createVertexArray=!0,n},jv.prototype.remove=function(t){return!!this.contains(t)&&(this._billboards[t._index]=void 0,this._billboardsRemoved=!0,this._createVertexArray=!0,t._destroy(),!0)},jv.prototype.removeAll=function(){Bv(this._billboards),this._billboards=[],this._billboardsToUpdate=[],this._billboardsToUpdateIndex=0,this._billboardsRemoved=!1,this._createVertexArray=!0},jv.prototype._updateBillboard=function(t,e){t._dirty||(this._billboardsToUpdate[this._billboardsToUpdateIndex++]=t),++this._propertiesChanged[e]},jv.prototype.contains=function(t){return e.defined(t)&&t._billboardCollection===this},jv.prototype.get=function(t){return e.Check.typeOf.number("index",t),Lv(this),this._billboards[t]},jv.prototype.computeNewBuffersUsage=function(){const t=this._buffersUsage;let n=!1;const i=this._propertiesChanged;for(let r=0;r<Dv;++r){const s=0===i[r]?e.BufferUsage.STATIC_DRAW:e.BufferUsage.STREAM_DRAW;n=n||t[r]!==s,t[r]=s}return n};const Yv=new e.EncodedCartesian3;function Kv(t,n,i,r,s){let o;const a=r[Nv.positionHighAndScale],u=r[Nv.positionLowAndRotation],h=s._getActualPosition();t._mode===e.SceneMode.SCENE3D&&(e.BoundingSphere.expand(t._baseVolume,h,t._baseVolume),t._boundingVolumeDirty=!0),e.EncodedCartesian3.fromCartesian(h,Yv);const l=s.scale,c=s.rotation;0!==c&&(t._shaderRotation=!0),t._maxScale=Math.max(t._maxScale,l);const f=Yv.high,d=Yv.low;t._instanced?(o=s._index,a(o,f.x,f.y,f.z,l),u(o,d.x,d.y,d.z,c)):(o=4*s._index,a(o+0,f.x,f.y,f.z,l),a(o+1,f.x,f.y,f.z,l),a(o+2,f.x,f.y,f.z,l),a(o+3,f.x,f.y,f.z,l),u(o+0,d.x,d.y,d.z,c),u(o+1,d.x,d.y,d.z,c),u(o+2,d.x,d.y,d.z,c),u(o+3,d.x,d.y,d.z,c))}const Xv=new e.Cartesian2,Qv=32768,Zv=65536,Jv=4096,tm=256,em=1/256;function nm(t,n,i,r,s){let o;const a=r[Nv.compressedAttribute0],u=s.pixelOffset,h=u.x,l=u.y,c=s._translate,f=c.x,d=c.y;t._maxPixelOffset=Math.max(t._maxPixelOffset,Math.abs(h+f),Math.abs(-l+d));const p=s.horizontalOrigin;let v=s._verticalOrigin,m=s.show&&s.clusterShow;0===s.color.alpha&&(m=!1),v===e.VerticalOrigin.BASELINE&&(v=e.VerticalOrigin.BOTTOM),t._allHorizontalCenter=t._allHorizontalCenter&&p===e.HorizontalOrigin.CENTER,t._allVerticalCenter=t._allVerticalCenter&&v===e.VerticalOrigin.CENTER;let y=0,w=0,g=0,b=0;const _=s._imageIndex;if(-1!==_){const t=i[_];if(!e.defined(t))throw new e.DeveloperError(`Invalid billboard image index: ${_}`);y=t.x,w=t.y,g=t.width,b=t.height}const x=y+g,k=w+b;let $=128*Math.floor(e.Math.clamp(h,-32768,Qv)+Qv);$+=32*(p+1),$+=8*(v+1),$+=4*(m?1:0);let S=Math.floor(e.Math.clamp(l,-32768,Qv)+Qv)*tm,M=Math.floor(e.Math.clamp(f,-32768,Qv)+Qv)*tm;const E=(e.Math.clamp(d,-32768,Qv)+Qv)*em,C=Math.floor(E);S+=C,M+=Math.floor((E-C)*tm),Xv.x=y,Xv.y=w;const A=e.AttributeCompression.compressTextureCoordinates(Xv);Xv.x=x;const O=e.AttributeCompression.compressTextureCoordinates(Xv);Xv.y=k;const I=e.AttributeCompression.compressTextureCoordinates(Xv);Xv.x=y;const T=e.AttributeCompression.compressTextureCoordinates(Xv);t._instanced?(o=s._index,a(o,$,S,M,A)):(o=4*s._index,a(o+0,$+0,S,M,A),a(o+1,$+2,S,M,O),a(o+2,$+3,S,M,I),a(o+3,$+1,S,M,T))}function im(t,n,i,r,s){let o;const a=r[Nv.compressedAttribute1],u=s.alignedAxis;e.Cartesian3.equals(u,e.Cartesian3.ZERO)||(t._shaderAlignedAxis=!0);let h=0,l=1,c=1,f=1;const d=s.translucencyByDistance;e.defined(d)&&(h=d.near,l=d.nearValue,c=d.far,f=d.farValue,1===l&&1===f||(t._shaderTranslucencyByDistance=!0));let p=0;const v=s._imageIndex;if(-1!==v){const t=i[v];if(!e.defined(t))throw new e.DeveloperError(`Invalid billboard image index: ${v}`);p=t.width}const m=t._textureAtlas.texture.width,y=Math.round(e.defaultValue(s.width,m*p));t._maxSize=Math.max(t._maxSize,y);let w=e.Math.clamp(y,0,Zv),g=0;Math.abs(e.Cartesian3.magnitudeSquared(u)-1)<e.Math.EPSILON6&&(g=e.AttributeCompression.octEncodeFloat(u)),l=e.Math.clamp(l,0,1),l=1===l?255:255*l|0,w=w*tm+l,f=e.Math.clamp(f,0,1),f=1===f?255:255*f|0,g=g*tm+f,t._instanced?(o=s._index,a(o,w,g,h,c)):(o=4*s._index,a(o+0,w,g,h,c),a(o+1,w,g,h,c),a(o+2,w,g,h,c),a(o+3,w,g,h,c))}function rm(t,n,i,r,s){let o;const a=r[Nv.compressedAttribute2],u=s.color,h=e.defined(t._batchTable)?e.Color.WHITE:s.getPickId(n.context).color,l=s.sizeInMeters?1:0,c=Math.abs(e.Cartesian3.magnitudeSquared(s.alignedAxis)-1)<e.Math.EPSILON6?1:0;t._allSizedInMeters=t._allSizedInMeters&&1===l;let f=0;const d=s._imageIndex;if(-1!==d){const t=i[d];if(!e.defined(t))throw new e.DeveloperError(`Invalid billboard image index: ${d}`);f=t.height}const p=t._textureAtlas.texture.dimensions,v=Math.round(e.defaultValue(s.height,p.y*f));t._maxSize=Math.max(t._maxSize,v);let m=e.defaultValue(s._labelHorizontalOrigin,-2);m+=2;const y=4*v+m;let w=e.Color.floatToByte(u.red),g=e.Color.floatToByte(u.green),b=e.Color.floatToByte(u.blue);const _=w*Zv+g*tm+b;w=e.Color.floatToByte(h.red),g=e.Color.floatToByte(h.green),b=e.Color.floatToByte(h.blue);const x=w*Zv+g*tm+b;let k=e.Color.floatToByte(u.alpha)*Zv+e.Color.floatToByte(h.alpha)*tm;k+=2*l+c,t._instanced?(o=s._index,a(o,_,x,k,y)):(o=4*s._index,a(o+0,_,x,k,y),a(o+1,_,x,k,y),a(o+2,_,x,k,y),a(o+3,_,x,k,y))}function sm(t,n,i,r,s){let o;const a=r[Nv.eyeOffset],u=s.eyeOffset;let h=u.z;if(s._heightReference!==e.HeightReference.NONE&&(h*=1.005),t._maxEyeOffset=Math.max(t._maxEyeOffset,Math.abs(u.x),Math.abs(u.y),Math.abs(h)),t._instanced){let t=0,n=0;const r=s._imageIndex;if(-1!==r){const s=i[r];if(!e.defined(s))throw new e.DeveloperError(`Invalid billboard image index: ${r}`);t=s.width,n=s.height}Xv.x=t,Xv.y=n;const l=e.AttributeCompression.compressTextureCoordinates(Xv);o=s._index,a(o,u.x,u.y,h,l)}else o=4*s._index,a(o+0,u.x,u.y,h,0),a(o+1,u.x,u.y,h,0),a(o+2,u.x,u.y,h,0),a(o+3,u.x,u.y,h,0)}function om(t,n,i,r,s){let o;const a=r[Nv.scaleByDistance];let u=0,h=1,l=1,c=1;const f=s.scaleByDistance;e.defined(f)&&(u=f.near,h=f.nearValue,l=f.far,c=f.farValue,1===h&&1===c||(t._shaderScaleByDistance=!0)),t._instanced?(o=s._index,a(o,u,h,l,c)):(o=4*s._index,a(o+0,u,h,l,c),a(o+1,u,h,l,c),a(o+2,u,h,l,c),a(o+3,u,h,l,c))}function am(t,n,i,r,s){let o;const a=r[Nv.pixelOffsetScaleByDistance];let u=0,h=1,l=1,c=1;const f=s.pixelOffsetScaleByDistance;e.defined(f)&&(u=f.near,h=f.nearValue,l=f.far,c=f.farValue,1===h&&1===c||(t._shaderPixelOffsetScaleByDistance=!0)),t._instanced?(o=s._index,a(o,u,h,l,c)):(o=4*s._index,a(o+0,u,h,l,c),a(o+1,u,h,l,c),a(o+2,u,h,l,c),a(o+3,u,h,l,c))}function um(t,n,i,r,s){let o;const a=r[Nv.compressedAttribute3];let u=0,h=Number.MAX_VALUE;const l=s.distanceDisplayCondition;e.defined(l)&&(u=l.near,h=l.far,u*=u,h*=h,t._shaderDistanceDisplayCondition=!0);let c=s.disableDepthTestDistance;const f=wv(s.heightReference)&&n.context.depthTexture;let d,p;if(e.defined(c)||(c=f?5e3:0),c*=c,(f||c>0)&&(t._shaderDisableDepthDistance=!0,c===Number.POSITIVE_INFINITY&&(c=-1)),e.defined(s._labelDimensions))p=s._labelDimensions.x,d=s._labelDimensions.y;else{let n=0,r=0;const o=s._imageIndex;if(-1!==o){const t=i[o];if(!e.defined(t))throw new e.DeveloperError(`Invalid billboard image index: ${o}`);n=t.height,r=t.width}d=Math.round(e.defaultValue(s.height,t._textureAtlas.texture.dimensions.y*n));const a=t._textureAtlas.texture.width;p=Math.round(e.defaultValue(s.width,a*r))}const v=Math.floor(e.Math.clamp(p,0,Jv)),m=Math.floor(e.Math.clamp(d,0,Jv)),y=v*Jv+m;t._instanced?(o=s._index,a(o,u,h,c,y)):(o=4*s._index,a(o+0,u,h,c,y),a(o+1,u,h,c,y),a(o+2,u,h,c,y),a(o+3,u,h,c,y))}function hm(t,n,i,r,s){if(wv(s.heightReference)){const i=t._scene,r=n.context,s=n.globeTranslucencyState.translucent,o=e.defined(i.globe)&&i.globe.depthTestAgainstTerrain;t._shaderClampToGround=r.depthTexture&&!s&&o}let o;const a=r[Nv.textureCoordinateBoundsOrLabelTranslate];if(e.ContextLimits.maximumVertexTextureImageUnits>0){let n=0,i=0;return e.defined(s._labelTranslate)&&(n=s._labelTranslate.x,i=s._labelTranslate.y),void(t._instanced?(o=s._index,a(o,n,i,0,0)):(o=4*s._index,a(o+0,n,i,0,0),a(o+1,n,i,0,0),a(o+2,n,i,0,0),a(o+3,n,i,0,0)))}let u=0,h=0,l=0,c=0;const f=s._imageIndex;if(-1!==f){const t=i[f];if(!e.defined(t))throw new e.DeveloperError(`Invalid billboard image index: ${f}`);u=t.x,h=t.y,l=t.width,c=t.height}const d=u+l,p=h+c;t._instanced?(o=s._index,a(o,u,h,d,p)):(o=4*s._index,a(o+0,u,h,d,p),a(o+1,u,h,d,p),a(o+2,u,h,d,p),a(o+3,u,h,d,p))}function lm(t,n,i,r,s){if(!t._sdf)return;let o;const a=r[Nv.sdf],u=s.outlineColor,h=s.outlineWidth,l=e.Color.floatToByte(u.red),c=e.Color.floatToByte(u.green),f=e.Color.floatToByte(u.blue),d=l*Zv+c*tm+f,p=h/e.SDFSettings.RADIUS,v=e.Color.floatToByte(u.alpha)*Zv+e.Color.floatToByte(p)*tm;t._instanced?(o=s._index,a(o,d,v)):(o=4*s._index,a(o+0,d+0,v),a(o+1,d+2,v),a(o+2,d+3,v),a(o+3,d+1,v))}function cm(t,n,i,r,s){Kv(t,0,0,r,s),nm(t,0,i,r,s),im(t,0,i,r,s),rm(t,n,i,r,s),sm(t,0,i,r,s),om(t,0,0,r,s),am(t,0,0,r,s),um(t,n,i,r,s),hm(t,n,i,r,s),function(t,n,i,r,s){if(!e.defined(t._batchTable))return;const o=r[Nv.a_batchId],a=s._batchIndex;let u;t._instanced?(u=s._index,o(u,a)):(u=4*s._index,o(u+0,a),o(u+1,a),o(u+2,a),o(u+3,a))}(t,0,0,r,s),lm(t,0,0,r,s),function(t,e,n,i,r){if(!t._sdf)return;const s=i[Nv.roadDirection],o=r.roadDirection;s(r._index,o.x,o.y,o.z,o.w)}(t,0,0,r,s)}function fm(t,n,i,r,s,o){let a;r.mode===e.SceneMode.SCENE3D?(a=t._baseVolume,t._boundingVolumeDirty=!0):a=t._baseVolume2D;const u=[];for(let t=0;t<i;++t){const i=n[t],h=i.position,l=e.Billboard._computeActualPosition(i,h,r,s);e.defined(l)&&(i._setActualPosition(l),o?u.push(l):e.BoundingSphere.expand(a,l,a))}o&&e.BoundingSphere.fromPoints(u,a)}const dm=[];jv.prototype.update=function(t){if(Lv(this),!this.show)return;let n=this._billboards,i=n.length;const r=t.context;this._instanced=r.instancedArrays,Nv=this._instanced?qv:Uv,Hv=this._instanced?Vv:Wv;let s=this._textureAtlas;if(!e.defined(s)){s=this._textureAtlas=new e.TextureAtlas({context:r});for(let t=0;t<i;++t)n[t]._loadImage()}const o=s.textureCoordinates;if(0===o.length)return;!function(t,n){const i=n.mode,r=t._billboards,s=t._billboardsToUpdate,o=t._modelMatrix;t._createVertexArray||t._mode!==i||i!==e.SceneMode.SCENE3D&&!e.Matrix4.equals(o,t.modelMatrix)?(t._mode=i,e.Matrix4.clone(t.modelMatrix,o),t._createVertexArray=!0,i!==e.SceneMode.SCENE3D&&i!==e.SceneMode.SCENE2D&&i!==e.SceneMode.COLUMBUS_VIEW||fm(t,r,r.length,n,o,!0)):i===e.SceneMode.MORPHING?fm(t,r,r.length,n,o,!0):i!==e.SceneMode.SCENE2D&&i!==e.SceneMode.COLUMBUS_VIEW||fm(t,s,t._billboardsToUpdateIndex,n,o,!1)}(this,t),n=this._billboards,i=n.length;const a=this._billboardsToUpdate,u=this._billboardsToUpdateIndex,h=this._propertiesChanged,l=s.guid,c=this._createVertexArray||this._textureAtlasGUID!==l;let f;this._textureAtlasGUID=l;const d=t.passes,p=d.pick;if(c||!p&&this.computeNewBuffersUsage()){this._createVertexArray=!1;for(let t=0;t<Dv;++t)h[t]=0;if(this._vaf=this._vaf&&this._vaf.destroy(),i>0){this._vaf=function(t,n,i,r,s,o){const a=[{index:Nv.positionHighAndScale,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[bv]},{index:Nv.positionLowAndRotation,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[bv]},{index:Nv.compressedAttribute0,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[_v]},{index:Nv.compressedAttribute1,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Iv]},{index:Nv.compressedAttribute2,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Ev]},{index:Nv.eyeOffset,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[xv]},{index:Nv.scaleByDistance,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Ov]},{index:Nv.pixelOffsetScaleByDistance,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Tv]},{index:Nv.compressedAttribute3,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[zv]},{index:Nv.textureCoordinateBoundsOrLabelTranslate,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Fv]}];r&&a.push({index:Nv.direction,componentsPerAttribute:2,componentDatatype:e.ComponentDatatype.FLOAT,vertexBuffer:Gv(t)}),e.defined(s)&&a.push({index:Nv.a_batchId,componentsPerAttribute:1,componentDatatype:e.ComponentDatatype.FLOAT,bufferUsage:e.BufferUsage.STATIC_DRAW}),o&&(a.push({index:Nv.sdf,componentsPerAttribute:2,componentDatatype:e.ComponentDatatype.FLOAT,usage:i[Pv]}),a.push({index:Nv.roadDirection,componentsPerAttribute:4,componentDatatype:e.ComponentDatatype.FLOAT,usage:e.BufferUsage.STATIC_DRAW}));const u=r?n:4*n;return new e.VertexArrayFacade(t,a,u,r)}(r,i,this._buffersUsage,this._instanced,this._batchTable,this._sdf),f=this._vaf.writers;for(let e=0;e<i;++e){const n=this._billboards[e];n._dirty=!1,cm(this,t,o,f,n)}this._vaf.commit(Hv(r))}this._billboardsToUpdateIndex=0}else if(u>0){const e=dm;e.length=0,(h[bv]||h[Cv]||h[Sv])&&e.push(Kv),(h[Mv]||h[_v]||h[kv]||h[$v]||h[gv])&&(e.push(nm),this._instanced&&e.push(sm)),(h[Mv]||h[Av]||h[Iv])&&(e.push(im),e.push(rm)),(h[Mv]||h[Ev])&&e.push(rm),h[xv]&&e.push(sm),h[Ov]&&e.push(om),h[Tv]&&e.push(am),(h[zv]||h[Rv]||h[Mv]||h[bv])&&e.push(um),(h[Mv]||h[bv])&&e.push(hm),h[Pv]&&e.push(lm);const n=e.length;if(f=this._vaf.writers,u/i>.1){for(let i=0;i<u;++i){const r=a[i];r._dirty=!1;for(let i=0;i<n;++i)e[i](this,t,o,f,r)}this._vaf.commit(Hv(r))}else{for(let i=0;i<u;++i){const r=a[i];r._dirty=!1;for(let i=0;i<n;++i)e[i](this,t,o,f,r);this._instanced?this._vaf.subCommit(r._index,1):this._vaf.subCommit(4*r._index,4)}this._vaf.endSubCommits()}this._billboardsToUpdateIndex=0}if(u>1.5*i&&(a.length=i),!e.defined(this._vaf)||!e.defined(this._vaf.va))return;let v;this._boundingVolumeDirty&&(this._boundingVolumeDirty=!1,e.BoundingSphere.transform(this._baseVolume,this.modelMatrix,this._baseVolumeWC));let m=e.Matrix4.IDENTITY;t.mode===e.SceneMode.SCENE3D?(m=this.modelMatrix,v=e.BoundingSphere.clone(this._baseVolumeWC,this._boundingVolume)):v=e.BoundingSphere.clone(this._baseVolume2D,this._boundingVolume),function(t,e,n){let i=1;t._allSizedInMeters&&0===t._maxPixelOffset||(i=e.camera.getPixelSize(n,e.context.drawingBufferWidth,e.context.drawingBufferHeight));let r=i*t._maxScale*t._maxSize*2;t._allHorizontalCenter&&t._allVerticalCenter&&(r*=.5);const s=i*t._maxPixelOffset+t._maxEyeOffset;n.radius+=r+s}(this,t,v);const y=this._blendOption!==this.blendOption;if(this._blendOption=this.blendOption,y){this._blendOption===e.BlendOption.OPAQUE||this._blendOption===e.BlendOption.OPAQUE_AND_TRANSLUCENT?this._rsOpaque=e.RenderState.fromCache({depthTest:{enabled:!0,func:e.WebGLConstants.LESS},depthMask:!0}):this._rsOpaque=void 0;const t=this._blendOption===e.BlendOption.TRANSLUCENT;this._blendOption===e.BlendOption.TRANSLUCENT||this._blendOption===e.BlendOption.OPAQUE_AND_TRANSLUCENT?this._rsTranslucent=e.RenderState.fromCache({depthTest:{enabled:!1,func:t?e.WebGLConstants.LEQUAL:e.WebGLConstants.LESS},depthMask:!1,blending:e.BlendingState.ALPHA_BLEND}):this._rsTranslucent=void 0}let w,g,b,_,x;this._shaderDisableDepthDistance=this._shaderDisableDepthDistance||0!==t.minimumDisableDepthTestDistance;const k=e.ContextLimits.maximumVertexTextureImageUnits>0;if(y||this._shaderRotation!==this._compiledShaderRotation||this._shaderAlignedAxis!==this._compiledShaderAlignedAxis||this._shaderScaleByDistance!==this._compiledShaderScaleByDistance||this._shaderTranslucencyByDistance!==this._compiledShaderTranslucencyByDistance||this._shaderPixelOffsetScaleByDistance!==this._compiledShaderPixelOffsetScaleByDistance||this._shaderDistanceDisplayCondition!==this._compiledShaderDistanceDisplayCondition||this._shaderDisableDepthDistance!==this._compiledShaderDisableDepthDistance||this._shaderClampToGround!==this._compiledShaderClampToGround||this._sdf!==this._compiledSDF){w="#ifdef INSTANCED\nin vec2 direction;\n#endif\nin vec4 positionHighAndScale;in vec4 positionLowAndRotation;in vec4 compressedAttribute0;in vec4 compressedAttribute1;in vec4 compressedAttribute2;in vec4 eyeOffset;in vec4 scaleByDistance;in vec4 pixelOffsetScaleByDistance;in vec4 compressedAttribute3;in vec2 sdf;\n#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\nin vec4 textureCoordinateBoundsOrLabelTranslate;\n#endif\n#ifdef VECTOR_TILE\nin float a_batchId;\n#endif\n#ifdef SDF\nin vec4 roadDirection;\n#endif\nout vec2 v_textureCoordinates;\n#ifdef FRAGMENT_DEPTH_CHECK\nout vec4 v_textureCoordinateBounds;out vec4 v_originTextureCoordinateAndTranslate;out vec4 v_compressed;out mat2 v_rotationMatrix;\n#endif\nout vec4 v_pickColor;out vec4 v_color;\n#ifdef SDF\nout vec4 v_outlineColor;out float v_outlineWidth;\n#endif\nout float v_discard;const float UPPER_BOUND=32768.0;const float SHIFT_LEFT16=65536.0;const float SHIFT_LEFT12=4096.0;const float SHIFT_LEFT8=256.0;const float SHIFT_LEFT7=128.0;const float SHIFT_LEFT5=32.0;const float SHIFT_LEFT3=8.0;const float SHIFT_LEFT2=4.0;const float SHIFT_LEFT1=2.0;const float SHIFT_RIGHT12=1.0/4096.0;const float SHIFT_RIGHT8=1.0/256.0;const float SHIFT_RIGHT7=1.0/128.0;const float SHIFT_RIGHT5=1.0/32.0;const float SHIFT_RIGHT3=1.0/8.0;const float SHIFT_RIGHT2=1.0/4.0;const float SHIFT_RIGHT1=1.0/2.0;vec4 addScreenSpaceOffset(vec4 positionEC,vec2 imageSize,float scale,vec2 direction,vec2 origin,vec2 translate,vec2 pixelOffset,vec3 alignedAxis,bool validAlignedAxis,float rotation,bool sizeInMeters,out mat2 rotationMatrix,out float mpp){vec2 halfSize=imageSize*scale*0.5;halfSize*=((direction*2.0)-1.0);vec2 originTranslate=origin*abs(halfSize);\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\nif(validAlignedAxis||rotation!=0.0){float angle=rotation;if(validAlignedAxis){vec4 projectedAlignedAxis=czm_modelView3D*vec4(alignedAxis,0.0);angle+=sign(-projectedAlignedAxis.x)*acos(sign(projectedAlignedAxis.y)*(projectedAlignedAxis.y*projectedAlignedAxis.y)/(projectedAlignedAxis.x*projectedAlignedAxis.x+projectedAlignedAxis.y*projectedAlignedAxis.y));}float cosTheta=cos(angle);float sinTheta=sin(angle);rotationMatrix=mat2(cosTheta,sinTheta,-sinTheta,cosTheta);halfSize=rotationMatrix*halfSize;}else{rotationMatrix=mat2(1.0,0.0,0.0,1.0);}\n#endif\nmpp=czm_metersPerPixel(positionEC);positionEC.xy+=(originTranslate+halfSize)*czm_branchFreeTernary(sizeInMeters,1.0,mpp);positionEC.xy+=(translate+pixelOffset)*mpp;return positionEC;}float getGlobeDepth(vec4 positionEC){vec4 posWC=czm_eyeToWindowCoordinates(positionEC);float globeDepth=czm_unpackDepth(texture(czm_globeDepthTexture,posWC.xy/czm_viewport.zw));if(globeDepth==0.0){return 0.0;}vec4 eyeCoordinate=czm_windowToEyeCoordinates(posWC.xy,globeDepth);return eyeCoordinate.z/eyeCoordinate.w;}float crossProduct(vec2 a,vec2 b){return a.x*b.y-a.y*b.x;}void main(){vec3 positionHigh=positionHighAndScale.xyz;vec3 positionLow=positionLowAndRotation.xyz;float scale=positionHighAndScale.w;\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\nfloat rotation=positionLowAndRotation.w;\n#else\nfloat rotation=0.0;\n#endif\nfloat compressed=compressedAttribute0.x;vec2 pixelOffset;pixelOffset.x=floor(compressed*SHIFT_RIGHT7);compressed-=pixelOffset.x*SHIFT_LEFT7;pixelOffset.x-=UPPER_BOUND;vec2 origin;origin.x=floor(compressed*SHIFT_RIGHT5);compressed-=origin.x*SHIFT_LEFT5;origin.y=floor(compressed*SHIFT_RIGHT3);compressed-=origin.y*SHIFT_LEFT3;\n#ifdef FRAGMENT_DEPTH_CHECK\nvec2 depthOrigin=origin.xy;\n#endif\norigin-=vec2(1.0);float show=floor(compressed*SHIFT_RIGHT2);compressed-=show*SHIFT_LEFT2;\n#ifdef INSTANCED\nvec2 textureCoordinatesBottomLeft=czm_decompressTextureCoordinates(compressedAttribute0.w);vec2 textureCoordinatesRange=czm_decompressTextureCoordinates(eyeOffset.w);vec2 textureCoordinates=textureCoordinatesBottomLeft+direction*textureCoordinatesRange;\n#else\nvec2 direction;direction.x=floor(compressed*SHIFT_RIGHT1);direction.y=compressed-direction.x*SHIFT_LEFT1;vec2 textureCoordinates=czm_decompressTextureCoordinates(compressedAttribute0.w);\n#endif\nfloat temp=compressedAttribute0.y*SHIFT_RIGHT8;pixelOffset.y=-(floor(temp)-UPPER_BOUND);vec2 translate;translate.y=(temp-floor(temp))*SHIFT_LEFT16;temp=compressedAttribute0.z*SHIFT_RIGHT8;translate.x=floor(temp)-UPPER_BOUND;translate.y+=(temp-floor(temp))*SHIFT_LEFT8;translate.y-=UPPER_BOUND;temp=compressedAttribute1.x*SHIFT_RIGHT8;float temp2=floor(compressedAttribute2.w*SHIFT_RIGHT2);vec2 imageSize=vec2(floor(temp),temp2);\n#ifdef FRAGMENT_DEPTH_CHECK\nfloat labelHorizontalOrigin=floor(compressedAttribute2.w-(temp2*SHIFT_LEFT2));float applyTranslate=0.0;if(labelHorizontalOrigin!=0.0){applyTranslate=1.0;labelHorizontalOrigin-=2.0;depthOrigin.x=labelHorizontalOrigin+1.0;}depthOrigin=vec2(1.0)-(depthOrigin*0.5);\n#endif\n#ifdef EYE_DISTANCE_TRANSLUCENCY\nvec4 translucencyByDistance;translucencyByDistance.x=compressedAttribute1.z;translucencyByDistance.z=compressedAttribute1.w;translucencyByDistance.y=((temp-floor(temp))*SHIFT_LEFT8)/255.0;temp=compressedAttribute1.y*SHIFT_RIGHT8;translucencyByDistance.w=((temp-floor(temp))*SHIFT_LEFT8)/255.0;\n#endif\n#if defined(VERTEX_DEPTH_CHECK) || defined(FRAGMENT_DEPTH_CHECK)\ntemp=compressedAttribute3.w;temp=temp*SHIFT_RIGHT12;vec2 dimensions;dimensions.y=(temp-floor(temp))*SHIFT_LEFT12;dimensions.x=floor(temp);\n#endif\n#ifdef ALIGNED_AXIS\nvec3 alignedAxis=czm_octDecode(floor(compressedAttribute1.y*SHIFT_RIGHT8));temp=compressedAttribute2.z*SHIFT_RIGHT5;bool validAlignedAxis=(temp-floor(temp))*SHIFT_LEFT1>0.0;\n#else\nvec3 alignedAxis=vec3(0.0);bool validAlignedAxis=false;\n#endif\nvec4 pickColor;vec4 color;temp=compressedAttribute2.y;temp=temp*SHIFT_RIGHT8;pickColor.b=(temp-floor(temp))*SHIFT_LEFT8;temp=floor(temp)*SHIFT_RIGHT8;pickColor.g=(temp-floor(temp))*SHIFT_LEFT8;pickColor.r=floor(temp);temp=compressedAttribute2.x;temp=temp*SHIFT_RIGHT8;color.b=(temp-floor(temp))*SHIFT_LEFT8;temp=floor(temp)*SHIFT_RIGHT8;color.g=(temp-floor(temp))*SHIFT_LEFT8;color.r=floor(temp);temp=compressedAttribute2.z*SHIFT_RIGHT8;bool sizeInMeters=floor((temp-floor(temp))*SHIFT_LEFT7)>0.0;temp=floor(temp)*SHIFT_RIGHT8;pickColor.a=(temp-floor(temp))*SHIFT_LEFT8;pickColor/=255.0;color.a=floor(temp);color/=255.0;vec4 p=czm_translateRelativeToEye(positionHigh,positionLow);vec4 positionEC=czm_modelViewRelativeToEye*p;\n#if defined(FRAGMENT_DEPTH_CHECK) || defined(VERTEX_DEPTH_CHECK)\nfloat eyeDepth=positionEC.z;\n#endif\npositionEC=czm_eyeOffset(positionEC,eyeOffset.xyz);positionEC.xyz*=show;vec4 rawPosition=positionEC;\n#if defined(EYE_DISTANCE_SCALING) || defined(EYE_DISTANCE_TRANSLUCENCY) || defined(EYE_DISTANCE_PIXEL_OFFSET) || defined(DISTANCE_DISPLAY_CONDITION) || defined(DISABLE_DEPTH_DISTANCE)\nfloat lengthSq;if(czm_sceneMode==czm_sceneMode2D){lengthSq=czm_eyeHeight2D.y;}else{lengthSq=dot(positionEC.xyz,positionEC.xyz);}\n#endif\n#ifdef EYE_DISTANCE_SCALING\nfloat distanceScale=czm_nearFarScalar(scaleByDistance,lengthSq);scale*=distanceScale;translate*=distanceScale;if(scale==0.0){positionEC.xyz=vec3(0.0);}\n#endif\nfloat translucency=1.0;\n#ifdef EYE_DISTANCE_TRANSLUCENCY\ntranslucency=czm_nearFarScalar(translucencyByDistance,lengthSq);if(translucency==0.0){positionEC.xyz=vec3(0.0);}\n#endif\n#ifdef EYE_DISTANCE_PIXEL_OFFSET\nfloat pixelOffsetScale=czm_nearFarScalar(pixelOffsetScaleByDistance,lengthSq);pixelOffset*=pixelOffsetScale;\n#endif\n#ifdef DISTANCE_DISPLAY_CONDITION\nfloat nearSq=compressedAttribute3.x;float farSq=compressedAttribute3.y;if(lengthSq<nearSq||lengthSq>farSq){positionEC.xyz=vec3(0.0);}\n#endif\nmat2 rotationMatrix;float mpp;\n#ifdef DISABLE_DEPTH_DISTANCE\nfloat disableDepthTestDistance=compressedAttribute3.z;\n#endif\n#ifdef VERTEX_DEPTH_CHECK\nif(lengthSq<disableDepthTestDistance){float depthsilon=10.0;vec2 labelTranslate=textureCoordinateBoundsOrLabelTranslate.xy;vec4 pEC1=addScreenSpaceOffset(positionEC,dimensions,scale,vec2(0.0),origin,labelTranslate,pixelOffset,alignedAxis,validAlignedAxis,rotation,sizeInMeters,rotationMatrix,mpp);float globeDepth1=getGlobeDepth(pEC1);if(globeDepth1!=0.0&&pEC1.z+depthsilon<globeDepth1){vec4 pEC2=addScreenSpaceOffset(positionEC,dimensions,scale,vec2(0.0,1.0),origin,labelTranslate,pixelOffset,alignedAxis,validAlignedAxis,rotation,sizeInMeters,rotationMatrix,mpp);float globeDepth2=getGlobeDepth(pEC2);if(globeDepth2!=0.0&&pEC2.z+depthsilon<globeDepth2){vec4 pEC3=addScreenSpaceOffset(positionEC,dimensions,scale,vec2(1.0),origin,labelTranslate,pixelOffset,alignedAxis,validAlignedAxis,rotation,sizeInMeters,rotationMatrix,mpp);float globeDepth3=getGlobeDepth(pEC3);if(globeDepth3!=0.0&&pEC3.z+depthsilon<globeDepth3){positionEC.xyz=vec3(0.0);}}}}\n#endif\npositionEC=addScreenSpaceOffset(positionEC,imageSize,scale,direction,origin,translate,pixelOffset,alignedAxis,validAlignedAxis,rotation,sizeInMeters,rotationMatrix,mpp);\n#ifdef SDF\nif(roadDirection.w>0.0){vec4 projectedPosition=czm_projection*rawPosition;vec4 worldPosition=czm_inverseView*rawPosition;vec4 endPosition=vec4(worldPosition.xyz+roadDirection.xyz,1.0);vec4 projectedEndPosition=czm_viewProjection*endPosition;vec4 ndcPos=projectedPosition/projectedPosition.w;vec4 ndcEndPos=projectedEndPosition/projectedEndPosition.w;vec2 screenPos=(czm_viewportTransformation*ndcPos).xy;vec2 screenEndPos=(czm_viewportTransformation*ndcEndPos).xy;vec2 screenDir=normalize(screenEndPos-screenPos);vec2 originDir=vec2(1.0,0.0);float cosThetaValue=dot(originDir,screenDir);float sign=crossProduct(originDir,screenDir);float theta=czm_branchFreeTernary(sign>0.0,1.0,-1.0)*acos(cosThetaValue);if(theta>czm_piOverTwo){theta=theta-czm_pi;}if(theta<-czm_piOverTwo){theta=theta+czm_pi;}float cosTheta=cos(theta);float sinTheta=sin(theta);mat4 T=mat4(1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,-rawPosition.x,-rawPosition.y,-rawPosition.z,1.0);mat4 R=mat4(cosTheta,sinTheta,0.0,0.0,-sinTheta,cosTheta,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0);mat4 invT=mat4(1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,rawPosition.x,rawPosition.y,rawPosition.z,1.0);positionEC=invT*R*T*positionEC;}\n#endif\ngl_Position=czm_projection*positionEC;v_textureCoordinates=textureCoordinates;\n#ifdef LOG_DEPTH\nczm_vertexLogDepth();\n#endif\n#ifdef DISABLE_DEPTH_DISTANCE\nif(disableDepthTestDistance==0.0&&czm_minimumDisableDepthTestDistance!=0.0){disableDepthTestDistance=czm_minimumDisableDepthTestDistance;}if(disableDepthTestDistance!=0.0){float zclip=gl_Position.z/gl_Position.w;bool clipped=(zclip<-1.0||zclip>1.0);if(!clipped&&(disableDepthTestDistance<0.0||(lengthSq>0.0&&lengthSq<disableDepthTestDistance))){gl_Position.z=-gl_Position.w;\n#ifdef LOG_DEPTH\nv_depthFromNearPlusOne=1.0;\n#endif\n}}\n#endif\n#ifdef FRAGMENT_DEPTH_CHECK\nif(sizeInMeters){translate/=mpp;dimensions/=mpp;imageSize/=mpp;}\n#if defined(ROTATION) || defined(ALIGNED_AXIS)\nv_rotationMatrix=rotationMatrix;\n#else\nv_rotationMatrix=mat2(1.0,0.0,0.0,1.0);\n#endif\nfloat enableDepthCheck=0.0;if(lengthSq<disableDepthTestDistance){enableDepthCheck=1.0;}float dw=floor(clamp(dimensions.x,0.0,SHIFT_LEFT12));float dh=floor(clamp(dimensions.y,0.0,SHIFT_LEFT12));float iw=floor(clamp(imageSize.x,0.0,SHIFT_LEFT12));float ih=floor(clamp(imageSize.y,0.0,SHIFT_LEFT12));v_compressed.x=eyeDepth;v_compressed.y=applyTranslate*SHIFT_LEFT1+enableDepthCheck;v_compressed.z=dw*SHIFT_LEFT12+dh;v_compressed.w=iw*SHIFT_LEFT12+ih;v_originTextureCoordinateAndTranslate.xy=depthOrigin;v_originTextureCoordinateAndTranslate.zw=translate;v_textureCoordinateBounds=textureCoordinateBoundsOrLabelTranslate;\n#endif\n#ifdef SDF\nvec4 outlineColor;float outlineWidth;temp=sdf.x;temp=temp*SHIFT_RIGHT8;outlineColor.b=(temp-floor(temp))*SHIFT_LEFT8;temp=floor(temp)*SHIFT_RIGHT8;outlineColor.g=(temp-floor(temp))*SHIFT_LEFT8;outlineColor.r=floor(temp);temp=sdf.y;temp=temp*SHIFT_RIGHT8;float temp3=(temp-floor(temp))*SHIFT_LEFT8;temp=floor(temp)*SHIFT_RIGHT8;outlineWidth=(temp-floor(temp))*SHIFT_LEFT8;outlineColor.a=floor(temp);outlineColor/=255.0;v_outlineWidth=outlineWidth/255.0;v_outlineColor=outlineColor;v_outlineColor.a*=translucency;\n#endif\nv_pickColor=pickColor;v_color=color;v_color.a*=translucency;v_discard=0.0;if(lengthSq<disableDepthTestDistance){float sceneDepth=getGlobeDepth(rawPosition);if(positionEC.z+10.<sceneDepth){v_discard=1.0;}}}",g="uniform sampler2D u_atlas;\n#ifdef VECTOR_TILE\nuniform vec4 u_highlightColor;\n#endif\nin vec2 v_textureCoordinates;in vec4 v_pickColor;in vec4 v_color;\n#ifdef SDF\nin vec4 v_outlineColor;in float v_outlineWidth;\n#endif\nin float v_discard;\n#ifdef FRAGMENT_DEPTH_CHECK\nin vec4 v_textureCoordinateBounds;in vec4 v_originTextureCoordinateAndTranslate;in vec4 v_compressed;in mat2 v_rotationMatrix;const float SHIFT_LEFT12=4096.0;const float SHIFT_LEFT1=2.0;const float SHIFT_RIGHT12=1.0/4096.0;const float SHIFT_RIGHT1=1.0/2.0;float getGlobeDepth(vec2 adjustedST,vec2 depthLookupST,bool applyTranslate,vec2 dimensions,vec2 imageSize){vec2 lookupVector=imageSize*(depthLookupST-adjustedST);lookupVector=v_rotationMatrix*lookupVector;vec2 labelOffset=(dimensions-imageSize)*(depthLookupST-vec2(0.0,v_originTextureCoordinateAndTranslate.y));vec2 translation=v_originTextureCoordinateAndTranslate.zw;if(applyTranslate){translation+=(dimensions*v_originTextureCoordinateAndTranslate.xy*vec2(1.0,0.0));}vec2 st=((lookupVector-translation+labelOffset)+gl_FragCoord.xy)/czm_viewport.zw;float logDepthOrDepth=czm_unpackDepth(texture(czm_globeDepthTexture,st));if(logDepthOrDepth==0.0){return 0.0;}vec4 eyeCoordinate=czm_windowToEyeCoordinates(gl_FragCoord.xy,logDepthOrDepth);return eyeCoordinate.z/eyeCoordinate.w;}\n#endif\n#ifdef SDF\nfloat getDistance(vec2 position){return texture(u_atlas,position).r;}vec4 getSDFColor(vec2 position,float outlineWidth,vec4 outlineColor,float smoothing){float distance=getDistance(position);if(outlineWidth>0.0){float outlineEdge=clamp(SDF_EDGE-outlineWidth,0.0,SDF_EDGE);float outlineFactor=smoothstep(SDF_EDGE-smoothing,SDF_EDGE+smoothing,distance);vec4 sdfColor=mix(outlineColor,v_color,outlineFactor);float alpha=smoothstep(outlineEdge-smoothing,outlineEdge+smoothing,distance);return vec4(sdfColor.rgb,sdfColor.a*alpha);}else{float alpha=smoothstep(SDF_EDGE-smoothing,SDF_EDGE+smoothing,distance);return vec4(v_color.rgb,v_color.a*alpha);}}\n#endif\nvoid main(){if(v_discard>0.0){discard;return;}vec4 color=texture(u_atlas,v_textureCoordinates);\n#ifdef SDF\nfloat outlineWidth=v_outlineWidth;vec4 outlineColor=v_outlineColor;float distance=getDistance(v_textureCoordinates);\n#if (__VERSION__ == 300 || defined(GL_OES_standard_derivatives))\nfloat smoothing=fwidth(distance);vec2 sampleOffset=0.354*vec2(dFdx(v_textureCoordinates)+dFdy(v_textureCoordinates));vec4 center=getSDFColor(v_textureCoordinates,outlineWidth,outlineColor,smoothing);vec4 color1=getSDFColor(v_textureCoordinates+vec2(sampleOffset.x,sampleOffset.y),outlineWidth,outlineColor,smoothing);vec4 color2=getSDFColor(v_textureCoordinates+vec2(-sampleOffset.x,sampleOffset.y),outlineWidth,outlineColor,smoothing);vec4 color3=getSDFColor(v_textureCoordinates+vec2(-sampleOffset.x,-sampleOffset.y),outlineWidth,outlineColor,smoothing);vec4 color4=getSDFColor(v_textureCoordinates+vec2(sampleOffset.x,-sampleOffset.y),outlineWidth,outlineColor,smoothing);color=(center+color1+color2+color3+color4)/5.0;\n#else\nfloat smoothing=1.0/32.0;color=getSDFColor(v_textureCoordinates,outlineWidth,outlineColor,smoothing);\n#endif\ncolor=czm_gammaCorrect(color);\n#else\ncolor=czm_gammaCorrect(color);color*=czm_gammaCorrect(v_color);\n#endif\n#if !defined(OPAQUE) && !defined(TRANSLUCENT)\nif(color.a<0.005){discard;}\n#else\n#ifdef OPAQUE\nif(color.a<0.995){discard;}\n#else\nif(color.a>=0.995){discard;}\n#endif\n#endif\n#ifdef VECTOR_TILE\ncolor*=u_highlightColor;\n#endif\nout_FragColor=color;\n#ifdef LOG_DEPTH\nczm_writeLogDepth();\n#endif\n}",x=[],e.defined(this._batchTable)&&(x.push("VECTOR_TILE"),w=this._batchTable.getVertexShaderCallback(!1,"a_batchId",void 0)(w),g=this._batchTable.getFragmentShaderCallback(!1,void 0)(g)),b=new e.ShaderSource({defines:x,sources:[w]}),this._instanced&&b.defines.push("INSTANCED"),this._shaderRotation&&b.defines.push("ROTATION"),this._shaderAlignedAxis&&b.defines.push("ALIGNED_AXIS"),this._shaderScaleByDistance&&b.defines.push("EYE_DISTANCE_SCALING"),this._shaderTranslucencyByDistance&&b.defines.push("EYE_DISTANCE_TRANSLUCENCY"),this._shaderPixelOffsetScaleByDistance&&b.defines.push("EYE_DISTANCE_PIXEL_OFFSET"),this._shaderDistanceDisplayCondition&&b.defines.push("DISTANCE_DISPLAY_CONDITION"),this._shaderDisableDepthDistance&&b.defines.push("DISABLE_DEPTH_DISTANCE"),this._shaderClampToGround&&(k?b.defines.push("VERTEX_DEPTH_CHECK"):b.defines.push("FRAGMENT_DEPTH_CHECK"));const t=1-e.SDFSettings.CUTOFF;this._sdf&&b.defines.push("SDF");const n=e.defined(this._batchTable)?"VECTOR_TILE":"";this._blendOption===e.BlendOption.OPAQUE_AND_TRANSLUCENT&&(_=new e.ShaderSource({defines:["OPAQUE",n],sources:[g]}),this._shaderClampToGround&&(k?_.defines.push("VERTEX_DEPTH_CHECK"):_.defines.push("FRAGMENT_DEPTH_CHECK")),this._sdf&&(_.defines.push("SDF"),_.defines.push(`SDF_EDGE ${t}`)),this._sp=e.ShaderProgram.replaceCache({context:r,shaderProgram:this._sp,vertexShaderSource:b,fragmentShaderSource:_,attributeLocations:Nv}),_=new e.ShaderSource({defines:["TRANSLUCENT",n],sources:[g]}),this._shaderClampToGround&&(k?_.defines.push("VERTEX_DEPTH_CHECK"):_.defines.push("FRAGMENT_DEPTH_CHECK")),this._sdf&&(_.defines.push("SDF"),_.defines.push(`SDF_EDGE ${t}`)),this._spTranslucent=e.ShaderProgram.replaceCache({context:r,shaderProgram:this._spTranslucent,vertexShaderSource:b,fragmentShaderSource:_,attributeLocations:Nv})),this._blendOption===e.BlendOption.OPAQUE&&(_=new e.ShaderSource({defines:[n],sources:[g]}),this._shaderClampToGround&&(k?_.defines.push("VERTEX_DEPTH_CHECK"):_.defines.push("FRAGMENT_DEPTH_CHECK")),this._sdf&&(_.defines.push("SDF"),_.defines.push(`SDF_EDGE ${t}`)),this._sp=e.ShaderProgram.replaceCache({context:r,shaderProgram:this._sp,vertexShaderSource:b,fragmentShaderSource:_,attributeLocations:Nv})),this._blendOption===e.BlendOption.TRANSLUCENT&&(_=new e.ShaderSource({defines:[n],sources:[g]}),this._shaderClampToGround&&(k?_.defines.push("VERTEX_DEPTH_CHECK"):_.defines.push("FRAGMENT_DEPTH_CHECK")),this._sdf&&(_.defines.push("SDF"),_.defines.push(`SDF_EDGE ${t}`)),this._spTranslucent=e.ShaderProgram.replaceCache({context:r,shaderProgram:this._spTranslucent,vertexShaderSource:b,fragmentShaderSource:_,attributeLocations:Nv})),this._compiledShaderRotation=this._shaderRotation,this._compiledShaderAlignedAxis=this._shaderAlignedAxis,this._compiledShaderScaleByDistance=this._shaderScaleByDistance,this._compiledShaderTranslucencyByDistance=this._shaderTranslucencyByDistance,this._compiledShaderPixelOffsetScaleByDistance=this._shaderPixelOffsetScaleByDistance,this._compiledShaderDistanceDisplayCondition=this._shaderDistanceDisplayCondition,this._compiledShaderDisableDepthDistance=this._shaderDisableDepthDistance,this._compiledShaderClampToGround=this._shaderClampToGround,this._compiledSDF=this._sdf}const $=t.commandList;if(d.render||d.pick){const n=this._colorCommands,r=this._blendOption===e.BlendOption.OPAQUE,s=this._blendOption===e.BlendOption.OPAQUE_AND_TRANSLUCENT,o=this._vaf.va,a=o.length;let u,h=this._uniforms;e.defined(this._batchTable)?(h=this._batchTable.getUniformMapCallback()(h),u=this._batchTable.getPickId()):u="v_pickColor",n.length=a;const l=s?2*a:a;for(let t=0;t<l;++t){let a=n[t];e.defined(a)||(a=n[t]=new e.DrawCommand);const l=r||s&&t%2==0;a.pass=l||!s?e.Pass.OPAQUE:e.Pass.TRANSLUCENT,a.owner=this;const c=s?Math.floor(t/2):t;a.boundingVolume=v,a.modelMatrix=m,a.count=o[c].indicesCount,a.shaderProgram=l?this._sp:this._spTranslucent,a.uniformMap=h,a.vertexArray=o[c].va,a.renderState=l?this._rsOpaque:this._rsTranslucent,a.debugShowBoundingVolume=this.debugShowBoundingVolume,a.pickId=u,this._instanced&&(a.count=6,a.instanceCount=i),$.push(a)}this.debugShowTextureAtlas&&(e.defined(this.debugCommand)||(this.debugCommand=function(t,n){const i=n.createViewportQuadCommand("uniform sampler2D billboard_texture; \nin vec2 v_textureCoordinates; \nvoid main() \n{ \n out_FragColor = texture(billboard_texture, v_textureCoordinates); \n} \n",{uniformMap:{billboard_texture:function(){return t._textureAtlas.texture}}});return i.pass=e.Pass.OVERLAY,i}(this,t.context)),$.push(this.debugCommand))}},jv.prototype.isDestroyed=function(){return!1},jv.prototype.destroy=function(){return e.defined(this._removeCallbackFunc)&&(this._removeCallbackFunc(),this._removeCallbackFunc=void 0),this._textureAtlas=this._destroyTextureAtlas&&this._textureAtlas&&this._textureAtlas.destroy(),this._sp=this._sp&&this._sp.destroy(),this._spTranslucent=this._spTranslucent&&this._spTranslucent.destroy(),this._vaf=this._vaf&&this._vaf.destroy(),Bv(this._billboards),e.destroyObject(this)};var pm,vm,mm={exports:{}},ym=(pm||(pm=1,(vm=mm).exports&&(vm.exports=function(){var t=3,e=4,n=12,i=13,r=16,s=17;function o(t,e){void 0===e&&(e=0);var n=t.charCodeAt(e);if(55296<=n&&n<=56319&&e<t.length-1){var i=n;return 56320<=(r=t.charCodeAt(e+1))&&r<=57343?1024*(i-55296)+(r-56320)+65536:i}if(56320<=n&&n<=57343&&e>=1){var r=n;return 55296<=(i=t.charCodeAt(e-1))&&i<=56319?1024*(i-55296)+(r-56320)+65536:r}return n}function a(o,a,u){var h=[o].concat(a).concat([u]),l=h[h.length-2],c=u,f=h.lastIndexOf(14);if(f>1&&h.slice(1,f).every((function(e){return e==t}))&&-1==[t,i,s].indexOf(o))return 2;var d=h.lastIndexOf(e);if(d>0&&h.slice(1,d).every((function(t){return t==e}))&&-1==[n,e].indexOf(l))return h.filter((function(t){return t==e})).length%2==1?3:4;if(0==l&&1==c)return 0;if(2==l||0==l||1==l)return 14==c&&a.every((function(e){return e==t}))?2:1;if(2==c||0==c||1==c)return 1;if(6==l&&(6==c||7==c||9==c||10==c))return 0;if(!(9!=l&&7!=l||7!=c&&8!=c))return 0;if((10==l||8==l)&&8==c)return 0;if(c==t||15==c)return 0;if(5==c)return 0;if(l==n)return 0;var p=-1!=h.indexOf(t)?h.lastIndexOf(t)-1:h.length-2;return-1!=[i,s].indexOf(h[p])&&h.slice(p+1,-1).every((function(e){return e==t}))&&14==c||15==l&&-1!=[r,s].indexOf(c)?0:-1!=a.indexOf(e)?2:l==e&&c==e?0:1}function u(o){return 1536<=o&&o<=1541||1757==o||1807==o||2274==o||3406==o||69821==o||70082<=o&&o<=70083||72250==o||72326<=o&&o<=72329||73030==o?n:13==o?0:10==o?1:0<=o&&o<=9||11<=o&&o<=12||14<=o&&o<=31||127<=o&&o<=159||173==o||1564==o||6158==o||8203==o||8206<=o&&o<=8207||8232==o||8233==o||8234<=o&&o<=8238||8288<=o&&o<=8292||8293==o||8294<=o&&o<=8303||55296<=o&&o<=57343||65279==o||65520<=o&&o<=65528||65529<=o&&o<=65531||113824<=o&&o<=113827||119155<=o&&o<=119162||917504==o||917505==o||917506<=o&&o<=917535||917632<=o&&o<=917759||918e3<=o&&o<=921599?2:768<=o&&o<=879||1155<=o&&o<=1159||1160<=o&&o<=1161||1425<=o&&o<=1469||1471==o||1473<=o&&o<=1474||1476<=o&&o<=1477||1479==o||1552<=o&&o<=1562||1611<=o&&o<=1631||1648==o||1750<=o&&o<=1756||1759<=o&&o<=1764||1767<=o&&o<=1768||1770<=o&&o<=1773||1809==o||1840<=o&&o<=1866||1958<=o&&o<=1968||2027<=o&&o<=2035||2070<=o&&o<=2073||2075<=o&&o<=2083||2085<=o&&o<=2087||2089<=o&&o<=2093||2137<=o&&o<=2139||2260<=o&&o<=2273||2275<=o&&o<=2306||2362==o||2364==o||2369<=o&&o<=2376||2381==o||2385<=o&&o<=2391||2402<=o&&o<=2403||2433==o||2492==o||2494==o||2497<=o&&o<=2500||2509==o||2519==o||2530<=o&&o<=2531||2561<=o&&o<=2562||2620==o||2625<=o&&o<=2626||2631<=o&&o<=2632||2635<=o&&o<=2637||2641==o||2672<=o&&o<=2673||2677==o||2689<=o&&o<=2690||2748==o||2753<=o&&o<=2757||2759<=o&&o<=2760||2765==o||2786<=o&&o<=2787||2810<=o&&o<=2815||2817==o||2876==o||2878==o||2879==o||2881<=o&&o<=2884||2893==o||2902==o||2903==o||2914<=o&&o<=2915||2946==o||3006==o||3008==o||3021==o||3031==o||3072==o||3134<=o&&o<=3136||3142<=o&&o<=3144||3146<=o&&o<=3149||3157<=o&&o<=3158||3170<=o&&o<=3171||3201==o||3260==o||3263==o||3266==o||3270==o||3276<=o&&o<=3277||3285<=o&&o<=3286||3298<=o&&o<=3299||3328<=o&&o<=3329||3387<=o&&o<=3388||3390==o||3393<=o&&o<=3396||3405==o||3415==o||3426<=o&&o<=3427||3530==o||3535==o||3538<=o&&o<=3540||3542==o||3551==o||3633==o||3636<=o&&o<=3642||3655<=o&&o<=3662||3761==o||3764<=o&&o<=3769||3771<=o&&o<=3772||3784<=o&&o<=3789||3864<=o&&o<=3865||3893==o||3895==o||3897==o||3953<=o&&o<=3966||3968<=o&&o<=3972||3974<=o&&o<=3975||3981<=o&&o<=3991||3993<=o&&o<=4028||4038==o||4141<=o&&o<=4144||4146<=o&&o<=4151||4153<=o&&o<=4154||4157<=o&&o<=4158||4184<=o&&o<=4185||4190<=o&&o<=4192||4209<=o&&o<=4212||4226==o||4229<=o&&o<=4230||4237==o||4253==o||4957<=o&&o<=4959||5906<=o&&o<=5908||5938<=o&&o<=5940||5970<=o&&o<=5971||6002<=o&&o<=6003||6068<=o&&o<=6069||6071<=o&&o<=6077||6086==o||6089<=o&&o<=6099||6109==o||6155<=o&&o<=6157||6277<=o&&o<=6278||6313==o||6432<=o&&o<=6434||6439<=o&&o<=6440||6450==o||6457<=o&&o<=6459||6679<=o&&o<=6680||6683==o||6742==o||6744<=o&&o<=6750||6752==o||6754==o||6757<=o&&o<=6764||6771<=o&&o<=6780||6783==o||6832<=o&&o<=6845||6846==o||6912<=o&&o<=6915||6964==o||6966<=o&&o<=6970||6972==o||6978==o||7019<=o&&o<=7027||7040<=o&&o<=7041||7074<=o&&o<=7077||7080<=o&&o<=7081||7083<=o&&o<=7085||7142==o||7144<=o&&o<=7145||7149==o||7151<=o&&o<=7153||7212<=o&&o<=7219||7222<=o&&o<=7223||7376<=o&&o<=7378||7380<=o&&o<=7392||7394<=o&&o<=7400||7405==o||7412==o||7416<=o&&o<=7417||7616<=o&&o<=7673||7675<=o&&o<=7679||8204==o||8400<=o&&o<=8412||8413<=o&&o<=8416||8417==o||8418<=o&&o<=8420||8421<=o&&o<=8432||11503<=o&&o<=11505||11647==o||11744<=o&&o<=11775||12330<=o&&o<=12333||12334<=o&&o<=12335||12441<=o&&o<=12442||42607==o||42608<=o&&o<=42610||42612<=o&&o<=42621||42654<=o&&o<=42655||42736<=o&&o<=42737||43010==o||43014==o||43019==o||43045<=o&&o<=43046||43204<=o&&o<=43205||43232<=o&&o<=43249||43302<=o&&o<=43309||43335<=o&&o<=43345||43392<=o&&o<=43394||43443==o||43446<=o&&o<=43449||43452==o||43493==o||43561<=o&&o<=43566||43569<=o&&o<=43570||43573<=o&&o<=43574||43587==o||43596==o||43644==o||43696==o||43698<=o&&o<=43700||43703<=o&&o<=43704||43710<=o&&o<=43711||43713==o||43756<=o&&o<=43757||43766==o||44005==o||44008==o||44013==o||64286==o||65024<=o&&o<=65039||65056<=o&&o<=65071||65438<=o&&o<=65439||66045==o||66272==o||66422<=o&&o<=66426||68097<=o&&o<=68099||68101<=o&&o<=68102||68108<=o&&o<=68111||68152<=o&&o<=68154||68159==o||68325<=o&&o<=68326||69633==o||69688<=o&&o<=69702||69759<=o&&o<=69761||69811<=o&&o<=69814||69817<=o&&o<=69818||69888<=o&&o<=69890||69927<=o&&o<=69931||69933<=o&&o<=69940||70003==o||70016<=o&&o<=70017||70070<=o&&o<=70078||70090<=o&&o<=70092||70191<=o&&o<=70193||70196==o||70198<=o&&o<=70199||70206==o||70367==o||70371<=o&&o<=70378||70400<=o&&o<=70401||70460==o||70462==o||70464==o||70487==o||70502<=o&&o<=70508||70512<=o&&o<=70516||70712<=o&&o<=70719||70722<=o&&o<=70724||70726==o||70832==o||70835<=o&&o<=70840||70842==o||70845==o||70847<=o&&o<=70848||70850<=o&&o<=70851||71087==o||71090<=o&&o<=71093||71100<=o&&o<=71101||71103<=o&&o<=71104||71132<=o&&o<=71133||71219<=o&&o<=71226||71229==o||71231<=o&&o<=71232||71339==o||71341==o||71344<=o&&o<=71349||71351==o||71453<=o&&o<=71455||71458<=o&&o<=71461||71463<=o&&o<=71467||72193<=o&&o<=72198||72201<=o&&o<=72202||72243<=o&&o<=72248||72251<=o&&o<=72254||72263==o||72273<=o&&o<=72278||72281<=o&&o<=72283||72330<=o&&o<=72342||72344<=o&&o<=72345||72752<=o&&o<=72758||72760<=o&&o<=72765||72767==o||72850<=o&&o<=72871||72874<=o&&o<=72880||72882<=o&&o<=72883||72885<=o&&o<=72886||73009<=o&&o<=73014||73018==o||73020<=o&&o<=73021||73023<=o&&o<=73029||73031==o||92912<=o&&o<=92916||92976<=o&&o<=92982||94095<=o&&o<=94098||113821<=o&&o<=113822||119141==o||119143<=o&&o<=119145||119150<=o&&o<=119154||119163<=o&&o<=119170||119173<=o&&o<=119179||119210<=o&&o<=119213||119362<=o&&o<=119364||121344<=o&&o<=121398||121403<=o&&o<=121452||121461==o||121476==o||121499<=o&&o<=121503||121505<=o&&o<=121519||122880<=o&&o<=122886||122888<=o&&o<=122904||122907<=o&&o<=122913||122915<=o&&o<=122916||122918<=o&&o<=122922||125136<=o&&o<=125142||125252<=o&&o<=125258||917536<=o&&o<=917631||917760<=o&&o<=917999?t:127462<=o&&o<=127487?e:2307==o||2363==o||2366<=o&&o<=2368||2377<=o&&o<=2380||2382<=o&&o<=2383||2434<=o&&o<=2435||2495<=o&&o<=2496||2503<=o&&o<=2504||2507<=o&&o<=2508||2563==o||2622<=o&&o<=2624||2691==o||2750<=o&&o<=2752||2761==o||2763<=o&&o<=2764||2818<=o&&o<=2819||2880==o||2887<=o&&o<=2888||2891<=o&&o<=2892||3007==o||3009<=o&&o<=3010||3014<=o&&o<=3016||3018<=o&&o<=3020||3073<=o&&o<=3075||3137<=o&&o<=3140||3202<=o&&o<=3203||3262==o||3264<=o&&o<=3265||3267<=o&&o<=3268||3271<=o&&o<=3272||3274<=o&&o<=3275||3330<=o&&o<=3331||3391<=o&&o<=3392||3398<=o&&o<=3400||3402<=o&&o<=3404||3458<=o&&o<=3459||3536<=o&&o<=3537||3544<=o&&o<=3550||3570<=o&&o<=3571||3635==o||3763==o||3902<=o&&o<=3903||3967==o||4145==o||4155<=o&&o<=4156||4182<=o&&o<=4183||4228==o||6070==o||6078<=o&&o<=6085||6087<=o&&o<=6088||6435<=o&&o<=6438||6441<=o&&o<=6443||6448<=o&&o<=6449||6451<=o&&o<=6456||6681<=o&&o<=6682||6741==o||6743==o||6765<=o&&o<=6770||6916==o||6965==o||6971==o||6973<=o&&o<=6977||6979<=o&&o<=6980||7042==o||7073==o||7078<=o&&o<=7079||7082==o||7143==o||7146<=o&&o<=7148||7150==o||7154<=o&&o<=7155||7204<=o&&o<=7211||7220<=o&&o<=7221||7393==o||7410<=o&&o<=7411||7415==o||43043<=o&&o<=43044||43047==o||43136<=o&&o<=43137||43188<=o&&o<=43203||43346<=o&&o<=43347||43395==o||43444<=o&&o<=43445||43450<=o&&o<=43451||43453<=o&&o<=43456||43567<=o&&o<=43568||43571<=o&&o<=43572||43597==o||43755==o||43758<=o&&o<=43759||43765==o||44003<=o&&o<=44004||44006<=o&&o<=44007||44009<=o&&o<=44010||44012==o||69632==o||69634==o||69762==o||69808<=o&&o<=69810||69815<=o&&o<=69816||69932==o||70018==o||70067<=o&&o<=70069||70079<=o&&o<=70080||70188<=o&&o<=70190||70194<=o&&o<=70195||70197==o||70368<=o&&o<=70370||70402<=o&&o<=70403||70463==o||70465<=o&&o<=70468||70471<=o&&o<=70472||70475<=o&&o<=70477||70498<=o&&o<=70499||70709<=o&&o<=70711||70720<=o&&o<=70721||70725==o||70833<=o&&o<=70834||70841==o||70843<=o&&o<=70844||70846==o||70849==o||71088<=o&&o<=71089||71096<=o&&o<=71099||71102==o||71216<=o&&o<=71218||71227<=o&&o<=71228||71230==o||71340==o||71342<=o&&o<=71343||71350==o||71456<=o&&o<=71457||71462==o||72199<=o&&o<=72200||72249==o||72279<=o&&o<=72280||72343==o||72751==o||72766==o||72873==o||72881==o||72884==o||94033<=o&&o<=94078||119142==o||119149==o?5:4352<=o&&o<=4447||43360<=o&&o<=43388?6:4448<=o&&o<=4519||55216<=o&&o<=55238?7:4520<=o&&o<=4607||55243<=o&&o<=55291?8:44032==o||44060==o||44088==o||44116==o||44144==o||44172==o||44200==o||44228==o||44256==o||44284==o||44312==o||44340==o||44368==o||44396==o||44424==o||44452==o||44480==o||44508==o||44536==o||44564==o||44592==o||44620==o||44648==o||44676==o||44704==o||44732==o||44760==o||44788==o||44816==o||44844==o||44872==o||44900==o||44928==o||44956==o||44984==o||45012==o||45040==o||45068==o||45096==o||45124==o||45152==o||45180==o||45208==o||45236==o||45264==o||45292==o||45320==o||45348==o||45376==o||45404==o||45432==o||45460==o||45488==o||45516==o||45544==o||45572==o||45600==o||45628==o||45656==o||45684==o||45712==o||45740==o||45768==o||45796==o||45824==o||45852==o||45880==o||45908==o||45936==o||45964==o||45992==o||46020==o||46048==o||46076==o||46104==o||46132==o||46160==o||46188==o||46216==o||46244==o||46272==o||46300==o||46328==o||46356==o||46384==o||46412==o||46440==o||46468==o||46496==o||46524==o||46552==o||46580==o||46608==o||46636==o||46664==o||46692==o||46720==o||46748==o||46776==o||46804==o||46832==o||46860==o||46888==o||46916==o||46944==o||46972==o||47e3==o||47028==o||47056==o||47084==o||47112==o||47140==o||47168==o||47196==o||47224==o||47252==o||47280==o||47308==o||47336==o||47364==o||47392==o||47420==o||47448==o||47476==o||47504==o||47532==o||47560==o||47588==o||47616==o||47644==o||47672==o||47700==o||47728==o||47756==o||47784==o||47812==o||47840==o||47868==o||47896==o||47924==o||47952==o||47980==o||48008==o||48036==o||48064==o||48092==o||48120==o||48148==o||48176==o||48204==o||48232==o||48260==o||48288==o||48316==o||48344==o||48372==o||48400==o||48428==o||48456==o||48484==o||48512==o||48540==o||48568==o||48596==o||48624==o||48652==o||48680==o||48708==o||48736==o||48764==o||48792==o||48820==o||48848==o||48876==o||48904==o||48932==o||48960==o||48988==o||49016==o||49044==o||49072==o||49100==o||49128==o||49156==o||49184==o||49212==o||49240==o||49268==o||49296==o||49324==o||49352==o||49380==o||49408==o||49436==o||49464==o||49492==o||49520==o||49548==o||49576==o||49604==o||49632==o||49660==o||49688==o||49716==o||49744==o||49772==o||49800==o||49828==o||49856==o||49884==o||49912==o||49940==o||49968==o||49996==o||50024==o||50052==o||50080==o||50108==o||50136==o||50164==o||50192==o||50220==o||50248==o||50276==o||50304==o||50332==o||50360==o||50388==o||50416==o||50444==o||50472==o||50500==o||50528==o||50556==o||50584==o||50612==o||50640==o||50668==o||50696==o||50724==o||50752==o||50780==o||50808==o||50836==o||50864==o||50892==o||50920==o||50948==o||50976==o||51004==o||51032==o||51060==o||51088==o||51116==o||51144==o||51172==o||51200==o||51228==o||51256==o||51284==o||51312==o||51340==o||51368==o||51396==o||51424==o||51452==o||51480==o||51508==o||51536==o||51564==o||51592==o||51620==o||51648==o||51676==o||51704==o||51732==o||51760==o||51788==o||51816==o||51844==o||51872==o||51900==o||51928==o||51956==o||51984==o||52012==o||52040==o||52068==o||52096==o||52124==o||52152==o||52180==o||52208==o||52236==o||52264==o||52292==o||52320==o||52348==o||52376==o||52404==o||52432==o||52460==o||52488==o||52516==o||52544==o||52572==o||52600==o||52628==o||52656==o||52684==o||52712==o||52740==o||52768==o||52796==o||52824==o||52852==o||52880==o||52908==o||52936==o||52964==o||52992==o||53020==o||53048==o||53076==o||53104==o||53132==o||53160==o||53188==o||53216==o||53244==o||53272==o||53300==o||53328==o||53356==o||53384==o||53412==o||53440==o||53468==o||53496==o||53524==o||53552==o||53580==o||53608==o||53636==o||53664==o||53692==o||53720==o||53748==o||53776==o||53804==o||53832==o||53860==o||53888==o||53916==o||53944==o||53972==o||54e3==o||54028==o||54056==o||54084==o||54112==o||54140==o||54168==o||54196==o||54224==o||54252==o||54280==o||54308==o||54336==o||54364==o||54392==o||54420==o||54448==o||54476==o||54504==o||54532==o||54560==o||54588==o||54616==o||54644==o||54672==o||54700==o||54728==o||54756==o||54784==o||54812==o||54840==o||54868==o||54896==o||54924==o||54952==o||54980==o||55008==o||55036==o||55064==o||55092==o||55120==o||55148==o||55176==o?9:44033<=o&&o<=44059||44061<=o&&o<=44087||44089<=o&&o<=44115||44117<=o&&o<=44143||44145<=o&&o<=44171||44173<=o&&o<=44199||44201<=o&&o<=44227||44229<=o&&o<=44255||44257<=o&&o<=44283||44285<=o&&o<=44311||44313<=o&&o<=44339||44341<=o&&o<=44367||44369<=o&&o<=44395||44397<=o&&o<=44423||44425<=o&&o<=44451||44453<=o&&o<=44479||44481<=o&&o<=44507||44509<=o&&o<=44535||44537<=o&&o<=44563||44565<=o&&o<=44591||44593<=o&&o<=44619||44621<=o&&o<=44647||44649<=o&&o<=44675||44677<=o&&o<=44703||44705<=o&&o<=44731||44733<=o&&o<=44759||44761<=o&&o<=44787||44789<=o&&o<=44815||44817<=o&&o<=44843||44845<=o&&o<=44871||44873<=o&&o<=44899||44901<=o&&o<=44927||44929<=o&&o<=44955||44957<=o&&o<=44983||44985<=o&&o<=45011||45013<=o&&o<=45039||45041<=o&&o<=45067||45069<=o&&o<=45095||45097<=o&&o<=45123||45125<=o&&o<=45151||45153<=o&&o<=45179||45181<=o&&o<=45207||45209<=o&&o<=45235||45237<=o&&o<=45263||45265<=o&&o<=45291||45293<=o&&o<=45319||45321<=o&&o<=45347||45349<=o&&o<=45375||45377<=o&&o<=45403||45405<=o&&o<=45431||45433<=o&&o<=45459||45461<=o&&o<=45487||45489<=o&&o<=45515||45517<=o&&o<=45543||45545<=o&&o<=45571||45573<=o&&o<=45599||45601<=o&&o<=45627||45629<=o&&o<=45655||45657<=o&&o<=45683||45685<=o&&o<=45711||45713<=o&&o<=45739||45741<=o&&o<=45767||45769<=o&&o<=45795||45797<=o&&o<=45823||45825<=o&&o<=45851||45853<=o&&o<=45879||45881<=o&&o<=45907||45909<=o&&o<=45935||45937<=o&&o<=45963||45965<=o&&o<=45991||45993<=o&&o<=46019||46021<=o&&o<=46047||46049<=o&&o<=46075||46077<=o&&o<=46103||46105<=o&&o<=46131||46133<=o&&o<=46159||46161<=o&&o<=46187||46189<=o&&o<=46215||46217<=o&&o<=46243||46245<=o&&o<=46271||46273<=o&&o<=46299||46301<=o&&o<=46327||46329<=o&&o<=46355||46357<=o&&o<=46383||46385<=o&&o<=46411||46413<=o&&o<=46439||46441<=o&&o<=46467||46469<=o&&o<=46495||46497<=o&&o<=46523||46525<=o&&o<=46551||46553<=o&&o<=46579||46581<=o&&o<=46607||46609<=o&&o<=46635||46637<=o&&o<=46663||46665<=o&&o<=46691||46693<=o&&o<=46719||46721<=o&&o<=46747||46749<=o&&o<=46775||46777<=o&&o<=46803||46805<=o&&o<=46831||46833<=o&&o<=46859||46861<=o&&o<=46887||46889<=o&&o<=46915||46917<=o&&o<=46943||46945<=o&&o<=46971||46973<=o&&o<=46999||47001<=o&&o<=47027||47029<=o&&o<=47055||47057<=o&&o<=47083||47085<=o&&o<=47111||47113<=o&&o<=47139||47141<=o&&o<=47167||47169<=o&&o<=47195||47197<=o&&o<=47223||47225<=o&&o<=47251||47253<=o&&o<=47279||47281<=o&&o<=47307||47309<=o&&o<=47335||47337<=o&&o<=47363||47365<=o&&o<=47391||47393<=o&&o<=47419||47421<=o&&o<=47447||47449<=o&&o<=47475||47477<=o&&o<=47503||47505<=o&&o<=47531||47533<=o&&o<=47559||47561<=o&&o<=47587||47589<=o&&o<=47615||47617<=o&&o<=47643||47645<=o&&o<=47671||47673<=o&&o<=47699||47701<=o&&o<=47727||47729<=o&&o<=47755||47757<=o&&o<=47783||47785<=o&&o<=47811||47813<=o&&o<=47839||47841<=o&&o<=47867||47869<=o&&o<=47895||47897<=o&&o<=47923||47925<=o&&o<=47951||47953<=o&&o<=47979||47981<=o&&o<=48007||48009<=o&&o<=48035||48037<=o&&o<=48063||48065<=o&&o<=48091||48093<=o&&o<=48119||48121<=o&&o<=48147||48149<=o&&o<=48175||48177<=o&&o<=48203||48205<=o&&o<=48231||48233<=o&&o<=48259||48261<=o&&o<=48287||48289<=o&&o<=48315||48317<=o&&o<=48343||48345<=o&&o<=48371||48373<=o&&o<=48399||48401<=o&&o<=48427||48429<=o&&o<=48455||48457<=o&&o<=48483||48485<=o&&o<=48511||48513<=o&&o<=48539||48541<=o&&o<=48567||48569<=o&&o<=48595||48597<=o&&o<=48623||48625<=o&&o<=48651||48653<=o&&o<=48679||48681<=o&&o<=48707||48709<=o&&o<=48735||48737<=o&&o<=48763||48765<=o&&o<=48791||48793<=o&&o<=48819||48821<=o&&o<=48847||48849<=o&&o<=48875||48877<=o&&o<=48903||48905<=o&&o<=48931||48933<=o&&o<=48959||48961<=o&&o<=48987||48989<=o&&o<=49015||49017<=o&&o<=49043||49045<=o&&o<=49071||49073<=o&&o<=49099||49101<=o&&o<=49127||49129<=o&&o<=49155||49157<=o&&o<=49183||49185<=o&&o<=49211||49213<=o&&o<=49239||49241<=o&&o<=49267||49269<=o&&o<=49295||49297<=o&&o<=49323||49325<=o&&o<=49351||49353<=o&&o<=49379||49381<=o&&o<=49407||49409<=o&&o<=49435||49437<=o&&o<=49463||49465<=o&&o<=49491||49493<=o&&o<=49519||49521<=o&&o<=49547||49549<=o&&o<=49575||49577<=o&&o<=49603||49605<=o&&o<=49631||49633<=o&&o<=49659||49661<=o&&o<=49687||49689<=o&&o<=49715||49717<=o&&o<=49743||49745<=o&&o<=49771||49773<=o&&o<=49799||49801<=o&&o<=49827||49829<=o&&o<=49855||49857<=o&&o<=49883||49885<=o&&o<=49911||49913<=o&&o<=49939||49941<=o&&o<=49967||49969<=o&&o<=49995||49997<=o&&o<=50023||50025<=o&&o<=50051||50053<=o&&o<=50079||50081<=o&&o<=50107||50109<=o&&o<=50135||50137<=o&&o<=50163||50165<=o&&o<=50191||50193<=o&&o<=50219||50221<=o&&o<=50247||50249<=o&&o<=50275||50277<=o&&o<=50303||50305<=o&&o<=50331||50333<=o&&o<=50359||50361<=o&&o<=50387||50389<=o&&o<=50415||50417<=o&&o<=50443||50445<=o&&o<=50471||50473<=o&&o<=50499||50501<=o&&o<=50527||50529<=o&&o<=50555||50557<=o&&o<=50583||50585<=o&&o<=50611||50613<=o&&o<=50639||50641<=o&&o<=50667||50669<=o&&o<=50695||50697<=o&&o<=50723||50725<=o&&o<=50751||50753<=o&&o<=50779||50781<=o&&o<=50807||50809<=o&&o<=50835||50837<=o&&o<=50863||50865<=o&&o<=50891||50893<=o&&o<=50919||50921<=o&&o<=50947||50949<=o&&o<=50975||50977<=o&&o<=51003||51005<=o&&o<=51031||51033<=o&&o<=51059||51061<=o&&o<=51087||51089<=o&&o<=51115||51117<=o&&o<=51143||51145<=o&&o<=51171||51173<=o&&o<=51199||51201<=o&&o<=51227||51229<=o&&o<=51255||51257<=o&&o<=51283||51285<=o&&o<=51311||51313<=o&&o<=51339||51341<=o&&o<=51367||51369<=o&&o<=51395||51397<=o&&o<=51423||51425<=o&&o<=51451||51453<=o&&o<=51479||51481<=o&&o<=51507||51509<=o&&o<=51535||51537<=o&&o<=51563||51565<=o&&o<=51591||51593<=o&&o<=51619||51621<=o&&o<=51647||51649<=o&&o<=51675||51677<=o&&o<=51703||51705<=o&&o<=51731||51733<=o&&o<=51759||51761<=o&&o<=51787||51789<=o&&o<=51815||51817<=o&&o<=51843||51845<=o&&o<=51871||51873<=o&&o<=51899||51901<=o&&o<=51927||51929<=o&&o<=51955||51957<=o&&o<=51983||51985<=o&&o<=52011||52013<=o&&o<=52039||52041<=o&&o<=52067||52069<=o&&o<=52095||52097<=o&&o<=52123||52125<=o&&o<=52151||52153<=o&&o<=52179||52181<=o&&o<=52207||52209<=o&&o<=52235||52237<=o&&o<=52263||52265<=o&&o<=52291||52293<=o&&o<=52319||52321<=o&&o<=52347||52349<=o&&o<=52375||52377<=o&&o<=52403||52405<=o&&o<=52431||52433<=o&&o<=52459||52461<=o&&o<=52487||52489<=o&&o<=52515||52517<=o&&o<=52543||52545<=o&&o<=52571||52573<=o&&o<=52599||52601<=o&&o<=52627||52629<=o&&o<=52655||52657<=o&&o<=52683||52685<=o&&o<=52711||52713<=o&&o<=52739||52741<=o&&o<=52767||52769<=o&&o<=52795||52797<=o&&o<=52823||52825<=o&&o<=52851||52853<=o&&o<=52879||52881<=o&&o<=52907||52909<=o&&o<=52935||52937<=o&&o<=52963||52965<=o&&o<=52991||52993<=o&&o<=53019||53021<=o&&o<=53047||53049<=o&&o<=53075||53077<=o&&o<=53103||53105<=o&&o<=53131||53133<=o&&o<=53159||53161<=o&&o<=53187||53189<=o&&o<=53215||53217<=o&&o<=53243||53245<=o&&o<=53271||53273<=o&&o<=53299||53301<=o&&o<=53327||53329<=o&&o<=53355||53357<=o&&o<=53383||53385<=o&&o<=53411||53413<=o&&o<=53439||53441<=o&&o<=53467||53469<=o&&o<=53495||53497<=o&&o<=53523||53525<=o&&o<=53551||53553<=o&&o<=53579||53581<=o&&o<=53607||53609<=o&&o<=53635||53637<=o&&o<=53663||53665<=o&&o<=53691||53693<=o&&o<=53719||53721<=o&&o<=53747||53749<=o&&o<=53775||53777<=o&&o<=53803||53805<=o&&o<=53831||53833<=o&&o<=53859||53861<=o&&o<=53887||53889<=o&&o<=53915||53917<=o&&o<=53943||53945<=o&&o<=53971||53973<=o&&o<=53999||54001<=o&&o<=54027||54029<=o&&o<=54055||54057<=o&&o<=54083||54085<=o&&o<=54111||54113<=o&&o<=54139||54141<=o&&o<=54167||54169<=o&&o<=54195||54197<=o&&o<=54223||54225<=o&&o<=54251||54253<=o&&o<=54279||54281<=o&&o<=54307||54309<=o&&o<=54335||54337<=o&&o<=54363||54365<=o&&o<=54391||54393<=o&&o<=54419||54421<=o&&o<=54447||54449<=o&&o<=54475||54477<=o&&o<=54503||54505<=o&&o<=54531||54533<=o&&o<=54559||54561<=o&&o<=54587||54589<=o&&o<=54615||54617<=o&&o<=54643||54645<=o&&o<=54671||54673<=o&&o<=54699||54701<=o&&o<=54727||54729<=o&&o<=54755||54757<=o&&o<=54783||54785<=o&&o<=54811||54813<=o&&o<=54839||54841<=o&&o<=54867||54869<=o&&o<=54895||54897<=o&&o<=54923||54925<=o&&o<=54951||54953<=o&&o<=54979||54981<=o&&o<=55007||55009<=o&&o<=55035||55037<=o&&o<=55063||55065<=o&&o<=55091||55093<=o&&o<=55119||55121<=o&&o<=55147||55149<=o&&o<=55175||55177<=o&&o<=55203?10:9757==o||9977==o||9994<=o&&o<=9997||127877==o||127938<=o&&o<=127940||127943==o||127946<=o&&o<=127948||128066<=o&&o<=128067||128070<=o&&o<=128080||128110==o||128112<=o&&o<=128120||128124==o||128129<=o&&o<=128131||128133<=o&&o<=128135||128170==o||128372<=o&&o<=128373||128378==o||128400==o||128405<=o&&o<=128406||128581<=o&&o<=128583||128587<=o&&o<=128591||128675==o||128692<=o&&o<=128694||128704==o||128716==o||129304<=o&&o<=129308||129310<=o&&o<=129311||129318==o||129328<=o&&o<=129337||129341<=o&&o<=129342||129489<=o&&o<=129501?i:127995<=o&&o<=127999?14:8205==o?15:9792==o||9794==o||9877<=o&&o<=9878||9992==o||10084==o||127752==o||127806==o||127859==o||127891==o||127908==o||127912==o||127979==o||127981==o||128139==o||128187<=o&&o<=128188||128295==o||128300==o||128488==o||128640==o||128658==o?r:128102<=o&&o<=128105?s:11}return this.nextBreak=function(t,e){if(void 0===e&&(e=0),e<0)return 0;if(e>=t.length-1)return t.length;for(var n,i,r=u(o(t,e)),s=[],h=e+1;h<t.length;h++)if(i=h-1,!(55296<=(n=t).charCodeAt(i)&&n.charCodeAt(i)<=56319&&56320<=n.charCodeAt(i+1)&&n.charCodeAt(i+1)<=57343)){var l=u(o(t,h));if(a(r,s,l))return h;s.push(l)}return t.length},this.splitGraphemes=function(t){for(var e,n=[],i=0;(e=this.nextBreak(t,i))<t.length;)n.push(t.slice(i,e)),i=e;return i<t.length&&n.push(t.slice(i)),n},this.iterateGraphemes=function(t){var e=0,n={next:function(){var n,i;return(i=this.nextBreak(t,e))<t.length?(n=t.slice(e,i),e=i,{value:n,done:!1}):e<t.length?(n=t.slice(e),e=t.length,{value:n,done:!1}):{value:void 0,done:!0}}.bind(this)};return"undefined"!=typeof Symbol&&Symbol.iterator&&(n[Symbol.iterator]=function(){return n}),n},this.countGraphemes=function(t){for(var e,n=0,i=0;(e=this.nextBreak(t,i))<t.length;)i=e,n++;return i<t.length&&n++,n},this})),mm.exports),wm=Bf(ym);function gm(){this.textureInfo=void 0,this.dimensions=void 0,this.billboard=void 0}function bm(t,e,n){this.labelCollection=t,this.index=e,this.dimensions=n}const _m="ID_WHITE_PIXEL",xm=new e.Cartesian2(4,4),km=new e.BoundingRectangle(1,1,1,1),$m={};function Sm(t,n,i,r,s,o,a){return $m.font=n,$m.fillColor=i,$m.strokeColor=r,$m.strokeWidth=s,$m.padding=e.SDFSettings.PADDING,a===e.VerticalOrigin.CENTER?$m.textBaseline="middle":a===e.VerticalOrigin.TOP?$m.textBaseline="top":$m.textBaseline="bottom",$m.fill=o===e.LabelStyle.FILL||o===e.LabelStyle.FILL_AND_OUTLINE,$m.stroke=o===e.LabelStyle.OUTLINE||o===e.LabelStyle.FILL_AND_OUTLINE,$m.backgroundColor=e.Color.BLACK,e.writeTextToCanvas(t,$m)}function Mm(t,n){n.textureInfo=void 0,n.dimensions=void 0;const i=n.billboard;e.defined(i)&&(i.show=!1,i.image=void 0,e.defined(i._removeCallbackFunc)&&(i._removeCallbackFunc(),i._removeCallbackFunc=void 0),t._reuseBillboards&&t._spareBillboards.push(i),n.billboard=void 0)}function Em(t,e,n,i){i.index=t.addImageSync(e,n)}const Cm=new wm;function Am(t,n){const i=n._renderedText,r=Cm.splitGraphemes(i),s=r.length,o=n._glyphs,a=o.length;let u,h,l;if(n._relativeSize=n._fontSize/e.SDFSettings.FONT_SIZE,s<a)for(h=s;h<a;++h)Mm(t,o[h]);o.length=s;const c=n.show&&n._showBackground&&i.split("\n").join("").length>0;let f=n._backgroundBillboard;const d=t._backgroundBillboardCollection;c?(e.defined(f)||(f=d.add({collection:t,image:_m,imageSubRegion:km}),n._backgroundBillboard=f),f.color=n._backgroundColor,f.show=n._show,f.position=n._position,f.eyeOffset=n._eyeOffset,f.pixelOffset=n._pixelOffset,f.horizontalOrigin=e.HorizontalOrigin.LEFT,f.verticalOrigin=n._verticalOrigin,f.heightReference=n._heightReference,f.scale=n.totalScale,f.pickPrimitive=n,f.id=n._id,f.translucencyByDistance=n._translucencyByDistance,f.pixelOffsetScaleByDistance=n._pixelOffsetScaleByDistance,f.scaleByDistance=n._scaleByDistance,f.distanceDisplayCondition=n._distanceDisplayCondition,f.disableDepthTestDistance=n._disableDepthTestDistance,f.clusterShow=n.clusterShow):e.defined(f)&&(d.remove(f),n._backgroundBillboard=f=void 0);const p=t._glyphTextureCache;for(l=0;l<s;++l){const i=r[l],s=n._verticalOrigin,a=JSON.stringify([i,n._fontFamily,n._fontStyle,n._fontWeight,+s]);let h=p[a];if(!e.defined(h)){const r=Sm(i,`${n._fontStyle} ${n._fontWeight} ${e.SDFSettings.FONT_SIZE}px ${n._fontFamily}`,e.Color.WHITE,e.Color.WHITE,0,e.LabelStyle.FILL,s);if(h=new bm(t,-1,r.dimensions),p[a]=h,r.width>0&&r.height>0){const n=yv(r,{cutoff:e.SDFSettings.CUTOFF,radius:e.SDFSettings.RADIUS}),s=r.getContext("2d"),o=r.width,u=r.height,l=s.getImageData(0,0,o,u);for(let t=0;t<o;t++)for(let e=0;e<u;e++){const i=e*o+t,r=255*n[i],s=4*i;l.data[s+0]=r,l.data[s+1]=r,l.data[s+2]=r,l.data[s+3]=r}s.putImageData(l,0,0)," "!==i&&Em(t._textureAtlas,a,r,h)}}if(u=o[l],e.defined(u)?-1===h.index?Mm(t,u):e.defined(u.textureInfo)&&(u.textureInfo=void 0):(u=new gm,o[l]=u),u.textureInfo=h,u.dimensions=h.dimensions,-1!==h.index){let i=u.billboard;const r=t._spareBillboards;e.defined(i)||(r.length>0?i=r.pop():(i=t._billboardCollection.add({collection:t}),i._labelDimensions=new e.Cartesian2,i._labelTranslate=new e.Cartesian2),u.billboard=i),i.show=n._show,i.position=n._position,i.eyeOffset=n._eyeOffset,i.pixelOffset=n._pixelOffset,i.horizontalOrigin=e.HorizontalOrigin.LEFT,i.verticalOrigin=n._verticalOrigin,i.heightReference=n._heightReference,i.scale=n.totalScale,i.pickPrimitive=n,i.id=n._id,i.image=a,i.translucencyByDistance=n._translucencyByDistance,i.pixelOffsetScaleByDistance=n._pixelOffsetScaleByDistance,i.scaleByDistance=n._scaleByDistance,i.distanceDisplayCondition=n._distanceDisplayCondition,i.disableDepthTestDistance=n._disableDepthTestDistance,i._batchIndex=n._batchIndex,i.outlineColor=n.outlineColor,i.roadDirection=n.roadDirection||Cesium.Cartesian4.ZERO.clone(),n.style===e.LabelStyle.FILL_AND_OUTLINE?(i.color=n._fillColor,i.outlineWidth=n.outlineWidth):n.style===e.LabelStyle.FILL?(i.color=n._fillColor,i.outlineWidth=0):n.style===e.LabelStyle.OUTLINE&&(i.color=e.Color.TRANSPARENT,i.outlineWidth=n.outlineWidth)}}n._repositionAllGlyphs=!0}function Om(t,n,i){return n===e.HorizontalOrigin.CENTER?-t/2:n===e.HorizontalOrigin.RIGHT?-(t+i.x):i.x}const Im=new e.Cartesian2,Tm=new e.Cartesian2;function zm(t){const n=t._glyphs,i=t._renderedText;let r,s,o=0,a=0;const u=[];let h,l=Number.NEGATIVE_INFINITY,c=0,f=1;const d=n.length,p=t._backgroundBillboard,v=e.Cartesian2.clone(e.defined(p)?t._backgroundPadding:e.Cartesian2.ZERO,Tm);for(v.x/=t._relativeSize,v.y/=t._relativeSize,h=0;h<d;++h)"\n"===i.charAt(h)?(u.push(o),++f,o=0):(r=n[h],s=r.dimensions,c=Math.max(c,s.height-s.descent),l=Math.max(l,s.descent),o+=s.width-s.minx,h<d-1&&(o+=n[h+1].dimensions.minx),a=Math.max(a,o));u.push(o);const m=c+l,y=t.totalScale,w=t._horizontalOrigin,g=t._verticalOrigin;let b=0,_=u[b],x=Om(_,w,v);const k=(e.defined(t._lineHeight)?t._lineHeight:1.2*t._fontSize)/t._relativeSize,$=k*(f-1);let S=a,M=m+$;e.defined(p)&&(S+=2*v.x,M+=2*v.y,p._labelHorizontalOrigin=w),Im.x=x*y,Im.y=0;let E=!0,C=0;for(h=0;h<d;++h)if("\n"===i.charAt(h))++b,C+=k,_=u[b],x=Om(_,w,v),Im.x=x*y,E=!0;else if(r=n[h],s=r.dimensions,g===e.VerticalOrigin.TOP?(Im.y=s.height-c-v.y,Im.y+=e.SDFSettings.PADDING):g===e.VerticalOrigin.CENTER?Im.y=($+s.height-c)/2:g===e.VerticalOrigin.BASELINE?(Im.y=$,Im.y-=e.SDFSettings.PADDING):(Im.y=$+l+v.y,Im.y-=e.SDFSettings.PADDING),Im.y=(Im.y-s.descent-C)*y,E&&(Im.x-=e.SDFSettings.PADDING*y,E=!1),e.defined(r.billboard)&&(r.billboard._setTranslate(Im),r.billboard._labelDimensions.x=S,r.billboard._labelDimensions.y=M,r.billboard._labelHorizontalOrigin=w),h<d-1){const t=n[h+1];Im.x+=(s.width-s.minx+t.dimensions.minx)*y}if(e.defined(p)&&i.split("\n").join("").length>0&&(x=w===e.HorizontalOrigin.CENTER?-a/2-v.x:w===e.HorizontalOrigin.RIGHT?-(a+2*v.x):0,Im.x=x*y,g===e.VerticalOrigin.TOP?Im.y=m-c-l:g===e.VerticalOrigin.CENTER?Im.y=(m-c)/2-l:g===e.VerticalOrigin.BASELINE?Im.y=-v.y-l:Im.y=0,Im.y=Im.y*y,p.width=S,p.height=M,p._setTranslate(Im),p._labelTranslate=e.Cartesian2.clone(Im,p._labelTranslate)),(A=t.heightReference)===e.HeightReference.CLAMP_TO_GROUND||A===e.HeightReference.CLAMP_TO_3D_TILE||A===e.HeightReference.CLAMP_TO_TERRAIN)for(h=0;h<d;++h){r=n[h];const t=r.billboard;e.defined(t)&&(t._labelTranslate=e.Cartesian2.clone(Im,t._labelTranslate))}var A}function Rm(t,n){const i=n._glyphs;for(let e=0,n=i.length;e<n;++e)Mm(t,i[e]);e.defined(n._backgroundBillboard)&&(t._backgroundBillboardCollection.remove(n._backgroundBillboard),n._backgroundBillboard=void 0),n._labelCollection=void 0,e.defined(n._removeCallbackFunc)&&n._removeCallbackFunc(),e.destroyObject(n)}function Fm(t){t=e.defaultValue(t,e.defaultValue.EMPTY_OBJECT),this.preloadSDF=!!t.preloadSDF,this.preloadSDFTextureUrl=e.defaultValue(t.preloadSDFTextureUrl,""),this.preloadSDFConfigUrl=e.defaultValue(t.preloadSDFConfigUrl,""),this._reuseBillboards=e.defaultValue(t.reuseBillboards,!0),this._scene=t.scene,this._batchTable=t.batchTable,this._textureAtlas=void 0,this._backgroundTextureAtlas=void 0,this._backgroundBillboardCollection=new jv({scene:this._scene}),this._backgroundBillboardCollection.destroyTextureAtlas=!1,this._billboardCollection=new jv({scene:this._scene,batchTable:this._batchTable}),this._billboardCollection.destroyTextureAtlas=!1,this._billboardCollection._sdf=!0,this._spareBillboards=[],this._glyphTextureCache={},this._labels=[],this._labelsToUpdate=[],this._totalGlyphCount=0,this._highlightColor=e.Color.clone(e.Color.WHITE),this.show=e.defaultValue(t.show,!0),this.modelMatrix=e.Matrix4.clone(e.defaultValue(t.modelMatrix,e.Matrix4.IDENTITY)),this.debugShowBoundingVolume=e.defaultValue(t.debugShowBoundingVolume,!1),this.blendOption=e.defaultValue(t.blendOption,e.BlendOption.OPAQUE_AND_TRANSLUCENT),this.preloadSDF?this.preload():this.preloaded=!0}Object.defineProperties(Fm.prototype,{length:{get:function(){return this._labels.length}}}),Fm.prototype.add=function(t){const n=new e.Label(t,this);return this._labels.push(n),this._labelsToUpdate.push(n),n},Fm.prototype.remove=function(t){if(e.defined(t)&&t._labelCollection===this){const e=this._labels.indexOf(t);if(-1!==e)return this._labels.splice(e,1),Rm(this,t),!0}return!1},Fm.prototype.removeAll=function(){const t=this._labels;for(let e=0,n=t.length;e<n;++e)Rm(this,t[e]);t.length=0},Fm.prototype.contains=function(t){return e.defined(t)&&t._labelCollection===this},Fm.prototype.get=function(t){if(!e.defined(t))throw new e.DeveloperError("index is required.");return this._labels[t]},Fm.prototype.update=function(t){if(!this.show)return;const n=this._billboardCollection,i=this._backgroundBillboardCollection;n.modelMatrix=this.modelMatrix,n.debugShowBoundingVolume=this.debugShowBoundingVolume,i.modelMatrix=this.modelMatrix,i.debugShowBoundingVolume=this.debugShowBoundingVolume;const r=t.context;e.defined(this._textureAtlas)||(this._textureAtlas=new e.TextureAtlas({context:r}),n.textureAtlas=this._textureAtlas),e.defined(this._backgroundTextureAtlas)||(this._backgroundTextureAtlas=new e.TextureAtlas({context:r,initialSize:xm}),i.textureAtlas=this._backgroundTextureAtlas,function(t){const e=document.createElement("canvas");e.width=xm.x,e.height=xm.y;const n=e.getContext("2d");n.fillStyle="#fff",n.fillRect(0,0,e.width,e.height),t.addImage(_m,e)}(this._backgroundTextureAtlas));const s=this._labelsToUpdate.length;for(let t=0;t<s;++t){const e=this._labelsToUpdate[t];if(e.isDestroyed())continue;const n=e._glyphs.length;e._rebindAllGlyphs&&(Am(this,e),e._rebindAllGlyphs=!1),e._repositionAllGlyphs&&(zm(e),e._repositionAllGlyphs=!1);const i=e._glyphs.length-n;this._totalGlyphCount+=i}const o=i.length>0?e.BlendOption.TRANSLUCENT:this.blendOption;n.blendOption=o,i.blendOption=o,n._highlightColor=this._highlightColor,i._highlightColor=this._highlightColor,this._labelsToUpdate.length=0,i.update(t),n.update(t)},Fm.prototype.isDestroyed=function(){return!1},Fm.prototype.destroy=function(){return this.removeAll(),this._billboardCollection=this._billboardCollection.destroy(),this._textureAtlas=this._textureAtlas&&this._textureAtlas.destroy(),this._backgroundBillboardCollection=this._backgroundBillboardCollection.destroy(),this._backgroundTextureAtlas=this._backgroundTextureAtlas&&this._backgroundTextureAtlas.destroy(),e.destroyObject(this)};const Pm=new RegExp(/[\u0000-\u0008\u000E-\u001F\u00ad\u202a-\u206f\u200b-\u200f]/,"g"),Dm={};function Nm(t,e,n=0,i=t.length-1,r=qm){for(;i>n;){if(i-n>600){const s=i-n+1,o=e-n+1,a=Math.log(s),u=.5*Math.exp(2*a/3),h=.5*Math.sqrt(a*u*(s-u)/s)*(o-s/2<0?-1:1);Nm(t,e,Math.max(n,Math.floor(e-o*u/s+h)),Math.min(i,Math.floor(e+(s-o)*u/s+h)),r)}const s=t[e];let o=n,a=i;for(Um(t,n,e),r(t[i],s)>0&&Um(t,n,i);o<a;){for(Um(t,o,a),o++,a--;r(t[o],s)<0;)o++;for(;r(t[a],s)>0;)a--}0===r(t[n],s)?Um(t,n,a):(a++,Um(t,a,i)),a<=e&&(n=a+1),e<=a&&(i=a-1)}}function Um(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function qm(t,e){return t<e?-1:t>e?1:0}Fm.prototype.computeLabelSize=function(t){const n=`${t.fontSize}:${t.text}`;if(Dm[n])return Dm[n];e.defined(this._textureAtlas)||(this._textureAtlas=new e.TextureAtlas({context:this._scene.context}),this._billboardCollection.textureAtlas=this._textureAtlas);const i=t.text.replace(Pm,""),r=Cm.splitGraphemes(i),s=r.length,o=[];let a,u;o.length=s;const h=this._glyphTextureCache;for(u=0;u<s;++u){const n=r[u],i=t.verticalOrigin,s=JSON.stringify([n,t.fontFamily,t.fontStyle,t.fontWeight,+i]);let l=h[s];if(!e.defined(l)){const r=Sm(n,`${t.fontStyle} ${t.fontWeight} ${e.SDFSettings.FONT_SIZE}px ${t.fontFamily}`,e.Color.WHITE,e.Color.WHITE,0,e.LabelStyle.FILL,i);if(l=new bm(this,-1,r.dimensions),h[s]=l,r.width>0&&r.height>0){const t=yv(r,{cutoff:e.SDFSettings.CUTOFF,radius:e.SDFSettings.RADIUS}),i=r.getContext("2d"),o=r.width,a=r.height,u=i.getImageData(0,0,o,a);for(let e=0;e<o;e++)for(let n=0;n<a;n++){const i=n*o+e,r=255*t[i],s=4*i;u.data[s+0]=r,u.data[s+1]=r,u.data[s+2]=r,u.data[s+3]=r}i.putImageData(u,0,0)," "!==n&&Em(this._textureAtlas,s,r,l)}}a=new gm,o[u]=a,a.textureInfo=l,a.dimensions=l.dimensions}let l,c,f=0,d=0,p=Number.NEGATIVE_INFINITY,v=0,m=1;const y=o.length;for(c=0;c<y;++c)"\n"===i.charAt(c)?(++m,f=0):(a=o[c],l=a.dimensions,v=Math.max(v,l.height-l.descent),p=Math.max(p,l.descent),f+=l.width-l.minx,c<y-1&&(f+=o[c+1].dimensions.minx),d=Math.max(d,f));let w=v+p+(e.defined(t.lineHeight)?t.lineHeight:1.2*t.fontSize)/t.relativeSize*(m-1);const g={width:d*t.totalScale,height:w*t.totalScale};return Dm[n]=g,g},Fm.prototype.preload=async function(){const t=t=>fetch(t).then((t=>t.json()));try{const[i,r]=await Promise.all([(n=this.preloadSDFTextureUrl,new Promise(((t,e)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=()=>{t(i)},i.onerror=()=>{e()},i.src=n}))),t(this.preloadSDFConfigUrl)]),s=new e.TextureAtlas({context:this._scene.context,initialSize:new e.Cartesian2(r.dimensions.x,r.dimensions.y)}),o=[...r.font];o.unshift("");const a={},u={};Object.keys(r.indexHash).forEach((t=>{o[0]=t;const e=JSON.stringify(o);a[e]=r.indexHash[t],u[e]=Promise.resolve(r.indexHash[t])})),s._indexHash=a,s._idHash=u,s._root=r.root,s._textureCoordinates=r.textureCoordinates.map((t=>new e.BoundingRectangle(t[0],t[1],t[2],t[3])));const h=new e.Texture({context:this._scene.context,width:r.dimensions.x,height:r.dimensions.y,pixelFormat:s._pixelFormat});h.copyFrom({width:r.dimensions.x,height:r.dimensions.y,source:i}),s._texture=h,this._textureAtlas=s,this._billboardCollection._textureAtlas=s,Object.keys(r.glyphTextureCache).forEach((t=>{o[0]=t;const e=JSON.stringify(o),n={width:r.glyphTextureCache[t][0],height:r.glyphTextureCache[t][1],ascent:r.glyphTextureCache[t][2],descent:r.glyphTextureCache[t][3],minx:r.glyphTextureCache[t][4]},i=r.glyphTextureCache[t][5];this._glyphTextureCache[e]=new bm(this,i,n)})),this.preloaded=!0}catch(t){this._textureAtlas&&this._textureAtlas.destroy(),this._textureAtlas=void 0,this._billboardCollection._textureAtlas=void 0,this._glyphTextureCache={},this.preloaded=!0}var n};class jm{constructor(t=9){this.Ao=Math.max(4,t),this.Oo=Math.max(2,Math.ceil(.4*this.Ao)),this.clear()}all(){return this.Io(this.data,[])}search(t){let e=this.data;const n=[];if(!Jm(t,e))return n;const i=this.toBBox,r=[];for(;e;){for(let s=0;s<e.children.length;s++){const o=e.children[s],a=e.leaf?i(o):o;Jm(t,a)&&(e.leaf?n.push(o):Zm(t,a)?this.Io(o,n):r.push(o))}e=r.pop()}return n}collides(t){let e=this.data;if(!Jm(t,e))return!1;const n=[];for(;e;){for(let i=0;i<e.children.length;i++){const r=e.children[i],s=e.leaf?this.toBBox(r):r;if(Jm(t,s)){if(e.leaf||Zm(t,s))return!0;n.push(r)}}e=n.pop()}return!1}load(t){if(!t||!t.length)return this;if(t.length<this.Oo){for(let e=0;e<t.length;e++)this.insert(t[e]);return this}let e=this.To(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===e.height)this.zo(this.data,e);else{if(this.data.height<e.height){const t=this.data;this.data=e,e=t}this.Ro(e,this.data.height-e.height-1,!0)}else this.data=e;return this}insert(t){return t&&this.Ro(t,this.data.height-1),this}clear(){return this.data=ty([]),this}remove(t,e){if(!t)return this;let n=this.data;const i=this.toBBox(t),r=[],s=[];let o,a,u;for(;n||r.length;){if(n||(n=r.pop(),a=r[r.length-1],o=s.pop(),u=!0),n.leaf){const i=Bm(t,n.children,e);if(-1!==i)return n.children.splice(i,1),r.push(n),this.Fo(r),this}u||n.leaf||!Zm(n,i)?a?(o++,n=a.children[o],u=!1):n=null:(r.push(n),s.push(o),o=0,a=n,n=n.children[0])}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}Io(t,e){const n=[];for(;t;)t.leaf?e.push(...t.children):n.push(...t.children),t=n.pop();return e}To(t,e,n,i){const r=n-e+1;let s,o=this.Ao;if(r<=o)return s=ty(t.slice(e,n+1)),Lm(s,this.toBBox),s;i||(i=Math.ceil(Math.log(r)/Math.log(o)),o=Math.ceil(r/Math.pow(o,i-1))),s=ty([]),s.leaf=!1,s.height=i;const a=Math.ceil(r/o),u=a*Math.ceil(Math.sqrt(o));ey(t,e,n,u,this.compareMinX);for(let r=e;r<=n;r+=u){const e=Math.min(r+u-1,n);ey(t,r,e,a,this.compareMinY);for(let n=r;n<=e;n+=a){const r=Math.min(n+a-1,e);s.children.push(this.To(t,n,r,i-1))}}return Lm(s,this.toBBox),s}Po(t,e,n,i){for(;i.push(e),!e.leaf&&i.length-1!==n;){let n,i=1/0,r=1/0;for(let s=0;s<e.children.length;s++){const o=e.children[s],a=Ym(o),u=Xm(t,o)-a;u<r?(r=u,i=a<i?a:i,n=o):u===r&&a<i&&(i=a,n=o)}e=n||e.children[0]}return e}Ro(t,e,n){const i=n?t:this.toBBox(t),r=[],s=this.Po(i,this.data,e,r);for(s.children.push(t),Wm(s,i);e>=0&&r[e].children.length>this.Ao;)this.Do(r,e),e--;this.No(i,r,e)}Do(t,e){const n=t[e],i=n.children.length,r=this.Oo;this.Uo(n,r,i);const s=this.qo(n,r,i),o=ty(n.children.splice(s,n.children.length-s));o.height=n.height,o.leaf=n.leaf,Lm(n,this.toBBox),Lm(o,this.toBBox),e?t[e-1].children.push(o):this.zo(n,o)}zo(t,e){this.data=ty([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Lm(this.data,this.toBBox)}qo(t,e,n){let i,r=1/0,s=1/0;for(let o=e;o<=n-e;o++){const e=Hm(t,0,o,this.toBBox),a=Hm(t,o,n,this.toBBox),u=Qm(e,a),h=Ym(e)+Ym(a);u<r?(r=u,i=o,s=h<s?h:s):u===r&&h<s&&(s=h,i=o)}return i||n-e}Uo(t,e,n){const i=t.leaf?this.compareMinX:Vm,r=t.leaf?this.compareMinY:Gm;this.jo(t,e,n,i)<this.jo(t,e,n,r)&&t.children.sort(i)}jo(t,e,n,i){t.children.sort(i);const r=this.toBBox,s=Hm(t,0,e,r),o=Hm(t,n-e,n,r);let a=Km(s)+Km(o);for(let i=e;i<n-e;i++){const e=t.children[i];Wm(s,t.leaf?r(e):e),a+=Km(s)}for(let i=n-e-1;i>=e;i--){const e=t.children[i];Wm(o,t.leaf?r(e):e),a+=Km(o)}return a}No(t,e,n){for(let i=n;i>=0;i--)Wm(e[i],t)}Fo(t){for(let e,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(e=t[n-1].children,e.splice(e.indexOf(t[n]),1)):this.clear():Lm(t[n],this.toBBox)}}function Bm(t,e,n){if(!n)return e.indexOf(t);for(let i=0;i<e.length;i++)if(n(t,e[i]))return i;return-1}function Lm(t,e){Hm(t,0,t.children.length,e,t)}function Hm(t,e,n,i,r){r||(r=ty(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(let s=e;s<n;s++){const e=t.children[s];Wm(r,t.leaf?i(e):e)}return r}function Wm(t,e){return t.minX=Math.min(t.minX,e.minX),t.minY=Math.min(t.minY,e.minY),t.maxX=Math.max(t.maxX,e.maxX),t.maxY=Math.max(t.maxY,e.maxY),t}function Vm(t,e){return t.minX-e.minX}function Gm(t,e){return t.minY-e.minY}function Ym(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function Km(t){return t.maxX-t.minX+(t.maxY-t.minY)}function Xm(t,e){return(Math.max(e.maxX,t.maxX)-Math.min(e.minX,t.minX))*(Math.max(e.maxY,t.maxY)-Math.min(e.minY,t.minY))}function Qm(t,e){const n=Math.max(t.minX,e.minX),i=Math.max(t.minY,e.minY),r=Math.min(t.maxX,e.maxX),s=Math.min(t.maxY,e.maxY);return Math.max(0,r-n)*Math.max(0,s-i)}function Zm(t,e){return t.minX<=e.minX&&t.minY<=e.minY&&e.maxX<=t.maxX&&e.maxY<=t.maxY}function Jm(t,e){return e.minX<=t.maxX&&e.minY<=t.maxY&&e.maxX>=t.minX&&e.maxY>=t.minY}function ty(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ey(t,e,n,i,r){const s=[e,n];for(;s.length;){if((n=s.pop())-(e=s.pop())<=i)continue;const o=e+Math.ceil((n-e)/i/2)*i;Nm(t,o,e,n,r),s.push(e,o,o,n)}}var ny,iy,ry,sy,oy,ay,uy={},hy=function(){if(ny)return uy;ny=1;var t=uy.Poi={};t.read=function(e,n){return e.readFields(t.Jd,{minzoom:0,maxzoom:0,pos:[],poiid:"",indoorid:"",name:"",rank:0,name_zh:"",name_en:"",name_local:"",local_lang:"",character:[],character_en:[],name_spilt:[],altitude:0},n)},t.Jd=function(t,e,n){1===t?e.minzoom=n.readVarint():2===t?e.maxzoom=n.readVarint():3===t?n.readPackedVarint(e.pos,!0):4===t?e.poiid=n.readString():5===t?e.indoorid=n.readString():6===t?e.name=n.readString():7===t?e.rank=n.readVarint():8===t?e.name_zh=n.readString():9===t?e.name_en=n.readString():10===t?e.name_local=n.readString():11===t?e.local_lang=n.readString():12===t?n.readPackedVarint(e.character):13===t?n.readPackedVarint(e.character_en):14===t?n.readPackedVarint(e.name_spilt):15===t&&(e.altitude=n.readVarint(!0))},t.write=function(t,e){t.minzoom&&e.writeVarintField(1,t.minzoom),t.maxzoom&&e.writeVarintField(2,t.maxzoom),t.pos&&e.writePackedVarint(3,t.pos),t.poiid&&e.writeStringField(4,t.poiid),t.indoorid&&e.writeStringField(5,t.indoorid),t.name&&e.writeStringField(6,t.name),t.rank&&e.writeVarintField(7,t.rank),t.name_zh&&e.writeStringField(8,t.name_zh),t.name_en&&e.writeStringField(9,t.name_en),t.name_local&&e.writeStringField(10,t.name_local),t.local_lang&&e.writeStringField(11,t.local_lang),t.character&&e.writePackedVarint(12,t.character),t.character_en&&e.writePackedVarint(13,t.character_en),t.name_spilt&&e.writePackedVarint(14,t.name_spilt),t.altitude&&e.writeVarintField(15,t.altitude)};var e=uy.PoiSameStyle={};e.read=function(t,n){return t.readFields(e.Jd,{styleid:"",items:[],resolution:0},n)},e.Jd=function(e,n,i){1===e?n.styleid=i.readString():2===e?n.items.push(t.read(i,i.readVarint()+i.pos)):3===e&&(n.resolution=i.readVarint())},e.write=function(e,n){if(e.styleid&&n.writeStringField(1,e.styleid),e.items)for(var i=0;i<e.items.length;i++)n.writeMessage(2,t.write,e.items[i]);e.resolution&&n.writeVarintField(3,e.resolution)};var n=uy.PoiLayer={};return n.read=function(t,e){return t.readFields(n.Jd,{poilabel:[]},e)},n.Jd=function(t,n,i){1===t&&n.poilabel.push(e.read(i,i.readVarint()+i.pos))},n.write=function(t,n){if(t.poilabel)for(var i=0;i<t.poilabel.length;i++)n.writeMessage(1,e.write,t.poilabel[i])},uy}(),ly=function(){if(ry)return iy;ry=1;const t=2147483648;function e(t,e){const r=function(t,e){const r=i(t,e);let s=n(180),o=n(90);const a=s/(1<<r),u=o/(1<<r);return s=a>0?Math.floor(a+.5):Math.floor(a-.5),o=u>0?Math.floor(u+.5):Math.floor(u-.5),[s,o]}(t,e);return[2*r[0],2*r[1]]}function n(e){return Math.floor(e*t/180+.5)}function i(t,e){return 33-e-t}function r(e){return 180*e/t}function s(t,n){const i=e(t.z,n),r=i[0],s=i[1],o=1<<t.z;return[-r/2+t.x*r/o,s/2-(t.y+1)*s/o]}function o(t,e,n){const o=s(t,e),a=i(t.z,e);for(var u=[],h=0;h<n.length;h+=2){const t=n[h]+o[0];let e=t<<a;const i=n[h+1]+o[1]<<a;t>0&&e<0&&(e=2147483647);const s=r(e),l=r(i);u.push([s,l])}return u}function a(t){for(var e=0,n=2,i=t.length;n<i;n+=2)e+=((t[n]-t[n-2])**2+(t[n+1]-t[n-1])**2)**.5;return e}function u(t,e){for(var n=0,i=0,r=t.length;i<r;i+=2){var s=a(t.slice(i,i+4));if(!(s+n<e)){var o=(e-n)/s;return[Math.round(t[i]+o*(t[i+2]-t[i])),Math.round(t[i+1]+o*(t[i+3]-t[i+1])),i]}n+=s}return null}function h(t,e){e=e/180*Math.PI;let n=0,i=0,r=0;for(var s=2,o=t.length;s<o;s+=2){var a=t[s]-t[s-2],u=t[s+1]-t[s-1],h=(a**2+u**2)**.5;if(2==s)n=a,i=u,r=h;else{if(Math.acos((a*n+u*i)/h/r)>e)return!1;n=a,i=u,r=h}}return!0}return iy={getWorldSize:e,riseLevel:function(t,e,r,a){var u=function(t,e,r){var o=t.z;const a=s(t,e),u=i(o,e);for(var h=[],l=0;l<r.length;l+=1){var c=r[l][0],f=r[l][1];f<-90&&(f=-90),f>90&&(f=90),c<-180&&(c=-180),c>180&&(c=180);let t=n(c),e=n(f);const i=t/(1<<u),s=e/(1<<u);t=i>0?Math.floor(i+.5):Math.floor(i-.5),e=s>0?Math.floor(s+.5):Math.floor(s-.5),t-=a[0],e-=a[1],h.push(t,e)}return h}(a,r-1,o(e,r,t));return u},ptsLength:a,getSmoothSlice:function(t,e,n){for(var i=function(t,e){var n=[],i=[],r=a(t);if(r>=e){for(var s=Math.floor(r/e),o=1;o<=s;o+=1)n.push(u(t,e*o));var h=[],l=[],c=0,f=void 0;for(o=0;o<n.length;o+=1){f=n[o][2]+2;var d=t.slice(c,f);l=[n[o][0],n[o][1]];for(var p=h.concat(d).concat(l),v=2;v<p.length;v+=2)p[v]===p[v-2]&&p[v+1]===p[v-1]&&(p.splice(v,2),v-=2);i.push(p),h=l,c=f}return i}}(t,e)||[],r=0;r<i.length;r+=1)h(i[r],n)||(i.splice(r,1),r-=1);return i},tileInnerCoords2LngLat:o,tileInnerCoord2LngLat:function(t,e,n,o){const a=s(t,e),u=n+a[0],h=o+a[1],l=i(t.z,e);return n=u<<l,o=h<<l,u>0&&n<0&&(n=2147483647),[r(n),r(o)]}},iy}(),cy={},fy=function(){if(ay)return oy;ay=1,oy=e;var t=(sy||(sy=1,cy.read=function(t,e,n,i,r){var s,o,a=8*r-i-1,u=(1<<a)-1,h=u>>1,l=-7,c=n?r-1:0,f=n?-1:1,d=t[e+c];for(c+=f,s=d&(1<<-l)-1,d>>=-l,l+=a;l>0;s=256*s+t[e+c],c+=f,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=i;l>0;o=256*o+t[e+c],c+=f,l-=8);if(0===s)s=1-h;else{if(s===u)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,i),s-=h}return(d?-1:1)*o*Math.pow(2,s-i)},cy.write=function(t,e,n,i,r,s){var o,a,u,h=8*s-r-1,l=(1<<h)-1,c=l>>1,f=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=i?0:s-1,p=i?1:-1,v=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),(e+=o+c>=1?f/u:f*Math.pow(2,1-c))*u>=2&&(o++,u/=2),o+c>=l?(a=0,o=l):o+c>=1?(a=(e*u-1)*Math.pow(2,r),o+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,r),o=0));r>=8;t[n+d]=255&a,d+=p,a/=256,r-=8);for(o=o<<r|a,h+=r;h>0;t[n+d]=255&o,d+=p,o/=256,h-=8);t[n+d-p]|=128*v}),cy);function e(t){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(t)?t:new Uint8Array(t||0),this.pos=0,this.type=0,this.length=this.buf.length}e.Varint=0,e.Fixed64=1,e.Bytes=2,e.Fixed32=5;var n=4294967296,i=1/n,r="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function s(t){return t.type===e.Bytes?t.readVarint()+t.pos:t.pos+1}function o(t,e,n){return n?4294967296*e+(t>>>0):4294967296*(e>>>0)+(t>>>0)}function a(t,e,n){var i=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(7*Math.LN2));n.realloc(i);for(var r=n.pos-1;r>=t;r--)n.buf[r+i]=n.buf[r]}function u(t,e){for(var n=0;n<t.length;n++)e.writeVarint(t[n])}function h(t,e){for(var n=0;n<t.length;n++)e.writeSVarint(t[n])}function l(t,e){for(var n=0;n<t.length;n++)e.writeFloat(t[n])}function c(t,e){for(var n=0;n<t.length;n++)e.writeDouble(t[n])}function f(t,e){for(var n=0;n<t.length;n++)e.writeBoolean(t[n])}function d(t,e){for(var n=0;n<t.length;n++)e.writeFixed32(t[n])}function p(t,e){for(var n=0;n<t.length;n++)e.writeSFixed32(t[n])}function v(t,e){for(var n=0;n<t.length;n++)e.writeFixed64(t[n])}function m(t,e){for(var n=0;n<t.length;n++)e.writeSFixed64(t[n])}function y(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16)+16777216*t[e+3]}function w(t,e,n){t[n]=e,t[n+1]=e>>>8,t[n+2]=e>>>16,t[n+3]=e>>>24}function g(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16)+(t[e+3]<<24)}return e.prototype={destroy:function(){this.buf=null},readFields:function(t,e,n){for(n=n||this.length;this.pos<n;){var i=this.readVarint(),r=i>>3,s=this.pos;this.type=7&i,t(r,e,this),this.pos===s&&this.skip(i)}return e},readMessage:function(t,e){return this.readFields(t,e,this.readVarint()+this.pos)},readFixed32:function(){var t=y(this.buf,this.pos);return this.pos+=4,t},readSFixed32:function(){var t=g(this.buf,this.pos);return this.pos+=4,t},readFixed64:function(){var t=y(this.buf,this.pos)+y(this.buf,this.pos+4)*n;return this.pos+=8,t},readSFixed64:function(){var t=y(this.buf,this.pos)+g(this.buf,this.pos+4)*n;return this.pos+=8,t},readFloat:function(){var e=t.read(this.buf,this.pos,!0,23,4);return this.pos+=4,e},readDouble:function(){var e=t.read(this.buf,this.pos,!0,52,8);return this.pos+=8,e},readVarint:function(t){var e,n,i=this.buf;return e=127&(n=i[this.pos++]),n<128?e:(e|=(127&(n=i[this.pos++]))<<7,n<128?e:(e|=(127&(n=i[this.pos++]))<<14,n<128?e:(e|=(127&(n=i[this.pos++]))<<21,n<128?e:function(t,e,n){var i,r,s=n.buf;if(i=(112&(r=s[n.pos++]))>>4,r<128)return o(t,i,e);if(i|=(127&(r=s[n.pos++]))<<3,r<128)return o(t,i,e);if(i|=(127&(r=s[n.pos++]))<<10,r<128)return o(t,i,e);if(i|=(127&(r=s[n.pos++]))<<17,r<128)return o(t,i,e);if(i|=(127&(r=s[n.pos++]))<<24,r<128)return o(t,i,e);if(i|=(1&(r=s[n.pos++]))<<31,r<128)return o(t,i,e);throw new Error("Expected varint not more than 10 bytes")}(e|=(15&(n=i[this.pos]))<<28,t,this))))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var t=this.readVarint();return t%2==1?(t+1)/-2:t/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var t=this.readVarint()+this.pos,e=this.pos;return this.pos=t,t-e>=12&&r?function(t,e,n){return r.decode(t.subarray(e,n))}(this.buf,e,t):function(t,e,n){for(var i="",r=e;r<n;){var s,o,a,u=t[r],h=null,l=u>239?4:u>223?3:u>191?2:1;if(r+l>n)break;1===l?u<128&&(h=u):2===l?128==(192&(s=t[r+1]))&&(h=(31&u)<<6|63&s)<=127&&(h=null):3===l?(s=t[r+1],o=t[r+2],128==(192&s)&&128==(192&o)&&((h=(15&u)<<12|(63&s)<<6|63&o)<=2047||h>=55296&&h<=57343)&&(h=null)):4===l&&(s=t[r+1],o=t[r+2],a=t[r+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&((h=(15&u)<<18|(63&s)<<12|(63&o)<<6|63&a)<=65535||h>=1114112)&&(h=null)),null===h?(h=65533,l=1):h>65535&&(h-=65536,i+=String.fromCharCode(h>>>10&1023|55296),h=56320|1023&h),i+=String.fromCharCode(h),r+=l}return i}(this.buf,e,t)},readBytes:function(){var t=this.readVarint()+this.pos,e=this.buf.subarray(this.pos,t);return this.pos=t,e},readPackedVarint:function(t,n){if(this.type!==e.Bytes)return t.push(this.readVarint(n));var i=s(this);for(t=t||[];this.pos<i;)t.push(this.readVarint(n));return t},readPackedSVarint:function(t){if(this.type!==e.Bytes)return t.push(this.readSVarint());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readSVarint());return t},readPackedBoolean:function(t){if(this.type!==e.Bytes)return t.push(this.readBoolean());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readBoolean());return t},readPackedFloat:function(t){if(this.type!==e.Bytes)return t.push(this.readFloat());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readFloat());return t},readPackedDouble:function(t){if(this.type!==e.Bytes)return t.push(this.readDouble());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readDouble());return t},readPackedFixed32:function(t){if(this.type!==e.Bytes)return t.push(this.readFixed32());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readFixed32());return t},readPackedSFixed32:function(t){if(this.type!==e.Bytes)return t.push(this.readSFixed32());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readSFixed32());return t},readPackedFixed64:function(t){if(this.type!==e.Bytes)return t.push(this.readFixed64());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readFixed64());return t},readPackedSFixed64:function(t){if(this.type!==e.Bytes)return t.push(this.readSFixed64());var n=s(this);for(t=t||[];this.pos<n;)t.push(this.readSFixed64());return t},skip:function(t){var n=7&t;if(n===e.Varint)for(;this.buf[this.pos++]>127;);else if(n===e.Bytes)this.pos=this.readVarint()+this.pos;else if(n===e.Fixed32)this.pos+=4;else{if(n!==e.Fixed64)throw new Error("Unimplemented type: "+n);this.pos+=8}},writeTag:function(t,e){this.writeVarint(t<<3|e)},realloc:function(t){for(var e=this.length||16;e<this.pos+t;)e*=2;if(e!==this.length){var n=new Uint8Array(e);n.set(this.buf),this.buf=n,this.length=e}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(t){this.realloc(4),w(this.buf,t,this.pos),this.pos+=4},writeSFixed32:function(t){this.realloc(4),w(this.buf,t,this.pos),this.pos+=4},writeFixed64:function(t){this.realloc(8),w(this.buf,-1&t,this.pos),w(this.buf,Math.floor(t*i),this.pos+4),this.pos+=8},writeSFixed64:function(t){this.realloc(8),w(this.buf,-1&t,this.pos),w(this.buf,Math.floor(t*i),this.pos+4),this.pos+=8},writeVarint:function(t){(t=+t||0)>268435455||t<0?function(t,e){var n,i;if(t>=0?(n=t%4294967296|0,i=t/4294967296|0):(i=~(-t/4294967296),4294967295^(n=~(-t%4294967296))?n=n+1|0:(n=0,i=i+1|0)),t>=0x10000000000000000||t<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");e.realloc(10),function(t,e,n){n.buf[n.pos++]=127&t|128,t>>>=7,n.buf[n.pos++]=127&t|128,t>>>=7,n.buf[n.pos++]=127&t|128,t>>>=7,n.buf[n.pos++]=127&t|128,t>>>=7,n.buf[n.pos]=127&t}(n,0,e),function(t,e){var n=(7&t)<<4;e.buf[e.pos++]|=n|((t>>>=3)?128:0),t&&(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),t&&(e.buf[e.pos++]=127&t)))))}(i,e)}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))))},writeSVarint:function(t){this.writeVarint(t<0?2*-t-1:2*t)},writeBoolean:function(t){this.writeVarint(Boolean(t))},writeString:function(t){t=String(t),this.realloc(4*t.length),this.pos++;var e=this.pos;this.pos=function(t,e,n){for(var i,r,s=0;s<e.length;s++){if((i=e.charCodeAt(s))>55295&&i<57344){if(!r){i>56319||s+1===e.length?(t[n++]=239,t[n++]=191,t[n++]=189):r=i;continue}if(i<56320){t[n++]=239,t[n++]=191,t[n++]=189,r=i;continue}i=r-55296<<10|i-56320|65536,r=null}else r&&(t[n++]=239,t[n++]=191,t[n++]=189,r=null);i<128?t[n++]=i:(i<2048?t[n++]=i>>6|192:(i<65536?t[n++]=i>>12|224:(t[n++]=i>>18|240,t[n++]=i>>12&63|128),t[n++]=i>>6&63|128),t[n++]=63&i|128)}return n}(this.buf,t,this.pos);var n=this.pos-e;n>=128&&a(e,n,this),this.pos=e-1,this.writeVarint(n),this.pos+=n},writeFloat:function(e){this.realloc(4),t.write(this.buf,e,this.pos,!0,23,4),this.pos+=4},writeDouble:function(e){this.realloc(8),t.write(this.buf,e,this.pos,!0,52,8),this.pos+=8},writeBytes:function(t){var e=t.length;this.writeVarint(e),this.realloc(e);for(var n=0;n<e;n++)this.buf[this.pos++]=t[n]},writeRawMessage:function(t,e){this.pos++;var n=this.pos;t(e,this);var i=this.pos-n;i>=128&&a(n,i,this),this.pos=n-1,this.writeVarint(i),this.pos+=i},writeMessage:function(t,n,i){this.writeTag(t,e.Bytes),this.writeRawMessage(n,i)},writePackedVarint:function(t,e){e.length&&this.writeMessage(t,u,e)},writePackedSVarint:function(t,e){e.length&&this.writeMessage(t,h,e)},writePackedBoolean:function(t,e){e.length&&this.writeMessage(t,f,e)},writePackedFloat:function(t,e){e.length&&this.writeMessage(t,l,e)},writePackedDouble:function(t,e){e.length&&this.writeMessage(t,c,e)},writePackedFixed32:function(t,e){e.length&&this.writeMessage(t,d,e)},writePackedSFixed32:function(t,e){e.length&&this.writeMessage(t,p,e)},writePackedFixed64:function(t,e){e.length&&this.writeMessage(t,v,e)},writePackedSFixed64:function(t,e){e.length&&this.writeMessage(t,m,e)},writeBytesField:function(t,n){this.writeTag(t,e.Bytes),this.writeBytes(n)},writeFixed32Field:function(t,n){this.writeTag(t,e.Fixed32),this.writeFixed32(n)},writeSFixed32Field:function(t,n){this.writeTag(t,e.Fixed32),this.writeSFixed32(n)},writeFixed64Field:function(t,n){this.writeTag(t,e.Fixed64),this.writeFixed64(n)},writeSFixed64Field:function(t,n){this.writeTag(t,e.Fixed64),this.writeSFixed64(n)},writeVarintField:function(t,n){this.writeTag(t,e.Varint),this.writeVarint(n)},writeSVarintField:function(t,n){this.writeTag(t,e.Varint),this.writeSVarint(n)},writeStringField:function(t,n){this.writeTag(t,e.Bytes),this.writeString(n)},writeFloatField:function(t,n){this.writeTag(t,e.Fixed32),this.writeFloat(n)},writeDoubleField:function(t,n){this.writeTag(t,e.Fixed64),this.writeDouble(n)},writeBooleanField:function(t,e){this.writeVarintField(t,Boolean(e))}},oy}(),dy=Bf(fy);class py{fo;do="PoiDataSource";po=!1;vo;mo;yo;_show=!0;wo;_scene;_id=0;Ve;tp=1;ep={};np;Qd=0;ip={};tilesetUrl;tileset;SSE;constructor(t){this.vo=new r.Event,this.mo=new r.Event,this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this._scene=t.scene,this.tilesetUrl=t.tileset,this.np=this.tilesetUrl.substring(0,this.tilesetUrl.lastIndexOf("/")),this.SSE=t.SSE,this.Ve=new Gc({Hi:30,Bi:this.onDrop})}rp=!1;onDrop=(t,e)=>{delete this.ep[t],this.rp=!0};async loadTileset(){try{const t=await fetch(this.tilesetUrl),e=await t.json();this.tileset=e}catch(t){}}getViewFrustum(){const t=this._scene.camera,e=this.tileset.metadata.enuCenterGCJ02,n=t.frustum.computeCullingVolume(t.positionWC,t.directionWC,t.upWC).planes,i=r.Cartesian3.fromDegrees(...e),s=r.Transforms.eastNorthUpToFixedFrame(i),o=r.Matrix4.inverse(s,new r.Matrix4),a=n.map((t=>{const e=new r.Cartesian3(t.x,t.y,t.z),n=t.w,i=r.Matrix4.multiplyByPointAsVector(o,e,new r.Cartesian3),s=r.Cartesian3.multiplyByScalar(e,-n,new r.Cartesian3),a=r.Matrix4.multiplyByPoint(o,s,new r.Cartesian3),u=-r.Cartesian3.dot(i,a);return new r.Cartesian4(i.x,i.y,i.z,u)}));return new r.CullingVolume(a)}getTileKey(t){return t.coord.join("-")}computeTilesToRender(){if(!this.tileset)return{};const t=this._scene.camera,e=t.frustum.sseDenominator,n=this._scene.context.drawingBufferHeight,{enuCenterGCJ02:i}=this.tileset.metadata,s=this.getViewFrustum(),o=this.tileset.root,a=Fc(t.position,i),u=t=>{const e=new r.Cartesian3(t[0],t[1],t[2]),n=new r.Cartesian3(t[0]-t[3],t[1]-t[7],t[2]-t[11]),i=new r.Cartesian3(t[0]+t[3],t[1]-t[7],t[2]-t[11]),s=new r.Cartesian3(t[0]-t[3],t[1]+t[7],t[2]-t[11]),o=new r.Cartesian3(t[0]+t[3],t[1]+t[7],t[2]-t[11]);return Math.min(r.Cartesian3.distance(a,e),r.Cartesian3.distance(a,n),r.Cartesian3.distance(a,i),r.Cartesian3.distance(a,s),r.Cartesian3.distance(a,o))},h={},l={},c=[o];for(;c.length;){let t=c.length;for(let i=0;i<t;i++){const t=c.shift(),i=t.boundingVolume.box,a=new r.Cartesian3(i[0]-i[3],i[1]-i[7],i[2]-i[11]),f=new r.Cartesian3(i[0]+i[3],i[1]+i[7],i[2]+i[11]),d=new r.AxisAlignedBoundingBox(a,f);if(s.computeVisibility(d)!==r.Intersect.OUTSIDE){const r=u(i),s=t.geometricError*n/(r*e),a=t.children.length>0;if(t===o||s>this.SSE&&a){let e;if(t.coord){const n=t.content.uri,i=n.startsWith("http")?n:this.np+"/"+n,r=this.getTileKey(t);h[r]=i,l[r]&&delete h[l[r]],e=r}for(let n=0;n<t.children.length;n++)c.push(t.children[n]),e&&(l[this.getTileKey(t.children[n])]=e)}else if(t.coord){const e=t.content.uri,n=e.startsWith("http")?e:this.np+"/"+e,i=this.getTileKey(t);h[i]=n,l[i]&&delete h[l[i]]}}}}return h}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}update(){const t=Date.now();if(t-this.Qd<1e3)return!0;if(this.Qd=t,!this.tileset&&2!==this.tp)return this.loadTileset(),!0;const e=this.computeTilesToRender(),n=this.tileChanged(this.ip,e);if(this.ip=e,!n&&!this.rp)return!0;this.rp=!1;const i=Object.keys(e);for(let t=0;t<i.length;t++){const n=i[t];this.Ve.ar(n)||2===this.ep[n]||this.fetchTile(n,e[n])}return!0}tileChanged(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!0;for(let t=0;t<n.length;t++)if(!e[n[t]])return!0;return!1}async fetchTile(t,e){try{this.ep[t]=2;const n=await fetch(e),i=await n.arrayBuffer(),s=new dy(i),o=hy.PoiLayer.read(s),a=t.split("-").map((t=>parseInt(t,10))),u={z:a[0],x:a[1],y:a[2]};let h=[];for(let t=0;t<o.poilabel.length;t++){const e=o.poilabel[t],n=[];e.items.forEach((t=>{n.push(t.pos[0],t.pos[1])}));const i=ly.tileInnerCoords2LngLat(u,e.resolution,n);e.items.forEach(((t,n)=>{h.push({position:r.Cartesian3.fromDegrees(i[n][0],i[n][1],t.altitude),name:t.name,rank:t.rank,poiid:t.poiid,minzoom:t.minzoom,maxzoom:t.maxzoom,id:++this._id,coord:[u.z,u.x,u.y],styleId:e.styleid,type:"poi"})}))}this.Ve.rr(t,h),this.ep[t]=3,this.changedEvent.raiseEvent(t)}catch(e){this.ep[t]=4}}getData(){const t=this.ip,e=Object.keys(t);let n=[];for(let t=0;t<e.length;t++){const i=this.Ve.nr(e[t],!1);i&&(n=n.concat(i))}return n.sort(((t,e)=>t.rank!=e.rank?t.rank<e.rank:t.coord[0]!=e.coord[0]?t.coord[0]>e.coord[0]:t.id<e.id)),n}}var vy,my={},yy=function(){if(vy)return my;vy=1;var t=my.Road={};t.read=function(e,n){return e.readFields(t.Jd,{minzoom:0,maxzoom:0,path:[],shield:"",shieldType:0,name:"",rank:0,name_zh:"",name_en:"",name_local:"",local_lang:"",character:[],id:0},n)},t.Jd=function(t,e,n){1===t?e.minzoom=n.readVarint():2===t?e.maxzoom=n.readVarint():3===t?n.readPackedVarint(e.path,!0):4===t?e.shield=n.readString():5===t?e.shieldType=n.readVarint():6===t?e.name=n.readString():7===t?e.rank=n.readVarint():8===t?e.name_zh=n.readString():9===t?e.name_en=n.readString():10===t?e.name_local=n.readString():11===t?e.local_lang=n.readString():12===t?n.readPackedVarint(e.character):13===t&&(e.id=n.readVarint())},t.write=function(t,e){t.minzoom&&e.writeVarintField(1,t.minzoom),t.maxzoom&&e.writeVarintField(2,t.maxzoom),t.path&&e.writePackedVarint(3,t.path),t.shield&&e.writeStringField(4,t.shield),t.shieldType&&e.writeVarintField(5,t.shieldType),t.name&&e.writeStringField(6,t.name),t.rank&&e.writeVarintField(7,t.rank),t.name_zh&&e.writeStringField(8,t.name_zh),t.name_en&&e.writeStringField(9,t.name_en),t.name_local&&e.writeStringField(10,t.name_local),t.local_lang&&e.writeStringField(11,t.local_lang),t.character&&e.writePackedVarint(12,t.character),t.id&&e.writeVarintField(13,t.id)};var e=my.RoadSameStyle={};e.read=function(t,n){return t.readFields(e.Jd,{styleid:"",items:[],resolution:0},n)},e.Jd=function(e,n,i){1===e?n.styleid=i.readString():2===e?n.items.push(t.read(i,i.readVarint()+i.pos)):3===e&&(n.resolution=i.readVarint())},e.write=function(e,n){if(e.styleid&&n.writeStringField(1,e.styleid),e.items)for(var i=0;i<e.items.length;i++)n.writeMessage(2,t.write,e.items[i]);e.resolution&&n.writeVarintField(3,e.resolution)};var n=my.RoadLayer={};return n.read=function(t,e){return t.readFields(n.Jd,{road:[]},e)},n.Jd=function(t,n,i){1===t&&n.road.push(e.read(i,i.readVarint()+i.pos))},n.write=function(t,n){if(t.road)for(var i=0;i<t.road.length;i++)n.writeMessage(1,e.write,t.road[i])},my}();class wy{fo;do="RoadDataSource";po=!1;vo;mo;yo;_show=!0;wo;_scene;_id=0;Ve;tp=1;ep={};np;Qd=0;ip={};tilesetUrl;tileset;SSE;constructor(t){this.vo=new r.Event,this.mo=new r.Event,this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this._scene=t.scene,this.tilesetUrl=t.tileset,this.np=this.tilesetUrl.substring(0,this.tilesetUrl.lastIndexOf("/")),this.SSE=t.SSE,this.Ve=new Gc({Hi:30,Bi:this.onDrop})}rp=!1;onDrop=(t,e)=>{delete this.ep[t],this.rp=!0};async loadTileset(){try{const t=await fetch(this.tilesetUrl),e=await t.json();this.tileset=e}catch(t){}}getViewFrustum(){const t=this._scene.camera,e=this.tileset.metadata.enuCenterGCJ02,n=t.frustum.computeCullingVolume(t.positionWC,t.directionWC,t.upWC).planes,i=r.Cartesian3.fromDegrees(...e),s=r.Transforms.eastNorthUpToFixedFrame(i),o=r.Matrix4.inverse(s,new r.Matrix4),a=n.map((t=>{const e=new r.Cartesian3(t.x,t.y,t.z),n=t.w,i=r.Matrix4.multiplyByPointAsVector(o,e,new r.Cartesian3),s=r.Cartesian3.multiplyByScalar(e,-n,new r.Cartesian3),a=r.Matrix4.multiplyByPoint(o,s,new r.Cartesian3),u=-r.Cartesian3.dot(i,a);return new r.Cartesian4(i.x,i.y,i.z,u)}));return new r.CullingVolume(a)}getTileKey(t){return t.coord.join("-")}computeTilesToRender(){if(!this.tileset)return{};const t=this._scene.camera,e=t.frustum.sseDenominator,n=this._scene.context.drawingBufferHeight,{enuCenterGCJ02:i}=this.tileset.metadata,s=this.getViewFrustum(),o=this.tileset.root,a=Fc(t.position,i),u=t=>{const e=new r.Cartesian3(t[0],t[1],t[2]),n=new r.Cartesian3(t[0]-t[3],t[1]-t[7],t[2]-t[11]),i=new r.Cartesian3(t[0]+t[3],t[1]-t[7],t[2]-t[11]),s=new r.Cartesian3(t[0]-t[3],t[1]+t[7],t[2]-t[11]),o=new r.Cartesian3(t[0]+t[3],t[1]+t[7],t[2]-t[11]);return Math.min(r.Cartesian3.distance(a,e),r.Cartesian3.distance(a,n),r.Cartesian3.distance(a,i),r.Cartesian3.distance(a,s),r.Cartesian3.distance(a,o))},h={},l={},c=[o];for(;c.length;){let t=c.length;for(let i=0;i<t;i++){const t=c.shift(),i=t.boundingVolume.box,a=new r.Cartesian3(i[0]-i[3],i[1]-i[7],i[2]-i[11]),f=new r.Cartesian3(i[0]+i[3],i[1]+i[7],i[2]+i[11]),d=new r.AxisAlignedBoundingBox(a,f);if(s.computeVisibility(d)!==r.Intersect.OUTSIDE){const r=u(i),s=t.geometricError*n/(r*e),a=t.children.length>0;if(t===o||s>this.SSE&&a){let e;if(t.coord){const n=t.content.uri,i=n.startsWith("http")?n:this.np+"/"+n,r=this.getTileKey(t);h[r]=i,l[r]&&delete l[r],e=r}for(let n=0;n<t.children.length;n++)c.push(t.children[n]),e&&(l[this.getTileKey(t.children[n])]=e)}else if(t.coord){const e=t.content.uri,n=e.startsWith("http")?e:this.np+"/"+e,i=this.getTileKey(t);h[i]=n,l[i]&&delete l[i]}}}}return h}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}update(){const t=Date.now();if(t-this.Qd<1e3)return!0;if(this.Qd=t,!this.tileset&&2!==this.tp)return this.loadTileset(),!0;const e=this.computeTilesToRender(),n=this.tileChanged(this.ip,e);if(this.ip=e,!n&&!this.rp)return!0;this.rp=!1;const i=Object.keys(e);for(let t=0;t<i.length;t++){const n=i[t];this.Ve.ar(n)||2===this.ep[n]||this.fetchTile(n,e[n])}return!0}tileChanged(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!0;for(let t=0;t<n.length;t++)if(!e[n[t]])return!0;return!1}async fetchTile(t,n){try{this.ep[t]=2;const i=await fetch(n),r=await i.arrayBuffer(),s=new dy(r),o=yy.RoadLayer.read(s),a=t.split("-").map((t=>parseInt(t,10))),u={z:a[0],x:a[1],y:a[2]};let h=[];for(let t=0;t<o.road.length;t++){const n=o.road[t],{resolution:i,styleid:r,items:s}=n;if(20015!==parseInt(r.split(":")[0],10))for(let t=0;t<s.length;t++){const n=s[t];if(!(n.path.length<6))if(n.shield){const{rank:t,minzoom:r,maxzoom:s,shield:o,shieldType:a,path:l}=n,c=[l[0],l[1],l[2]],f=ly.tileInnerCoords2LngLat(u,i,[c[0],c[1]])[0],d={coord:u,name:o,styleId:`40001:${a}`,rank:t,minzoom:r,maxzoom:s,position:e.Cartesian3.fromDegrees(f[0],f[1],c[2]),id:++this._id,type:"road",subType:"guideboard"};h.push(d)}else if(n.name){const{rank:t,minzoom:s,maxzoom:o,path:a,name:l}=n,c=a.length/3,f=[];for(let t=0;t<c;t+=1)f.push(a[3*t],a[3*t+1]);const d=ly.tileInnerCoords2LngLat(u,i,f);for(let t=0;t<c;t+=1)d[t].push(a[3*t+2]);let p=d[0],v=d[c-1];const m=e.Cartesian3.fromDegrees(p[0],p[1],p[2]),y=e.Cartesian3.fromDegrees(v[0],v[1],v[2]);let w,g,b;if(e.Cartesian3.distance(m,y)>100){if(c>2){let t,n,i=0,r=-1/0;for(let s=0;s<d.length-1;s++){const o=Math.max(d[s][2],d[s+1][2]);t=e.Cartesian3.fromDegrees(d[s][0],d[s][1],o),n=e.Cartesian3.fromDegrees(d[s+1][0],d[s+1][1],o);const a=e.Cartesian3.distance(t,n);a>r&&(r=a,i=s,w=t,g=n)}b=e.Cartesian3.midpoint(w,g,new e.Cartesian3)}else{const t=Math.max(p[2],v[2]);w=e.Cartesian3.fromDegrees(p[0],p[1],t),g=e.Cartesian3.fromDegrees(v[0],v[1],t),b=e.Cartesian3.midpoint(w,g,new e.Cartesian3)}const n=e.Cartesian3.subtract(g,w,new e.Cartesian3),i=e.Cartesian3.magnitude(n);let a;const f=1e4;a=i<f?new e.Cartesian3(w.x+f/i*n.x,w.y+f/i*n.y,w.z+f/i*n.z):g;const m={coord:u,name:l,styleId:r,rank:t,minzoom:s,maxzoom:o,position:b,start:w,end:a,id:++this._id,type:"road",subType:"roadname",path:d};h.push(m)}}}}this.Ve.rr(t,h),this.ep[t]=3,this.changedEvent.raiseEvent(t)}catch(e){this.ep[t]=4}}getData(){const t=this.ip,e=Object.keys(t);let n=[];for(let t=0;t<e.length;t++){const i=this.Ve.nr(e[t],!1);i&&(n=n.concat(i))}return n.sort(((t,e)=>t.rank!=e.rank?t.rank<e.rank:t.coord[0]!=e.coord[0]?t.coord[0]>e.coord[0]:t.id<e.id)),n}}var gy,by,_y,xy=function(){if(by)return gy;by=1;var t=/^\s+|\s+$/g,e=/^[-+]0x[0-9a-f]+$/i,n=/^0b[01]+$/i,i=/^0o[0-7]+$/i,r=parseInt,s="object"==typeof jf&&jf&&jf.Object===Object&&jf,o="object"==typeof self&&self&&self.Object===Object&&self,a=s||o||Function("","return this")(),u={}.toString,h=Math.max,l=Math.min,c=function(){return a.Date.now()};function f(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function d(s){if("number"==typeof s)return s;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&"[object Symbol]"==u.call(t)}(s))return NaN;if(f(s)){var o="function"==typeof s.valueOf?s.valueOf():s;s=f(o)?o+"":o}if("string"!=typeof s)return 0===s?s:+s;s=s.replace(t,"");var a=n.test(s);return a||i.test(s)?r(s.slice(2),a?2:8):e.test(s)?NaN:+s}return gy=function(t,e,n){var i,r,s,o,a,u,p=0,v=!1,m=!1,y=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function w(e){var n=i,s=r;return i=r=void 0,p=e,o=t.apply(s,n)}function g(t){var n=t-u;return void 0===u||n>=e||n<0||m&&t-p>=s}function b(){var t=c();if(g(t))return _(t);a=setTimeout(b,function(t){var n=e-(t-u);return m?l(n,s-(t-p)):n}(t))}function _(t){return a=void 0,y&&i?w(t):(i=r=void 0,o)}function x(){var t=c(),n=g(t);if(i=arguments,r=this,u=t,n){if(void 0===a)return function(t){return p=t,a=setTimeout(b,e),v?w(t):o}(u);if(m)return a=setTimeout(b,e),w(u)}return void 0===a&&(a=setTimeout(b,e)),o}return e=d(e)||0,f(n)&&(v=!!n.leading,s=(m="maxWait"in n)?h(d(n.maxWait)||0,e):s,y="trailing"in n?!!n.trailing:y),x.cancel=function(){void 0!==a&&clearTimeout(a),p=0,i=u=r=a=void 0},x.flush=function(){return void 0===a?o:_(c())},x},gy}(),ky=Bf(xy),$y={exports:{}},Sy=(_y||(_y=1,function(t){!function(){function e(t,e){document.addEventListener?t.addEventListener("scroll",e,!1):t.attachEvent("scroll",e)}function n(t){this.g=document.createElement("div"),this.g.setAttribute("aria-hidden","true"),this.g.appendChild(document.createTextNode(t)),this.h=document.createElement("span"),this.i=document.createElement("span"),this.m=document.createElement("span"),this.j=document.createElement("span"),this.l=-1,this.h.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.i.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.j.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.m.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;",this.h.appendChild(this.m),this.i.appendChild(this.j),this.g.appendChild(this.h),this.g.appendChild(this.i)}function i(t,e){t.g.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+e+";"}function r(t){var e=t.g.offsetWidth,n=e+100;return t.j.style.width=n+"px",t.i.scrollLeft=n,t.h.scrollLeft=t.h.scrollWidth+100,t.l!==e&&(t.l=e,!0)}function s(t,n){function i(){var t=s;r(t)&&null!==t.g.parentNode&&n(t.l)}var s=t;e(t.h,i),e(t.i,i),r(t)}function o(t,e,n){e=e||{},n=n||window,this.family=t,this.style=e.style||"normal",this.weight=e.weight||"normal",this.stretch=e.stretch||"normal",this.context=n}var a=null,u=null,h=null,l=null;function c(t){return null===l&&(l=!!t.document.fonts),l}function f(t,e){var n=t.style,i=t.weight;if(null===h){var r=document.createElement("div");try{r.style.font="condensed 100px sans-serif"}catch(t){}h=""!==r.style.font}return[n,i,h?t.stretch:"","100px",e].join(" ")}o.prototype.load=function(t,e){var r=this,o=t||"BESbswy",h=0,l=e||3e3,d=(new Date).getTime();return new Promise((function(t,e){if(c(r.context)&&!function(t){return null===u&&(c(t)&&/Apple/.test(window.navigator.vendor)?(t=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent),u=!!t&&603>parseInt(t[1],10)):u=!1),u}(r.context)){var p=new Promise((function(t,e){!function n(){(new Date).getTime()-d>=l?e(Error(l+"ms timeout exceeded")):r.context.document.fonts.load(f(r,'"'+r.family+'"'),o).then((function(e){1<=e.length?t():setTimeout(n,25)}),e)}()})),v=new Promise((function(t,e){h=setTimeout((function(){e(Error(l+"ms timeout exceeded"))}),l)}));Promise.race([v,p]).then((function(){clearTimeout(h),t(r)}),e)}else!function(t){document.body?t():document.addEventListener?document.addEventListener("DOMContentLoaded",(function e(){document.removeEventListener("DOMContentLoaded",e),t()})):document.attachEvent("onreadystatechange",(function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),t())}))}((function(){function u(){var e;(e=-1!=m&&-1!=y||-1!=m&&-1!=w||-1!=y&&-1!=w)&&((e=m!=y&&m!=w&&y!=w)||(null===a&&(e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),a=!!e&&(536>parseInt(e[1],10)||536===parseInt(e[1],10)&&11>=parseInt(e[2],10))),e=a&&(m==g&&y==g&&w==g||m==b&&y==b&&w==b||m==_&&y==_&&w==_)),e=!e),e&&(null!==x.parentNode&&x.parentNode.removeChild(x),clearTimeout(h),t(r))}var c=new n(o),p=new n(o),v=new n(o),m=-1,y=-1,w=-1,g=-1,b=-1,_=-1,x=document.createElement("div");x.dir="ltr",i(c,f(r,"sans-serif")),i(p,f(r,"serif")),i(v,f(r,"monospace")),x.appendChild(c.g),x.appendChild(p.g),x.appendChild(v.g),r.context.document.body.appendChild(x),g=c.g.offsetWidth,b=p.g.offsetWidth,_=v.g.offsetWidth,function t(){if((new Date).getTime()-d>=l)null!==x.parentNode&&x.parentNode.removeChild(x),e(Error(l+"ms timeout exceeded"));else{var n=r.context.document.hidden;!0!==n&&void 0!==n||(m=c.g.offsetWidth,y=p.g.offsetWidth,w=v.g.offsetWidth,u()),h=setTimeout(t,50)}}(),s(c,(function(t){m=t,u()})),i(c,f(r,'"'+r.family+'",sans-serif')),s(p,(function(t){y=t,u()})),i(p,f(r,'"'+r.family+'",serif')),s(v,(function(t){w=t,u()})),i(v,f(r,'"'+r.family+'",monospace'))}))}))},t.exports=o}()}($y)),$y.exports),My=Bf(Sy),Ey={sp:"v0.5",op:"https://a.amap.com/yunjing/static/cesium/"};class Cy{Hn;_scene;_labels;ap;hp;lp;cp={};fp={};disableDepthTestDistance=2e3;fontSize="20";fontFamily="AlibabaPuHuiTi";styleUrl=Ey.op+"assets/style.json";styles=null;fontStyle="normal";fontWeight="800";iconSize=24;iconTextSpacing=4;lineHeight=void 0;dp;tileset;pp=200;me=!1;vp=[];mp=12e4;yp=!1;wp=1e3;collisionBuffer=new r.Cartesian2(20,20);gp=0;set SSE(t){this.pp=t,this.poiDataSource.SSE=this.pp,this.roadDataSource.SSE=this.pp}get SSE(){return this.pp}poiDataSource;roadDataSource;_dirty=!0;bp=new r.Cartesian3(0,0,0);_p=new r.Cartesian3(0,0,0);preloadSDF=!0;preloadSDFTextureUrl=Ey.op+"assets/AlibabaPuHuiTi-2-55-Regular/SDF.png";preloadSDFConfigUrl=Ey.op+"assets/AlibabaPuHuiTi-2-55-Regular/SDF.json";constructor(t){this.dp=new jm,this.preloadSDF=!1!==t.preloadSDF,this._labels=new Fm({blendOption:e.BlendOption.TRANSLUCENT,scene:t.viewer.scene,preloadSDF:this.preloadSDF,preloadSDFTextureUrl:this.preloadSDFTextureUrl,preloadSDFConfigUrl:this.preloadSDFConfigUrl}),this.hp=new Fm({blendOption:e.BlendOption.TRANSLUCENT,scene:t.viewer.scene,reuseBillboards:!1}),this.ap=new jv({blendOption:e.BlendOption.TRANSLUCENT}),this.lp=new jv({blendOption:e.BlendOption.TRANSLUCENT}),this.Hn=t.viewer,this._scene=t.viewer.scene,this.poiDataSource=new py({scene:this._scene,tileset:t.poiTileset,SSE:this.SSE}),this.roadDataSource=new wy({scene:this._scene,tileset:t.roadTileset,SSE:this.SSE}),this.Hn.dataSources.add(this.poiDataSource),this.Hn.dataSources.add(this.roadDataSource),this.onData=ky(this.onData,500,{maxWait:1e3}),this.poiDataSource.changedEvent.addEventListener(this.onData),this.roadDataSource.changedEvent.addEventListener(this.onData),this.xp(),this.kp(),this.Hn.camera.moveEnd.addEventListener(this.requestRender)}set show(t){this._labels.show=!!t,this.hp.show=!!t,this.ap.show=!!t,this.lp.show=!!t}get show(){return this._labels.show}onData=()=>{this.me||(this._dirty=!0,this.requestRender())};update(t){if(!this.styles||!this.show||!this.yp)return;if(!this._labels.preloaded)return;const e=this._scene.camera.position.clone(),{heading:n,pitch:i,roll:s}=this._scene.camera,o=new r.Cartesian3(n,i,s),a=r.Cartesian3.distance(e,this.bp)<1&&r.Cartesian3.equalsEpsilon(o,this._p,Math.PI/180),u=Date.now();if(u-this.gp>this.wp&&(!a||this._dirty)){this.gp=u,this.bp=e,this._p=o,this._dirty=!1;let t=this.poiDataSource.getData();this.vp.length&&(t=[].concat(this.vp).concat(t));const n=this.roadDataSource.getData(),i=this.computeItemsToRender(t,n),{pois:r,roads:s}=i;this.updateRoads(this.fp,s),this.updatePois(this.cp,r)}this.lp.update(t),this.hp.update(t),this.ap.update(t),this._labels.update(t)}isDestroyed(){return this.me}destroy(){this._labels.destroy(),this.ap.destroy(),this.hp.destroy(),this.lp.destroy(),this.cp={},this.fp={},this.poiDataSource.changedEvent.removeEventListener(this.onData),this.roadDataSource.changedEvent.removeEventListener(this.onData),this.me=!0,this.Hn.camera.moveEnd.removeEventListener(this.requestRender),this.requestRender()}addPoi(t){const n=`${Math.min(Math.floor(this.getZoom()),20)}:${t.styleId}`,i={...this.styles[n]};if(i)if(0===i.layout){const e=this.iconSize*i.transform[0],n=this.iconSize*i.transform[1],s=this.getIconUrl(i.file),o=this.ap.add({position:t.position,image:s,horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.CENTER,width:e,height:n,disableDepthTestDistance:this.disableDepthTestDistance});this.cp[t.id]={icon:o}}else if(1===i.layout){const n=t.name,s={text:n,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${i.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:i.size/e.SDFSettings.FONT_SIZE,relativeSize:i.size/e.SDFSettings.FONT_SIZE},o=this._labels.computeLabelSize(s),a=new e.Cartesian2(-o.width/2,-o.height/2),u=this.lineHeight?`/${this.lineHeight}px`:"",h=`${this.fontStyle} ${this.fontWeight} ${i.size}px${u} ${this.fontFamily}`,l=this._labels.add({position:t.position,text:n,font:h,horizontalOrigin:r.HorizontalOrigin.LEFT,verticalOrigin:r.VerticalOrigin.TOP,fillColor:r.Color.fromCssColorString(i.fill),style:r.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:this.disableDepthTestDistance,outlineColor:r.Color.fromCssColorString(i.haloFill),outlineWidth:i.haloRadius,pixelOffset:a});this.cp[t.id]={label:l}}else if(2===i.layout){const n=t.name,s=this.iconSize*i.transform[0],o=this.iconSize*i.transform[1],a=this.getIconUrl(i.file),u=this.ap.add({position:t.position,image:a,horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.CENTER,width:s,height:o,disableDepthTestDistance:this.disableDepthTestDistance,pixelOffset:new r.Cartesian2(0,i.shieldDy)}),h={text:n,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${i.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:i.size/e.SDFSettings.FONT_SIZE,relativeSize:i.size/e.SDFSettings.FONT_SIZE},l=this._labels.computeLabelSize(h),c=new e.Cartesian2(-l.width/2,-l.height/2),f=this.lineHeight?`/${this.lineHeight}px`:"",d=`${this.fontStyle} ${this.fontWeight} ${i.size}px${f} ${this.fontFamily}`,p=this._labels.add({position:t.position,text:n,font:d,horizontalOrigin:r.HorizontalOrigin.LEFT,verticalOrigin:r.VerticalOrigin.TOP,fillColor:r.Color.fromCssColorString(i.fill),style:r.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:this.disableDepthTestDistance,outlineColor:r.Color.fromCssColorString(i.haloFill),outlineWidth:i.haloRadius,pixelOffset:c});this.cp[t.id]={icon:u,label:p}}else if(3===i.layout){const n=t.name,s=this.iconSize*i.transform[0],o=this.iconSize*i.transform[1],a=this.getIconUrl(i.file),u=this.ap.add({position:t.position,image:a,horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.CENTER,width:s,height:o,disableDepthTestDistance:t.external?1/0:this.disableDepthTestDistance,pixelOffset:new r.Cartesian2(0,i.shieldDy)}),h={text:n,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${i.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:i.size/e.SDFSettings.FONT_SIZE,relativeSize:i.size/e.SDFSettings.FONT_SIZE},l=this._labels.computeLabelSize(h),c=new e.Cartesian2(s/2+this.iconTextSpacing,i.shieldDy-l.height/2),f=this.lineHeight?`/${this.lineHeight}px`:"",d=`${this.fontStyle} ${this.fontWeight} ${i.size}px${f} ${this.fontFamily}`,p=this._labels.add({position:t.position,text:n,font:d,horizontalOrigin:r.HorizontalOrigin.LEFT,verticalOrigin:r.VerticalOrigin.TOP,fillColor:r.Color.fromCssColorString(i.fill),style:r.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:t.external?1/0:this.disableDepthTestDistance,outlineColor:r.Color.fromCssColorString(i.haloFill),outlineWidth:i.haloRadius,pixelOffset:c});this.cp[t.id]={icon:u,label:p}}}addRoad(t){const n=`${Math.min(Math.floor(this.getZoom()),20)}:${t.styleId}`,i=this.styles[n];if(!i)return;const s=t.subType;if("roadname"===s){const n=t.name,s={text:n,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${i.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:i.size/e.SDFSettings.FONT_SIZE,relativeSize:i.size/e.SDFSettings.FONT_SIZE},o=this._labels.computeLabelSize(s),a=new e.Cartesian2(-o.width/2,-o.height/2),u=this.lineHeight?`/${this.lineHeight}px`:"",h=`${this.fontStyle} ${this.fontWeight} ${i.size}px${u} ${this.fontFamily}`,l=this.hp.add({position:t.position,text:n,font:h,horizontalOrigin:r.HorizontalOrigin.LEFT,verticalOrigin:r.VerticalOrigin.TOP,fillColor:r.Color.fromCssColorString(i.fill),style:r.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:this.disableDepthTestDistance,outlineColor:r.Color.fromCssColorString(i.haloFill),outlineWidth:i.haloRadius,pixelOffset:a});l.roadDirection=new r.Cartesian4(t.end.x-t.position.x,t.end.y-t.position.y,t.end.z-t.position.z,1),this.fp[t.id]={label:l}}else if("guideboard"===s){const n=t.name,s=this.iconSize*i.transform[0],o=this.iconSize*i.transform[1],a=this.getIconUrl(i.file),u=this.lp.add({position:t.position,image:a,horizontalOrigin:r.HorizontalOrigin.CENTER,verticalOrigin:r.VerticalOrigin.CENTER,width:s,height:o,disableDepthTestDistance:this.disableDepthTestDistance}),h={text:n,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${i.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:i.size/e.SDFSettings.FONT_SIZE,relativeSize:i.size/e.SDFSettings.FONT_SIZE},l=this._labels.computeLabelSize(h),c=new e.Cartesian2(-l.width/2,-l.height/2),f=this.lineHeight?`/${this.lineHeight}px`:"",d=`${this.fontStyle} ${this.fontWeight} ${i.size}px${f} ${this.fontFamily}`,p=this.hp.add({position:t.position,text:n,font:d,horizontalOrigin:r.HorizontalOrigin.LEFT,verticalOrigin:r.VerticalOrigin.TOP,fillColor:r.Color.fromCssColorString(i.fill),style:r.LabelStyle.FILL_AND_OUTLINE,disableDepthTestDistance:this.disableDepthTestDistance,outlineColor:r.Color.fromCssColorString(i.haloFill),outlineWidth:i.haloRadius,pixelOffset:c});this.fp[t.id]={icon:u,label:p}}}getIconUrl(t){return`${Ey.op}assets`+t.substring(1)}debugShowOrigin(t){this.Hn.entities.add({position:t,point:{pixelSize:1,color:r.Color.RED,outlineColor:r.Color.WHITE,outlineWidth:1}})}computeScreenSpaceSize(t){const n=this.Hn.scene.cartesianToCanvasCoordinates(t.position);if(!n)return;const i=`${Math.min(Math.floor(this.getZoom()),20)}:${t.styleId}`,s=this.styles[i];if(s){if(0===s.layout){const t=this.iconSize*s.transform[0],e=this.iconSize*s.transform[1];return new r.BoundingRectangle(n.x-t/2,n.y-e/2,t,e)}if(1===s.layout){const i={text:t.name,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${s.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:s.size/e.SDFSettings.FONT_SIZE,relativeSize:s.size/e.SDFSettings.FONT_SIZE},o=this._labels.computeLabelSize(i);return new r.BoundingRectangle(n.x-o.width/2,n.y-o.height/2,o.width,o.height)}if(2===s.layout){const i=t.name,o=this.iconSize*s.transform[0],a=this.iconSize*s.transform[1],u={text:i,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${s.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:s.size/e.SDFSettings.FONT_SIZE,relativeSize:s.size/e.SDFSettings.FONT_SIZE},h=this._labels.computeLabelSize(u),l=Math.max(o,h.width),c=Math.max(a,h.height);return new r.BoundingRectangle(n.x-l/2,n.y-c/2,l,c)}if(3===s.layout){const i=t.name,o=this.iconSize*s.transform[0],a=this.iconSize*s.transform[1],u={text:i,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${s.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:s.size/e.SDFSettings.FONT_SIZE,relativeSize:s.size/e.SDFSettings.FONT_SIZE},h=this._labels.computeLabelSize(u),l=Math.max(a,h.height);return new r.BoundingRectangle(n.x-o/2,n.y-l/2+s.shieldDy,o+h.width+this.iconTextSpacing,l)}}}computeScreenSpaceSizeRoad(t){const n=this.Hn.scene,i=`${Math.min(Math.floor(this.getZoom()),20)}:${t.styleId}`,s=this.styles[i];if(s){if("guideboard"===t.subType){const i=n.cartesianToCanvasCoordinates(t.position);if(!i)return;const o=t.name,a=this.iconSize*s.transform[0],u=this.iconSize*s.transform[1],h={text:o,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${s.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:s.size/e.SDFSettings.FONT_SIZE,relativeSize:s.size/e.SDFSettings.FONT_SIZE},l=this._labels.computeLabelSize(h),c=Math.max(a,l.width),f=Math.max(u,l.height);return new r.BoundingRectangle(i.x-c/2,i.y-f/2,c,f)}if("roadname"===t.subType){const i=n.cartesianToCanvasCoordinates(t.position),o=n.cartesianToCanvasCoordinates(t.end);if(!i||!o)return;t.screenPos=i,t.endScreenPos=o;const a=r.Cartesian2.subtract(o,i,new r.Cartesian2);a.y*=-1;const u=r.Cartesian2.normalize(a,new r.Cartesian2),h=new r.Cartesian2(1,0),l=r.Cartesian2.dot(h,u),c=(r.Cartesian2.cross(h,u)>0?1:-1)*Math.acos(l),f={text:t.name,fontStyle:this.fontStyle,fontWeight:this.fontWeight,fontSize:`${s.size}`,fontFamily:this.fontFamily,verticalOrigin:e.VerticalOrigin.TOP,totalScale:s.size/e.SDFSettings.FONT_SIZE,relativeSize:s.size/e.SDFSettings.FONT_SIZE},d=this._labels.computeLabelSize(f),p=[-d.width/2,d.height/2],v=[d.width/2,d.height/2],m=[-d.width/2,-d.height/2],y=[d.width/2,-d.height/2],w=Math.cos(c),g=Math.sin(c),b=[w*p[0]-g*p[1],g*p[0]+w*p[1]],_=[w*v[0]-g*v[1],g*v[0]+w*v[1]],x=[w*m[0]-g*m[1],g*m[0]+w*m[1]],k=[w*y[0]-g*y[1],g*y[0]+w*y[1]];return r.BoundingRectangle.fromPoints([new r.Cartesian2(i.x+b[0],i.y-b[1]),new r.Cartesian2(i.x+_[0],i.y-_[1]),new r.Cartesian2(i.x+x[0],i.y-x[1]),new r.Cartesian2(i.x+k[0],i.y-k[1])])}}}computePoiToRender(t){const e=this.getZoom();this.dp.clear();const n=new r.BoundingRectangle;n.x=0,n.y=0,n.width=this._scene.canvas.clientWidth,n.height=this._scene.canvas.clientHeight;const i=[];for(let s=0;s<t.length;s++){const o=t[s],a=20===o.maxzoom?999:o.maxzoom;if(e<o.minzoom||e>a)continue;const u=this.computeScreenSpaceSize(o);if(!u)continue;const{x:h,y:l,width:c,height:f}=u;if(n.intersect(u)===r.Intersect.OUTSIDE)continue;const d={minX:h-this.collisionBuffer.x,minY:l-this.collisionBuffer.y,maxX:h+c+this.collisionBuffer.x,maxY:l+f+this.collisionBuffer.y};this.dp.collides(d)||(this.dp.insert(d),i.push(o))}return i}computeItemsToRender(t,e){const n=this.getZoom();this.dp.clear();const i=new r.BoundingRectangle;i.x=0,i.y=0,i.width=this._scene.canvas.clientWidth,i.height=this._scene.canvas.clientHeight;const s=[];for(let t=0;t<e.length;t++){const o=e[t],a=20===o.maxzoom?999:o.maxzoom;if(n<o.minzoom||n>a)continue;const u=this.computeScreenSpaceSizeRoad(o);if(!u)continue;const{x:h,y:l,width:c,height:f}=u;if(i.intersect(u)===r.Intersect.OUTSIDE)continue;const d={minX:h-this.collisionBuffer.x,minY:l-this.collisionBuffer.y,maxX:h+c+this.collisionBuffer.x,maxY:l+f+this.collisionBuffer.y,data:o};this.dp.collides(d)||(this.dp.insert(d),s.push(o),o.bbox=u)}const o=[];for(let e=0;e<t.length;e++){const s=t[e],a=20===s.maxzoom?999:s.maxzoom;if(n<s.minzoom||n>a)continue;const u=this.computeScreenSpaceSize(s);if(!u)continue;const{x:h,y:l,width:c,height:f}=u;if(i.intersect(u)===r.Intersect.OUTSIDE)continue;const d={minX:h-this.collisionBuffer.x,minY:l-this.collisionBuffer.y,maxX:h+c+this.collisionBuffer.x,maxY:l+f+this.collisionBuffer.y,data:s};if(!s.external){if(this.dp.collides(d))continue;this.dp.insert(d)}o.push(s),s.bbox=u}return{pois:o,roads:s}}diff(t,e){const n=e.reduce(((t,e)=>(t[e.id]=e,t)),{}),i=Object.keys(t),r=[],s=[];for(let t=0;t<i.length;t++)n[i[t]]||r.push(i[t]);for(let n=0;n<e.length;n++)t[e[n].id]||s.push(e[n]);return{add:s,remove:r}}getZoom(){const t=this._scene.camera.position,e=r.Ellipsoid.WGS84.cartesianToCartographic(t).height;return Math.log2(169066473.75/e)}updateRoads(t,e){const{add:n,remove:i}=this.diff(t,e);for(let t=0;t<i.length;t++){const e=i[t],{label:n,icon:r}=this.fp[e];n&&this.hp.remove(n),r&&this.lp.remove(r),delete this.fp[e]}for(let t=0;t<n.length;t++){const e=n[t];this.addRoad(e)}}updatePois(t,e){const{add:n,remove:i}=this.diff(t,e);for(let t=0;t<i.length;t++){const e=i[t];if(this.cp[e]){const{icon:t,label:n}=this.cp[e];t&&this.ap.remove(t),n&&this._labels.remove(n),delete this.cp[e]}}for(let t=0;t<n.length;t++){const e=n[t];this.addPoi(e)}}xp(){const t=`\n @font-face {\n font-family: "AlibabaPuHuiTi";\n src: url("${Ey.op+"assets/AlibabaPuHuiTi-2-55-Regular/AlibabaPuHuiTi-2-55-Regular.woff2"}")\n format("woff2");\n font-weight: normal;\n font-style: normal;\n }\n `,e=document.createElement("style");e.id="AlibabaPuHuiTi",e.innerHTML=t,document.head.appendChild(e),new My("AlibabaPuHuiTi").load(null,this.mp).then((()=>{this.yp=!0,this.requestRender()}))}async kp(){try{const t=await fetch(this.styleUrl),e=await t.json();this.styles=e}catch(t){}}pick(t){const e={minX:t.x,minY:t.y,maxX:t.x+1,maxY:t.y+1},n=this.dp.search(e)[0];if("poi"===n?.data?.type)return n.data.poiid}setExtraPois(t){this.vp=t,this._dirty=!0,this.requestRender()}$p=null;requestRender=()=>{clearTimeout(this.$p);const t=Date.now()-this.gp;t>this.wp?this.Hn.scene.requestRender():this.$p=setTimeout((()=>{this.Hn.scene.requestRender()}),this.wp-t+1)}}class Ay{endpoint="https://address-search.amap.com/v3/query/place/text";constructor(){}async search(t){try{const e={method:"GET"},n=Object.keys(t).map((e=>`${e}=${encodeURIComponent(t[e])}`)).join("&"),i=this.endpoint+"?"+n,r=await fetch(i,e),s=await r.json();if(0===s.code){const t=s.pois.map((t=>{const[e,n]=t.location.split(",").map((t=>parseFloat(t))),i=parseFloat(t.height)||0;return{name:t.name,position:[e,n,i]}}));return{success:!0,data:t,message:""}}throw new Error(`Failed to fetch ${i}`)}catch(t){return{success:!1,data:[],message:t.message}}}}class Oy{fo;do="BuildingDataSource";po=!1;vo;mo;yo;_show=!0;wo;_scene;Ve;tp=1;ep={};np;Qd=0;ip={};tilesetUrl;tileset;minDistance;worker;constructor(t){this.vo=new r.Event,this.mo=new r.Event,this.po=!1,this.yo=new r.Event,this.fo=new r.EntityCollection,this.wo=new r.EntityCluster,this._scene=t.scene,this.tilesetUrl=t.tileset,this.np=this.tilesetUrl.substring(0,this.tilesetUrl.lastIndexOf("/")),this.minDistance=t.minDistance,this.Ve=new Gc({Hi:30,Bi:this.onDrop});const e=new Blob(['var factory;factory=function(){"use strict";var t="undefined"!=typeof document?document.currentScript:null;function n(t){return null!=t}function e(t){let n;this.name="DeveloperError",this.message=t;try{throw new Error}catch(t){n=t.stack}this.stack=n}n(Object.create)&&(e.prototype=Object.create(Error.prototype),e.prototype.constructor=e),e.prototype.toString=function(){let t=`${this.name}: ${this.message}`;return n(this.stack)&&(t+=`\\n${this.stack.toString()}`),t},e.throwInstantiationError=function(){throw new e("This function defines an interface and should not be called directly.")};const r={};function i(t,n,e){return`Expected ${e} to be typeof ${n}, actual typeof was ${t}`}function o(t,n){return null!=t?t:n}r.typeOf={},r.defined=function(t,r){if(!n(r))throw new e(function(t){return`${t} is required, actual value was undefined`}(t))},r.typeOf.func=function(t,n){if("function"!=typeof n)throw new e(i(typeof n,"function",t))},r.typeOf.string=function(t,n){if("string"!=typeof n)throw new e(i(typeof n,"string",t))},r.typeOf.number=function(t,n){if("number"!=typeof n)throw new e(i(typeof n,"number",t))},r.typeOf.number.lessThan=function(t,n,i){if(r.typeOf.number(t,n),n>=i)throw new e(`Expected ${t} to be less than ${i}, actual value was ${n}`)},r.typeOf.number.lessThanOrEquals=function(t,n,i){if(r.typeOf.number(t,n),n>i)throw new e(`Expected ${t} to be less than or equal to ${i}, actual value was ${n}`)},r.typeOf.number.greaterThan=function(t,n,i){if(r.typeOf.number(t,n),n<=i)throw new e(`Expected ${t} to be greater than ${i}, actual value was ${n}`)},r.typeOf.number.greaterThanOrEquals=function(t,n,i){if(r.typeOf.number(t,n),n<i)throw new e(`Expected ${t} to be greater than or equal to ${i}, actual value was ${n}`)},r.typeOf.object=function(t,n){if("object"!=typeof n)throw new e(i(typeof n,"object",t))},r.typeOf.bool=function(t,n){if("boolean"!=typeof n)throw new e(i(typeof n,"boolean",t))},r.typeOf.bigint=function(t,n){if("bigint"!=typeof n)throw new e(i(typeof n,"bigint",t))},r.typeOf.number.equals=function(t,n,i,o){if(r.typeOf.number(t,i),r.typeOf.number(n,o),i!==o)throw new e(`${t} must be equal to ${n}, the actual values are ${i} and ${o}`)},o.EMPTY_OBJECT=Object.freeze({});var u,s,c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){return t&&t.t&&{}.hasOwnProperty.call(t,"default")?t.default:t}var f=function(){if(s)return u;s=1;var t=function(t){null==t&&(t=(new Date).getTime()),this.N=624,this.M=397,this.MATRIX_A=2567483615,this.UPPER_MASK=2147483648,this.LOWER_MASK=2147483647,this.mt=new Array(this.N),this.mti=this.N+1,t.constructor==Array?this.init_by_array(t,t.length):this.init_seed(t)};return t.prototype.init_seed=function(t){for(this.mt[0]=t>>>0,this.mti=1;this.mti<this.N;this.mti++)t=this.mt[this.mti-1]^this.mt[this.mti-1]>>>30,this.mt[this.mti]=(1812433253*((4294901760&t)>>>16)<<16)+1812433253*(65535&t)+this.mti,this.mt[this.mti]>>>=0},t.prototype.init_by_array=function(t,n){var e,r,i;for(this.init_seed(19650218),e=1,r=0,i=this.N>n?this.N:n;i;i--){var o=this.mt[e-1]^this.mt[e-1]>>>30;this.mt[e]=(this.mt[e]^(1664525*((4294901760&o)>>>16)<<16)+1664525*(65535&o))+t[r]+r,this.mt[e]>>>=0,r++,++e>=this.N&&(this.mt[0]=this.mt[this.N-1],e=1),r>=n&&(r=0)}for(i=this.N-1;i;i--)o=this.mt[e-1]^this.mt[e-1]>>>30,this.mt[e]=(this.mt[e]^(1566083941*((4294901760&o)>>>16)<<16)+1566083941*(65535&o))-e,this.mt[e]>>>=0,++e>=this.N&&(this.mt[0]=this.mt[this.N-1],e=1);this.mt[0]=2147483648},t.prototype.random_int=function(){var t,n=new Array(0,this.MATRIX_A);if(this.mti>=this.N){var e;for(this.mti==this.N+1&&this.init_seed(5489),e=0;e<this.N-this.M;e++)t=this.mt[e]&this.UPPER_MASK|this.mt[e+1]&this.LOWER_MASK,this.mt[e]=this.mt[e+this.M]^t>>>1^n[1&t];for(;e<this.N-1;e++)t=this.mt[e]&this.UPPER_MASK|this.mt[e+1]&this.LOWER_MASK,this.mt[e]=this.mt[e+(this.M-this.N)]^t>>>1^n[1&t];t=this.mt[this.N-1]&this.UPPER_MASK|this.mt[0]&this.LOWER_MASK,this.mt[this.N-1]=this.mt[this.M-1]^t>>>1^n[1&t],this.mti=0}return t=this.mt[this.mti++],t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,(t^=t>>>18)>>>0},t.prototype.random_int31=function(){return this.random_int()>>>1},t.prototype.random_incl=function(){return this.random_int()*(1/4294967295)},t.prototype.random=function(){return this.random_int()*(1/4294967296)},t.prototype.random_excl=function(){return(this.random_int()+.5)*(1/4294967296)},t.prototype.random_long=function(){return(67108864*(this.random_int()>>>5)+(this.random_int()>>>6))*(1/9007199254740992)},u=t}(),h=a(f);const l={EPSILON1:.1,EPSILON2:.01,EPSILON3:.001,EPSILON4:1e-4,EPSILON5:1e-5,EPSILON6:1e-6,EPSILON7:1e-7,EPSILON8:1e-8,EPSILON9:1e-9,EPSILON10:1e-10,EPSILON11:1e-11,EPSILON12:1e-12,EPSILON13:1e-13,EPSILON14:1e-14,EPSILON15:1e-15,EPSILON16:1e-16,EPSILON17:1e-17,EPSILON18:1e-18,EPSILON19:1e-19,EPSILON20:1e-20,EPSILON21:1e-21,GRAVITATIONALPARAMETER:3986004418e5,SOLAR_RADIUS:6955e5,LUNAR_RADIUS:1737400,SIXTY_FOUR_KILOBYTES:65536,FOUR_GIGABYTES:4294967296};l.sign=o(Math.sign,(function(t){return 0==(t=+t)||t!=t?t:t>0?1:-1})),l.signNotZero=function(t){return t<0?-1:1},l.toSNorm=function(t,n){return n=o(n,255),Math.round((.5*l.clamp(t,-1,1)+.5)*n)},l.fromSNorm=function(t,n){return n=o(n,255),l.clamp(t,0,n)/n*2-1},l.normalize=function(t,n,e){return 0===(e=Math.max(e-n,0))?0:l.clamp((t-n)/e,0,1)},l.sinh=o(Math.sinh,(function(t){return(Math.exp(t)-Math.exp(-t))/2})),l.cosh=o(Math.cosh,(function(t){return(Math.exp(t)+Math.exp(-t))/2})),l.lerp=function(t,n,e){return(1-e)*t+e*n},l.PI=Math.PI,l.ONE_OVER_PI=1/Math.PI,l.PI_OVER_TWO=Math.PI/2,l.PI_OVER_THREE=Math.PI/3,l.PI_OVER_FOUR=Math.PI/4,l.PI_OVER_SIX=Math.PI/6,l.THREE_PI_OVER_TWO=3*Math.PI/2,l.TWO_PI=2*Math.PI,l.ONE_OVER_TWO_PI=1/(2*Math.PI),l.RADIANS_PER_DEGREE=Math.PI/180,l.DEGREES_PER_RADIAN=180/Math.PI,l.RADIANS_PER_ARCSECOND=l.RADIANS_PER_DEGREE/3600,l.toRadians=function(t){if(!n(t))throw new e("degrees is required.");return t*l.RADIANS_PER_DEGREE},l.toDegrees=function(t){if(!n(t))throw new e("radians is required.");return t*l.DEGREES_PER_RADIAN},l.convertLongitudeRange=function(t){if(!n(t))throw new e("angle is required.");const r=l.TWO_PI,i=t-Math.floor(t/r)*r;return i<-Math.PI?i+r:i>=Math.PI?i-r:i},l.clampToLatitudeRange=function(t){if(!n(t))throw new e("angle is required.");return l.clamp(t,-1*l.PI_OVER_TWO,l.PI_OVER_TWO)},l.negativePiToPi=function(t){if(!n(t))throw new e("angle is required.");return t>=-l.PI&&t<=l.PI?t:l.zeroToTwoPi(t+l.PI)-l.PI},l.zeroToTwoPi=function(t){if(!n(t))throw new e("angle is required.");if(t>=0&&t<=l.TWO_PI)return t;const r=l.mod(t,l.TWO_PI);return Math.abs(r)<l.EPSILON14&&Math.abs(t)>l.EPSILON14?l.TWO_PI:r},l.mod=function(t,r){if(!n(t))throw new e("m is required.");if(!n(r))throw new e("n is required.");if(0===r)throw new e("divisor cannot be 0.");return l.sign(t)===l.sign(r)&&Math.abs(t)<Math.abs(r)?t:(t%r+r)%r},l.equalsEpsilon=function(t,r,i,u){if(!n(t))throw new e("left is required.");if(!n(r))throw new e("right is required.");i=o(i,0),u=o(u,i);const s=Math.abs(t-r);return s<=u||s<=i*Math.max(Math.abs(t),Math.abs(r))},l.lessThan=function(t,r,i){if(!n(t))throw new e("first is required.");if(!n(r))throw new e("second is required.");if(!n(i))throw new e("absoluteEpsilon is required.");return t-r<-i},l.lessThanOrEquals=function(t,r,i){if(!n(t))throw new e("first is required.");if(!n(r))throw new e("second is required.");if(!n(i))throw new e("absoluteEpsilon is required.");return t-r<i},l.greaterThan=function(t,r,i){if(!n(t))throw new e("first is required.");if(!n(r))throw new e("second is required.");if(!n(i))throw new e("absoluteEpsilon is required.");return t-r>i},l.greaterThanOrEquals=function(t,r,i){if(!n(t))throw new e("first is required.");if(!n(r))throw new e("second is required.");if(!n(i))throw new e("absoluteEpsilon is required.");return t-r>-i};const d=[1];l.factorial=function(t){if("number"!=typeof t||t<0)throw new e("A number greater than or equal to 0 is required.");const n=d.length;if(t>=n){let e=d[n-1];for(let r=n;r<=t;r++){const t=e*r;d.push(t),e=t}}return d[t]},l.incrementWrap=function(t,r,i){if(i=o(i,0),!n(t))throw new e("n is required.");if(r<=i)throw new e("maximumValue must be greater than minimumValue.");return++t>r&&(t=i),t},l.isPowerOfTwo=function(t){if("number"!=typeof t||t<0||t>4294967295)throw new e("A number between 0 and (2^32)-1 is required.");return 0!==t&&!(t&t-1)},l.nextPowerOfTwo=function(t){if("number"!=typeof t||t<0||t>2147483648)throw new e("A number between 0 and 2^31 is required.");return--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t},l.previousPowerOfTwo=function(t){if("number"!=typeof t||t<0||t>4294967295)throw new e("A number between 0 and (2^32)-1 is required.");return t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,((t|=t>>32)>>>0)-(t>>>1)},l.clamp=function(t,n,e){return r.typeOf.number("value",t),r.typeOf.number("min",n),r.typeOf.number("max",e),t<n?n:t>e?e:t};let w=new h;function m(t,n,e){this.x=o(t,0),this.y=o(n,0),this.z=o(e,0)}l.setRandomNumberSeed=function(t){if(!n(t))throw new e("seed is required.");w=new h(t)},l.nextRandomNumber=function(){return w.random()},l.randomBetween=function(t,n){return l.nextRandomNumber()*(n-t)+t},l.acosClamped=function(t){if(!n(t))throw new e("value is required.");return Math.acos(l.clamp(t,-1,1))},l.asinClamped=function(t){if(!n(t))throw new e("value is required.");return Math.asin(l.clamp(t,-1,1))},l.chordLength=function(t,r){if(!n(t))throw new e("angle is required.");if(!n(r))throw new e("radius is required.");return 2*r*Math.sin(.5*t)},l.logBase=function(t,r){if(!n(t))throw new e("number is required.");if(!n(r))throw new e("base is required.");return Math.log(t)/Math.log(r)},l.cbrt=o(Math.cbrt,(function(t){const n=Math.pow(Math.abs(t),1/3);return t<0?-n:n})),l.log2=o(Math.log2,(function(t){return Math.log(t)*Math.LOG2E})),l.fog=function(t,n){const e=t*n;return 1-Math.exp(-e*e)},l.fastApproximateAtan=function(t){return r.typeOf.number("x",t),t*(-.1784*Math.abs(t)-.0663*t*t+1.0301)},l.fastApproximateAtan2=function(t,n){let i;r.typeOf.number("x",t),r.typeOf.number("y",n);let o=Math.abs(t);i=Math.abs(n);const u=Math.max(o,i);i=Math.min(o,i);const s=i/u;if(isNaN(s))throw new e("either x or y must be nonzero");return o=l.fastApproximateAtan(s),o=Math.abs(n)>Math.abs(t)?l.PI_OVER_TWO-o:o,o=t<0?l.PI-o:o,o=n<0?-o:o,o},m.fromSpherical=function(t,e){r.typeOf.object("spherical",t),n(e)||(e=new m);const i=t.clock,u=t.cone,s=o(t.magnitude,1),c=s*Math.sin(u);return e.x=c*Math.cos(i),e.y=c*Math.sin(i),e.z=s*Math.cos(u),e},m.fromElements=function(t,e,r,i){return n(i)?(i.x=t,i.y=e,i.z=r,i):new m(t,e,r)},m.clone=function(t,e){if(n(t))return n(e)?(e.x=t.x,e.y=t.y,e.z=t.z,e):new m(t.x,t.y,t.z)},m.fromCartesian4=m.clone,m.packedLength=3,m.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t.x,n[e++]=t.y,n[e]=t.z,n},m.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new m),i.x=t[e++],i.y=t[e++],i.z=t[e],i},m.packArray=function(t,i){r.defined("array",t);const o=t.length,u=3*o;if(n(i)){if(!Array.isArray(i)&&i.length!==u)throw new e("If result is a typed array, it must have exactly array.length * 3 elements");i.length!==u&&(i.length=u)}else i=new Array(u);for(let n=0;n<o;++n)m.pack(t[n],i,3*n);return i},m.unpackArray=function(t,i){if(r.defined("array",t),r.typeOf.number.greaterThanOrEquals("array.length",t.length,3),t.length%3!=0)throw new e("array length must be a multiple of 3.");const o=t.length;n(i)?i.length=o/3:i=new Array(o/3);for(let n=0;n<o;n+=3){const e=n/3;i[e]=m.unpack(t,n,i[e])}return i},m.fromArray=m.unpack,m.maximumComponent=function(t){return r.typeOf.object("cartesian",t),Math.max(t.x,t.y,t.z)},m.minimumComponent=function(t){return r.typeOf.object("cartesian",t),Math.min(t.x,t.y,t.z)},m.minimumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.min(t.x,n.x),e.y=Math.min(t.y,n.y),e.z=Math.min(t.z,n.z),e},m.maximumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.max(t.x,n.x),e.y=Math.max(t.y,n.y),e.z=Math.max(t.z,n.z),e},m.clamp=function(t,n,e,i){r.typeOf.object("value",t),r.typeOf.object("min",n),r.typeOf.object("max",e),r.typeOf.object("result",i);const o=l.clamp(t.x,n.x,e.x),u=l.clamp(t.y,n.y,e.y),s=l.clamp(t.z,n.z,e.z);return i.x=o,i.y=u,i.z=s,i},m.magnitudeSquared=function(t){return r.typeOf.object("cartesian",t),t.x*t.x+t.y*t.y+t.z*t.z},m.magnitude=function(t){return Math.sqrt(m.magnitudeSquared(t))};const g=new m;m.distance=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),m.subtract(t,n,g),m.magnitude(g)},m.distanceSquared=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),m.subtract(t,n,g),m.magnitudeSquared(g)},m.normalize=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const i=m.magnitude(t);if(n.x=t.x/i,n.y=t.y/i,n.z=t.z/i,isNaN(n.x)||isNaN(n.y)||isNaN(n.z))throw new e("normalized result is not a number");return n},m.dot=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),t.x*n.x+t.y*n.y+t.z*n.z},m.multiplyComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x*n.x,e.y=t.y*n.y,e.z=t.z*n.z,e},m.divideComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x/n.x,e.y=t.y/n.y,e.z=t.z/n.z,e},m.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x+n.x,e.y=t.y+n.y,e.z=t.z+n.z,e},m.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x-n.x,e.y=t.y-n.y,e.z=t.z-n.z,e},m.multiplyByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x*n,e.y=t.y*n,e.z=t.z*n,e},m.divideByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x/n,e.y=t.y/n,e.z=t.z/n,e},m.negate=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=-t.x,n.y=-t.y,n.z=-t.z,n},m.abs=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=Math.abs(t.x),n.y=Math.abs(t.y),n.z=Math.abs(t.z),n};const v=new m;m.lerp=function(t,n,e,i){return r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i),m.multiplyByScalar(n,e,v),i=m.multiplyByScalar(t,1-e,i),m.add(v,i,i)};const p=new m,y=new m;m.angleBetween=function(t,n){r.typeOf.object("left",t),r.typeOf.object("right",n),m.normalize(t,p),m.normalize(n,y);const e=m.dot(p,y),i=m.magnitude(m.cross(p,y,p));return Math.atan2(i,e)};const b=new m;m.mostOrthogonalAxis=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const e=m.normalize(t,b);return m.abs(e,e),e.x<=e.y?e.x<=e.z?m.clone(m.UNIT_X,n):m.clone(m.UNIT_Z,n):e.y<=e.z?m.clone(m.UNIT_Y,n):m.clone(m.UNIT_Z,n)},m.projectVector=function(t,n,e){r.defined("a",t),r.defined("b",n),r.defined("result",e);const i=m.dot(t,n)/m.dot(n,n);return m.multiplyByScalar(n,i,e)},m.equals=function(t,e){return t===e||n(t)&&n(e)&&t.x===e.x&&t.y===e.y&&t.z===e.z},m.equalsArray=function(t,n,e){return t.x===n[e]&&t.y===n[e+1]&&t.z===n[e+2]},m.equalsEpsilon=function(t,e,r,i){return t===e||n(t)&&n(e)&&l.equalsEpsilon(t.x,e.x,r,i)&&l.equalsEpsilon(t.y,e.y,r,i)&&l.equalsEpsilon(t.z,e.z,r,i)},m.cross=function(t,n,e){r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e);const i=t.x,o=t.y,u=t.z,s=n.x,c=n.y,a=n.z,f=o*a-u*c,h=u*s-i*a,l=i*c-o*s;return e.x=f,e.y=h,e.z=l,e},m.midpoint=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=.5*(t.x+n.x),e.y=.5*(t.y+n.y),e.z=.5*(t.z+n.z),e},m.fromDegrees=function(t,n,e,i,o){return r.typeOf.number("longitude",t),r.typeOf.number("latitude",n),t=l.toRadians(t),n=l.toRadians(n),m.fromRadians(t,n,e,i,o)};let M=new m,A=new m;function x(t,n,e,r){this.x=o(t,0),this.y=o(n,0),this.z=o(e,0),this.w=o(r,0)}m.o=new m(40680631590769,40680631590769,40408299984661.445),m.fromRadians=function(t,e,i,u,s){r.typeOf.number("longitude",t),r.typeOf.number("latitude",e),i=o(i,0);const c=n(u)?u.radiiSquared:m.o,a=Math.cos(e);M.x=a*Math.cos(t),M.y=a*Math.sin(t),M.z=Math.sin(e),M=m.normalize(M,M),m.multiplyComponents(c,M,A);const f=Math.sqrt(m.dot(M,A));return A=m.divideByScalar(A,f,A),M=m.multiplyByScalar(M,i,M),n(s)||(s=new m),m.add(A,M,s)},m.fromDegreesArray=function(t,i,o){if(r.defined("coordinates",t),t.length<2||t.length%2!=0)throw new e("the number of coordinates must be a multiple of 2 and at least 2");const u=t.length;n(o)?o.length=u/2:o=new Array(u/2);for(let n=0;n<u;n+=2){const e=t[n],r=t[n+1],u=n/2;o[u]=m.fromDegrees(e,r,0,i,o[u])}return o},m.fromRadiansArray=function(t,i,o){if(r.defined("coordinates",t),t.length<2||t.length%2!=0)throw new e("the number of coordinates must be a multiple of 2 and at least 2");const u=t.length;n(o)?o.length=u/2:o=new Array(u/2);for(let n=0;n<u;n+=2){const e=t[n],r=t[n+1],u=n/2;o[u]=m.fromRadians(e,r,0,i,o[u])}return o},m.fromDegreesArrayHeights=function(t,i,o){if(r.defined("coordinates",t),t.length<3||t.length%3!=0)throw new e("the number of coordinates must be a multiple of 3 and at least 3");const u=t.length;n(o)?o.length=u/3:o=new Array(u/3);for(let n=0;n<u;n+=3){const e=t[n],r=t[n+1],u=t[n+2],s=n/3;o[s]=m.fromDegrees(e,r,u,i,o[s])}return o},m.fromRadiansArrayHeights=function(t,i,o){if(r.defined("coordinates",t),t.length<3||t.length%3!=0)throw new e("the number of coordinates must be a multiple of 3 and at least 3");const u=t.length;n(o)?o.length=u/3:o=new Array(u/3);for(let n=0;n<u;n+=3){const e=t[n],r=t[n+1],u=t[n+2],s=n/3;o[s]=m.fromRadians(e,r,u,i,o[s])}return o},m.ZERO=Object.freeze(new m(0,0,0)),m.ONE=Object.freeze(new m(1,1,1)),m.UNIT_X=Object.freeze(new m(1,0,0)),m.UNIT_Y=Object.freeze(new m(0,1,0)),m.UNIT_Z=Object.freeze(new m(0,0,1)),m.prototype.clone=function(t){return m.clone(this,t)},m.prototype.equals=function(t){return m.equals(this,t)},m.prototype.equalsEpsilon=function(t,n,e){return m.equalsEpsilon(this,t,n,e)},m.prototype.toString=function(){return`(${this.x}, ${this.y}, ${this.z})`},x.fromElements=function(t,e,r,i,o){return n(o)?(o.x=t,o.y=e,o.z=r,o.w=i,o):new x(t,e,r,i)},x.fromColor=function(t,e){return r.typeOf.object("color",t),n(e)?(e.x=t.red,e.y=t.green,e.z=t.blue,e.w=t.alpha,e):new x(t.red,t.green,t.blue,t.alpha)},x.clone=function(t,e){if(n(t))return n(e)?(e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e):new x(t.x,t.y,t.z,t.w)},x.packedLength=4,x.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t.x,n[e++]=t.y,n[e++]=t.z,n[e]=t.w,n},x.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new x),i.x=t[e++],i.y=t[e++],i.z=t[e++],i.w=t[e],i},x.packArray=function(t,i){r.defined("array",t);const o=t.length,u=4*o;if(n(i)){if(!Array.isArray(i)&&i.length!==u)throw new e("If result is a typed array, it must have exactly array.length * 4 elements");i.length!==u&&(i.length=u)}else i=new Array(u);for(let n=0;n<o;++n)x.pack(t[n],i,4*n);return i},x.unpackArray=function(t,i){if(r.defined("array",t),r.typeOf.number.greaterThanOrEquals("array.length",t.length,4),t.length%4!=0)throw new e("array length must be a multiple of 4.");const o=t.length;n(i)?i.length=o/4:i=new Array(o/4);for(let n=0;n<o;n+=4){const e=n/4;i[e]=x.unpack(t,n,i[e])}return i},x.fromArray=x.unpack,x.maximumComponent=function(t){return r.typeOf.object("cartesian",t),Math.max(t.x,t.y,t.z,t.w)},x.minimumComponent=function(t){return r.typeOf.object("cartesian",t),Math.min(t.x,t.y,t.z,t.w)},x.minimumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.min(t.x,n.x),e.y=Math.min(t.y,n.y),e.z=Math.min(t.z,n.z),e.w=Math.min(t.w,n.w),e},x.maximumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.max(t.x,n.x),e.y=Math.max(t.y,n.y),e.z=Math.max(t.z,n.z),e.w=Math.max(t.w,n.w),e},x.clamp=function(t,n,e,i){r.typeOf.object("value",t),r.typeOf.object("min",n),r.typeOf.object("max",e),r.typeOf.object("result",i);const o=l.clamp(t.x,n.x,e.x),u=l.clamp(t.y,n.y,e.y),s=l.clamp(t.z,n.z,e.z),c=l.clamp(t.w,n.w,e.w);return i.x=o,i.y=u,i.z=s,i.w=c,i},x.magnitudeSquared=function(t){return r.typeOf.object("cartesian",t),t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w},x.magnitude=function(t){return Math.sqrt(x.magnitudeSquared(t))};const E=new x;x.distance=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),x.subtract(t,n,E),x.magnitude(E)},x.distanceSquared=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),x.subtract(t,n,E),x.magnitudeSquared(E)},x.normalize=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const i=x.magnitude(t);if(n.x=t.x/i,n.y=t.y/i,n.z=t.z/i,n.w=t.w/i,isNaN(n.x)||isNaN(n.y)||isNaN(n.z)||isNaN(n.w))throw new e("normalized result is not a number");return n},x.dot=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),t.x*n.x+t.y*n.y+t.z*n.z+t.w*n.w},x.multiplyComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x*n.x,e.y=t.y*n.y,e.z=t.z*n.z,e.w=t.w*n.w,e},x.divideComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x/n.x,e.y=t.y/n.y,e.z=t.z/n.z,e.w=t.w/n.w,e},x.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x+n.x,e.y=t.y+n.y,e.z=t.z+n.z,e.w=t.w+n.w,e},x.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x-n.x,e.y=t.y-n.y,e.z=t.z-n.z,e.w=t.w-n.w,e},x.multiplyByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x*n,e.y=t.y*n,e.z=t.z*n,e.w=t.w*n,e},x.divideByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x/n,e.y=t.y/n,e.z=t.z/n,e.w=t.w/n,e},x.negate=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=-t.x,n.y=-t.y,n.z=-t.z,n.w=-t.w,n},x.abs=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=Math.abs(t.x),n.y=Math.abs(t.y),n.z=Math.abs(t.z),n.w=Math.abs(t.w),n};const k=new x;x.lerp=function(t,n,e,i){return r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i),x.multiplyByScalar(n,e,k),i=x.multiplyByScalar(t,1-e,i),x.add(k,i,i)};const q=new x;x.mostOrthogonalAxis=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const e=x.normalize(t,q);return x.abs(e,e),e.x<=e.y?e.x<=e.z?e.x<=e.w?x.clone(x.UNIT_X,n):x.clone(x.UNIT_W,n):e.z<=e.w?x.clone(x.UNIT_Z,n):x.clone(x.UNIT_W,n):e.y<=e.z?e.y<=e.w?x.clone(x.UNIT_Y,n):x.clone(x.UNIT_W,n):e.z<=e.w?x.clone(x.UNIT_Z,n):x.clone(x.UNIT_W,n)},x.equals=function(t,e){return t===e||n(t)&&n(e)&&t.x===e.x&&t.y===e.y&&t.z===e.z&&t.w===e.w},x.equalsArray=function(t,n,e){return t.x===n[e]&&t.y===n[e+1]&&t.z===n[e+2]&&t.w===n[e+3]},x.equalsEpsilon=function(t,e,r,i){return t===e||n(t)&&n(e)&&l.equalsEpsilon(t.x,e.x,r,i)&&l.equalsEpsilon(t.y,e.y,r,i)&&l.equalsEpsilon(t.z,e.z,r,i)&&l.equalsEpsilon(t.w,e.w,r,i)},x.ZERO=Object.freeze(new x(0,0,0,0)),x.ONE=Object.freeze(new x(1,1,1,1)),x.UNIT_X=Object.freeze(new x(1,0,0,0)),x.UNIT_Y=Object.freeze(new x(0,1,0,0)),x.UNIT_Z=Object.freeze(new x(0,0,1,0)),x.UNIT_W=Object.freeze(new x(0,0,0,1)),x.prototype.clone=function(t){return x.clone(this,t)},x.prototype.equals=function(t){return x.equals(this,t)},x.prototype.equalsEpsilon=function(t,n,e){return x.equalsEpsilon(this,t,n,e)},x.prototype.toString=function(){return`(${this.x}, ${this.y}, ${this.z}, ${this.w})`};const $=new Float32Array(1),S=new Uint8Array($.buffer),I=new Uint32Array([287454020]),O=68===new Uint8Array(I.buffer)[0];function R(t,n,e,r,i,u,s,c,a){this[0]=o(t,0),this[1]=o(r,0),this[2]=o(s,0),this[3]=o(n,0),this[4]=o(i,0),this[5]=o(c,0),this[6]=o(e,0),this[7]=o(u,0),this[8]=o(a,0)}x.packFloat=function(t,e){return r.typeOf.number("value",t),n(e)||(e=new x),$[0]=t,O?(e.x=S[0],e.y=S[1],e.z=S[2],e.w=S[3]):(e.x=S[3],e.y=S[2],e.z=S[1],e.w=S[0]),e},x.unpackFloat=function(t){return r.typeOf.object("packedFloat",t),O?(S[0]=t.x,S[1]=t.y,S[2]=t.z,S[3]=t.w):(S[0]=t.w,S[1]=t.z,S[2]=t.y,S[3]=t.x),$[0]},R.packedLength=9,R.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t[0],n[e++]=t[1],n[e++]=t[2],n[e++]=t[3],n[e++]=t[4],n[e++]=t[5],n[e++]=t[6],n[e++]=t[7],n[e++]=t[8],n},R.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new R),i[0]=t[e++],i[1]=t[e++],i[2]=t[e++],i[3]=t[e++],i[4]=t[e++],i[5]=t[e++],i[6]=t[e++],i[7]=t[e++],i[8]=t[e++],i},R.packArray=function(t,i){r.defined("array",t);const o=t.length,u=9*o;if(n(i)){if(!Array.isArray(i)&&i.length!==u)throw new e("If result is a typed array, it must have exactly array.length * 9 elements");i.length!==u&&(i.length=u)}else i=new Array(u);for(let n=0;n<o;++n)R.pack(t[n],i,9*n);return i},R.unpackArray=function(t,i){if(r.defined("array",t),r.typeOf.number.greaterThanOrEquals("array.length",t.length,9),t.length%9!=0)throw new e("array length must be a multiple of 9.");const o=t.length;n(i)?i.length=o/9:i=new Array(o/9);for(let n=0;n<o;n+=9){const e=n/9;i[e]=R.unpack(t,n,i[e])}return i},R.clone=function(t,e){if(n(t))return n(e)?(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):new R(t[0],t[3],t[6],t[1],t[4],t[7],t[2],t[5],t[8])},R.fromArray=R.unpack,R.fromColumnMajorArray=function(t,n){return r.defined("values",t),R.clone(t,n)},R.fromRowMajorArray=function(t,e){return r.defined("values",t),n(e)?(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],e):new R(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8])},R.fromQuaternion=function(t,e){r.typeOf.object("quaternion",t);const i=t.x*t.x,o=t.x*t.y,u=t.x*t.z,s=t.x*t.w,c=t.y*t.y,a=t.y*t.z,f=t.y*t.w,h=t.z*t.z,l=t.z*t.w,d=t.w*t.w,w=i-c-h+d,m=2*(o-l),g=2*(u+f),v=2*(o+l),p=-i+c-h+d,y=2*(a-s),b=2*(u-f),M=2*(a+s),A=-i-c+h+d;return n(e)?(e[0]=w,e[1]=v,e[2]=b,e[3]=m,e[4]=p,e[5]=M,e[6]=g,e[7]=y,e[8]=A,e):new R(w,m,g,v,p,y,b,M,A)},R.fromHeadingPitchRoll=function(t,e){r.typeOf.object("headingPitchRoll",t);const i=Math.cos(-t.pitch),o=Math.cos(-t.heading),u=Math.cos(t.roll),s=Math.sin(-t.pitch),c=Math.sin(-t.heading),a=Math.sin(t.roll),f=i*o,h=-u*c+a*s*o,l=a*c+u*s*o,d=i*c,w=u*o+a*s*c,m=-a*o+u*s*c,g=-s,v=a*i,p=u*i;return n(e)?(e[0]=f,e[1]=d,e[2]=g,e[3]=h,e[4]=w,e[5]=v,e[6]=l,e[7]=m,e[8]=p,e):new R(f,h,l,d,w,m,g,v,p)},R.fromScale=function(t,e){return r.typeOf.object("scale",t),n(e)?(e[0]=t.x,e[1]=0,e[2]=0,e[3]=0,e[4]=t.y,e[5]=0,e[6]=0,e[7]=0,e[8]=t.z,e):new R(t.x,0,0,0,t.y,0,0,0,t.z)},R.fromUniformScale=function(t,e){return r.typeOf.number("scale",t),n(e)?(e[0]=t,e[1]=0,e[2]=0,e[3]=0,e[4]=t,e[5]=0,e[6]=0,e[7]=0,e[8]=t,e):new R(t,0,0,0,t,0,0,0,t)},R.fromCrossProduct=function(t,e){return r.typeOf.object("vector",t),n(e)?(e[0]=0,e[1]=t.z,e[2]=-t.y,e[3]=-t.z,e[4]=0,e[5]=t.x,e[6]=t.y,e[7]=-t.x,e[8]=0,e):new R(0,-t.z,t.y,t.z,0,-t.x,-t.y,t.x,0)},R.fromRotationX=function(t,e){r.typeOf.number("angle",t);const i=Math.cos(t),o=Math.sin(t);return n(e)?(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=i,e[5]=o,e[6]=0,e[7]=-o,e[8]=i,e):new R(1,0,0,0,i,-o,0,o,i)},R.fromRotationY=function(t,e){r.typeOf.number("angle",t);const i=Math.cos(t),o=Math.sin(t);return n(e)?(e[0]=i,e[1]=0,e[2]=-o,e[3]=0,e[4]=1,e[5]=0,e[6]=o,e[7]=0,e[8]=i,e):new R(i,0,o,0,1,0,-o,0,i)},R.fromRotationZ=function(t,e){r.typeOf.number("angle",t);const i=Math.cos(t),o=Math.sin(t);return n(e)?(e[0]=i,e[1]=o,e[2]=0,e[3]=-o,e[4]=i,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e):new R(i,-o,0,o,i,0,0,0,1)},R.toArray=function(t,e){return r.typeOf.object("matrix",t),n(e)?(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):[t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]]},R.getElementIndex=function(t,n){return r.typeOf.number.greaterThanOrEquals("row",n,0),r.typeOf.number.lessThanOrEquals("row",n,2),r.typeOf.number.greaterThanOrEquals("column",t,0),r.typeOf.number.lessThanOrEquals("column",t,2),3*t+n},R.getColumn=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,2),r.typeOf.object("result",e);const i=3*n,o=t[i],u=t[i+1],s=t[i+2];return e.x=o,e.y=u,e.z=s,e},R.setColumn=function(t,n,e,i){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,2),r.typeOf.object("cartesian",e),r.typeOf.object("result",i);const o=3*n;return(i=R.clone(t,i))[o]=e.x,i[o+1]=e.y,i[o+2]=e.z,i},R.getRow=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,2),r.typeOf.object("result",e);const i=t[n],o=t[n+3],u=t[n+6];return e.x=i,e.y=o,e.z=u,e},R.setRow=function(t,n,e,i){return r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,2),r.typeOf.object("cartesian",e),r.typeOf.object("result",i),(i=R.clone(t,i))[n]=e.x,i[n+3]=e.y,i[n+6]=e.z,i};const P=new m;R.setScale=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("scale",n),r.typeOf.object("result",e);const i=R.getScale(t,P),o=n.x/i.x,u=n.y/i.y,s=n.z/i.z;return e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3]*u,e[4]=t[4]*u,e[5]=t[5]*u,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*s,e};const j=new m;R.setUniformScale=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number("scale",n),r.typeOf.object("result",e);const i=R.getScale(t,j),o=n/i.x,u=n/i.y,s=n/i.z;return e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3]*u,e[4]=t[4]*u,e[5]=t[5]*u,e[6]=t[6]*s,e[7]=t[7]*s,e[8]=t[8]*s,e};const F=new m;R.getScale=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n.x=m.magnitude(m.fromElements(t[0],t[1],t[2],F)),n.y=m.magnitude(m.fromElements(t[3],t[4],t[5],F)),n.z=m.magnitude(m.fromElements(t[6],t[7],t[8],F)),n};const N=new m;R.getMaximumScale=function(t){return R.getScale(t,N),m.maximumComponent(N)};const U=new m;R.setRotation=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("result",e);const i=R.getScale(t,U);return e[0]=n[0]*i.x,e[1]=n[1]*i.x,e[2]=n[2]*i.x,e[3]=n[3]*i.y,e[4]=n[4]*i.y,e[5]=n[5]*i.y,e[6]=n[6]*i.z,e[7]=n[7]*i.z,e[8]=n[8]*i.z,e};const T=new m;R.getRotation=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=R.getScale(t,T);return n[0]=t[0]/e.x,n[1]=t[1]/e.x,n[2]=t[2]/e.x,n[3]=t[3]/e.y,n[4]=t[4]/e.y,n[5]=t[5]/e.y,n[6]=t[6]/e.z,n[7]=t[7]/e.z,n[8]=t[8]/e.z,n},R.multiply=function(t,n,e){r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e);const i=t[0]*n[0]+t[3]*n[1]+t[6]*n[2],o=t[1]*n[0]+t[4]*n[1]+t[7]*n[2],u=t[2]*n[0]+t[5]*n[1]+t[8]*n[2],s=t[0]*n[3]+t[3]*n[4]+t[6]*n[5],c=t[1]*n[3]+t[4]*n[4]+t[7]*n[5],a=t[2]*n[3]+t[5]*n[4]+t[8]*n[5],f=t[0]*n[6]+t[3]*n[7]+t[6]*n[8],h=t[1]*n[6]+t[4]*n[7]+t[7]*n[8],l=t[2]*n[6]+t[5]*n[7]+t[8]*n[8];return e[0]=i,e[1]=o,e[2]=u,e[3]=s,e[4]=c,e[5]=a,e[6]=f,e[7]=h,e[8]=l,e},R.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),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},R.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),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},R.multiplyByVector=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("cartesian",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z,s=t[0]*i+t[3]*o+t[6]*u,c=t[1]*i+t[4]*o+t[7]*u,a=t[2]*i+t[5]*o+t[8]*u;return e.x=s,e.y=c,e.z=a,e},R.multiplyByScalar=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),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},R.multiplyByScale=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.object("scale",n),r.typeOf.object("result",e),e[0]=t[0]*n.x,e[1]=t[1]*n.x,e[2]=t[2]*n.x,e[3]=t[3]*n.y,e[4]=t[4]*n.y,e[5]=t[5]*n.y,e[6]=t[6]*n.z,e[7]=t[7]*n.z,e[8]=t[8]*n.z,e},R.multiplyByUniformScale=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.number("scale",n),r.typeOf.object("result",e),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},R.negate=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n[3]=-t[3],n[4]=-t[4],n[5]=-t[5],n[6]=-t[6],n[7]=-t[7],n[8]=-t[8],n},R.transpose=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=t[0],i=t[3],o=t[6],u=t[1],s=t[4],c=t[7],a=t[2],f=t[5],h=t[8];return n[0]=e,n[1]=i,n[2]=o,n[3]=u,n[4]=s,n[5]=c,n[6]=a,n[7]=f,n[8]=h,n};const z=[1,0,0],C=[2,2,1];function D(t){let n=0;for(let e=0;e<3;++e){const r=t[R.getElementIndex(C[e],z[e])];n+=2*r*r}return Math.sqrt(n)}function B(t,n){const e=l.EPSILON15;let r=0,i=1;for(let n=0;n<3;++n){const e=Math.abs(t[R.getElementIndex(C[n],z[n])]);e>r&&(i=n,r=e)}let o=1,u=0;const s=z[i],c=C[i];if(Math.abs(t[R.getElementIndex(c,s)])>e){const n=(t[R.getElementIndex(c,c)]-t[R.getElementIndex(s,s)])/2/t[R.getElementIndex(c,s)];let e;e=n<0?-1/(-n+Math.sqrt(1+n*n)):1/(n+Math.sqrt(1+n*n)),o=1/Math.sqrt(1+e*e),u=e*o}return(n=R.clone(R.IDENTITY,n))[R.getElementIndex(s,s)]=n[R.getElementIndex(c,c)]=o,n[R.getElementIndex(c,s)]=u,n[R.getElementIndex(s,c)]=-u,n}const L=new R,_=new R;R.computeEigenDecomposition=function(t,e){r.typeOf.object("matrix",t);const i=l.EPSILON20;let o=0,u=0;n(e)||(e={});const s=e.unitary=R.clone(R.IDENTITY,e.unitary),c=e.diagonal=R.clone(t,e.diagonal),a=i*function(t){let n=0;for(let e=0;e<9;++e){const r=t[e];n+=r*r}return Math.sqrt(n)}(c);for(;u<10&&D(c)>a;)B(c,L),R.transpose(L,_),R.multiply(c,L,c),R.multiply(_,c,c),R.multiply(s,L,s),++o>2&&(++u,o=0);return e},R.abs=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n[0]=Math.abs(t[0]),n[1]=Math.abs(t[1]),n[2]=Math.abs(t[2]),n[3]=Math.abs(t[3]),n[4]=Math.abs(t[4]),n[5]=Math.abs(t[5]),n[6]=Math.abs(t[6]),n[7]=Math.abs(t[7]),n[8]=Math.abs(t[8]),n},R.determinant=function(t){r.typeOf.object("matrix",t);const n=t[0],e=t[3],i=t[6],o=t[1],u=t[4],s=t[7],c=t[2],a=t[5],f=t[8];return n*(u*f-a*s)+o*(a*i-e*f)+c*(e*s-u*i)},R.inverse=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const i=t[0],o=t[1],u=t[2],s=t[3],c=t[4],a=t[5],f=t[6],h=t[7],d=t[8],w=R.determinant(t);if(Math.abs(w)<=l.EPSILON15)throw new e("matrix is not invertible");n[0]=c*d-h*a,n[1]=h*u-o*d,n[2]=o*a-c*u,n[3]=f*a-s*d,n[4]=i*d-f*u,n[5]=s*u-i*a,n[6]=s*h-f*c,n[7]=f*o-i*h,n[8]=i*c-s*o;const m=1/w;return R.multiplyByScalar(n,m,n)};const V=new R;function H(t){let n;this.name="RuntimeError",this.message=t;try{throw new Error}catch(t){n=t.stack}this.stack=n}function Y(t,n,e,r,i,u,s,c,a,f,h,l,d,w,m,g){this[0]=o(t,0),this[1]=o(i,0),this[2]=o(a,0),this[3]=o(d,0),this[4]=o(n,0),this[5]=o(u,0),this[6]=o(f,0),this[7]=o(w,0),this[8]=o(e,0),this[9]=o(s,0),this[10]=o(h,0),this[11]=o(m,0),this[12]=o(r,0),this[13]=o(c,0),this[14]=o(l,0),this[15]=o(g,0)}R.inverseTranspose=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),R.inverse(R.transpose(t,V),n)},R.equals=function(t,e){return t===e||n(t)&&n(e)&&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]},R.equalsEpsilon=function(t,e,r){return r=o(r,0),t===e||n(t)&&n(e)&&Math.abs(t[0]-e[0])<=r&&Math.abs(t[1]-e[1])<=r&&Math.abs(t[2]-e[2])<=r&&Math.abs(t[3]-e[3])<=r&&Math.abs(t[4]-e[4])<=r&&Math.abs(t[5]-e[5])<=r&&Math.abs(t[6]-e[6])<=r&&Math.abs(t[7]-e[7])<=r&&Math.abs(t[8]-e[8])<=r},R.IDENTITY=Object.freeze(new R(1,0,0,0,1,0,0,0,1)),R.ZERO=Object.freeze(new R(0,0,0,0,0,0,0,0,0)),R.COLUMN0ROW0=0,R.COLUMN0ROW1=1,R.COLUMN0ROW2=2,R.COLUMN1ROW0=3,R.COLUMN1ROW1=4,R.COLUMN1ROW2=5,R.COLUMN2ROW0=6,R.COLUMN2ROW1=7,R.COLUMN2ROW2=8,Object.defineProperties(R.prototype,{length:{get:function(){return R.packedLength}}}),R.prototype.clone=function(t){return R.clone(this,t)},R.prototype.equals=function(t){return R.equals(this,t)},R.equalsArray=function(t,n,e){return t[0]===n[e]&&t[1]===n[e+1]&&t[2]===n[e+2]&&t[3]===n[e+3]&&t[4]===n[e+4]&&t[5]===n[e+5]&&t[6]===n[e+6]&&t[7]===n[e+7]&&t[8]===n[e+8]},R.prototype.equalsEpsilon=function(t,n){return R.equalsEpsilon(this,t,n)},R.prototype.toString=function(){return`(${this[0]}, ${this[3]}, ${this[6]})\\n(${this[1]}, ${this[4]}, ${this[7]})\\n(${this[2]}, ${this[5]}, ${this[8]})`},n(Object.create)&&(H.prototype=Object.create(Error.prototype),H.prototype.constructor=H),H.prototype.toString=function(){let t=`${this.name}: ${this.message}`;return n(this.stack)&&(t+=`\\n${this.stack.toString()}`),t},Y.packedLength=16,Y.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t[0],n[e++]=t[1],n[e++]=t[2],n[e++]=t[3],n[e++]=t[4],n[e++]=t[5],n[e++]=t[6],n[e++]=t[7],n[e++]=t[8],n[e++]=t[9],n[e++]=t[10],n[e++]=t[11],n[e++]=t[12],n[e++]=t[13],n[e++]=t[14],n[e]=t[15],n},Y.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new Y),i[0]=t[e++],i[1]=t[e++],i[2]=t[e++],i[3]=t[e++],i[4]=t[e++],i[5]=t[e++],i[6]=t[e++],i[7]=t[e++],i[8]=t[e++],i[9]=t[e++],i[10]=t[e++],i[11]=t[e++],i[12]=t[e++],i[13]=t[e++],i[14]=t[e++],i[15]=t[e],i},Y.packArray=function(t,i){r.defined("array",t);const o=t.length,u=16*o;if(n(i)){if(!Array.isArray(i)&&i.length!==u)throw new e("If result is a typed array, it must have exactly array.length * 16 elements");i.length!==u&&(i.length=u)}else i=new Array(u);for(let n=0;n<o;++n)Y.pack(t[n],i,16*n);return i},Y.unpackArray=function(t,i){if(r.defined("array",t),r.typeOf.number.greaterThanOrEquals("array.length",t.length,16),t.length%16!=0)throw new e("array length must be a multiple of 16.");const o=t.length;n(i)?i.length=o/16:i=new Array(o/16);for(let n=0;n<o;n+=16){const e=n/16;i[e]=Y.unpack(t,n,i[e])}return i},Y.clone=function(t,e){if(n(t))return n(e)?(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):new Y(t[0],t[4],t[8],t[12],t[1],t[5],t[9],t[13],t[2],t[6],t[10],t[14],t[3],t[7],t[11],t[15])},Y.fromArray=Y.unpack,Y.fromColumnMajorArray=function(t,n){return r.defined("values",t),Y.clone(t,n)},Y.fromRowMajorArray=function(t,e){return r.defined("values",t),n(e)?(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],e):new Y(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15])},Y.fromRotationTranslation=function(t,e,i){return r.typeOf.object("rotation",t),e=o(e,m.ZERO),n(i)?(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=0,i[4]=t[3],i[5]=t[4],i[6]=t[5],i[7]=0,i[8]=t[6],i[9]=t[7],i[10]=t[8],i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,i):new Y(t[0],t[3],t[6],e.x,t[1],t[4],t[7],e.y,t[2],t[5],t[8],e.z,0,0,0,1)},Y.fromTranslationQuaternionRotationScale=function(t,e,i,o){r.typeOf.object("translation",t),r.typeOf.object("rotation",e),r.typeOf.object("scale",i),n(o)||(o=new Y);const u=i.x,s=i.y,c=i.z,a=e.x*e.x,f=e.x*e.y,h=e.x*e.z,l=e.x*e.w,d=e.y*e.y,w=e.y*e.z,m=e.y*e.w,g=e.z*e.z,v=e.z*e.w,p=e.w*e.w,y=a-d-g+p,b=2*(f-v),M=2*(h+m),A=2*(f+v),x=-a+d-g+p,E=2*(w-l),k=2*(h-m),q=2*(w+l),$=-a-d+g+p;return o[0]=y*u,o[1]=A*u,o[2]=k*u,o[3]=0,o[4]=b*s,o[5]=x*s,o[6]=q*s,o[7]=0,o[8]=M*c,o[9]=E*c,o[10]=$*c,o[11]=0,o[12]=t.x,o[13]=t.y,o[14]=t.z,o[15]=1,o},Y.fromTranslationRotationScale=function(t,n){return r.typeOf.object("translationRotationScale",t),Y.fromTranslationQuaternionRotationScale(t.translation,t.rotation,t.scale,n)},Y.fromTranslation=function(t,n){return r.typeOf.object("translation",t),Y.fromRotationTranslation(R.IDENTITY,t,n)},Y.fromScale=function(t,e){return r.typeOf.object("scale",t),n(e)?(e[0]=t.x,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t.y,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t.z,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e):new Y(t.x,0,0,0,0,t.y,0,0,0,0,t.z,0,0,0,0,1)},Y.fromUniformScale=function(t,e){return r.typeOf.number("scale",t),n(e)?(e[0]=t,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e):new Y(t,0,0,0,0,t,0,0,0,0,t,0,0,0,0,1)},Y.fromRotation=function(t,e){return r.typeOf.object("rotation",t),n(e)||(e=new Y),e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=0,e[4]=t[3],e[5]=t[4],e[6]=t[5],e[7]=0,e[8]=t[6],e[9]=t[7],e[10]=t[8],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e};const Z=new m,W=new m,Q=new m;Y.fromCamera=function(t,e){r.typeOf.object("camera",t);const i=t.position,o=t.direction,u=t.up;r.typeOf.object("camera.position",i),r.typeOf.object("camera.direction",o),r.typeOf.object("camera.up",u),m.normalize(o,Z),m.normalize(m.cross(Z,u,W),W),m.normalize(m.cross(W,Z,Q),Q);const s=W.x,c=W.y,a=W.z,f=Z.x,h=Z.y,l=Z.z,d=Q.x,w=Q.y,g=Q.z,v=i.x,p=i.y,y=i.z,b=s*-v+c*-p+a*-y,M=d*-v+w*-p+g*-y,A=f*v+h*p+l*y;return n(e)?(e[0]=s,e[1]=d,e[2]=-f,e[3]=0,e[4]=c,e[5]=w,e[6]=-h,e[7]=0,e[8]=a,e[9]=g,e[10]=-l,e[11]=0,e[12]=b,e[13]=M,e[14]=A,e[15]=1,e):new Y(s,c,a,b,d,w,g,M,-f,-h,-l,A,0,0,0,1)},Y.computePerspectiveFieldOfView=function(t,n,e,i,o){r.typeOf.number.greaterThan("fovY",t,0),r.typeOf.number.lessThan("fovY",t,Math.PI),r.typeOf.number.greaterThan("near",e,0),r.typeOf.number.greaterThan("far",i,0),r.typeOf.object("result",o);const u=1/Math.tan(.5*t),s=u/n,c=(i+e)/(e-i),a=2*i*e/(e-i);return o[0]=s,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=u,o[6]=0,o[7]=0,o[8]=0,o[9]=0,o[10]=c,o[11]=-1,o[12]=0,o[13]=0,o[14]=a,o[15]=0,o},Y.computeOrthographicOffCenter=function(t,n,e,i,o,u,s){r.typeOf.number("left",t),r.typeOf.number("right",n),r.typeOf.number("bottom",e),r.typeOf.number("top",i),r.typeOf.number("near",o),r.typeOf.number("far",u),r.typeOf.object("result",s);let c=1/(n-t),a=1/(i-e),f=1/(u-o);const h=-(n+t)*c,l=-(i+e)*a,d=-(u+o)*f;return c*=2,a*=2,f*=-2,s[0]=c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=f,s[11]=0,s[12]=h,s[13]=l,s[14]=d,s[15]=1,s},Y.computePerspectiveOffCenter=function(t,n,e,i,o,u,s){r.typeOf.number("left",t),r.typeOf.number("right",n),r.typeOf.number("bottom",e),r.typeOf.number("top",i),r.typeOf.number("near",o),r.typeOf.number("far",u),r.typeOf.object("result",s);const c=2*o/(n-t),a=2*o/(i-e),f=(n+t)/(n-t),h=(i+e)/(i-e),l=-(u+o)/(u-o),d=-2*u*o/(u-o);return s[0]=c,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a,s[6]=0,s[7]=0,s[8]=f,s[9]=h,s[10]=l,s[11]=-1,s[12]=0,s[13]=0,s[14]=d,s[15]=0,s},Y.computeInfinitePerspectiveOffCenter=function(t,n,e,i,o,u){r.typeOf.number("left",t),r.typeOf.number("right",n),r.typeOf.number("bottom",e),r.typeOf.number("top",i),r.typeOf.number("near",o),r.typeOf.object("result",u);const s=2*o/(n-t),c=2*o/(i-e),a=(n+t)/(n-t),f=(i+e)/(i-e),h=-2*o;return u[0]=s,u[1]=0,u[2]=0,u[3]=0,u[4]=0,u[5]=c,u[6]=0,u[7]=0,u[8]=a,u[9]=f,u[10]=-1,u[11]=-1,u[12]=0,u[13]=0,u[14]=h,u[15]=0,u},Y.computeViewportTransformation=function(t,e,r,i){n(i)||(i=new Y),t=o(t,o.EMPTY_OBJECT);const u=o(t.x,0),s=o(t.y,0),c=o(t.width,0),a=o(t.height,0);e=o(e,0);const f=.5*c,h=.5*a,l=.5*((r=o(r,1))-e),d=f,w=h,m=l,g=u+f,v=s+h,p=e+l;return i[0]=d,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=w,i[6]=0,i[7]=0,i[8]=0,i[9]=0,i[10]=m,i[11]=0,i[12]=g,i[13]=v,i[14]=p,i[15]=1,i},Y.computeView=function(t,n,e,i,o){return r.typeOf.object("position",t),r.typeOf.object("direction",n),r.typeOf.object("up",e),r.typeOf.object("right",i),r.typeOf.object("result",o),o[0]=i.x,o[1]=e.x,o[2]=-n.x,o[3]=0,o[4]=i.y,o[5]=e.y,o[6]=-n.y,o[7]=0,o[8]=i.z,o[9]=e.z,o[10]=-n.z,o[11]=0,o[12]=-m.dot(i,t),o[13]=-m.dot(e,t),o[14]=m.dot(n,t),o[15]=1,o},Y.toArray=function(t,e){return r.typeOf.object("matrix",t),n(e)?(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):[t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]]},Y.getElementIndex=function(t,n){return r.typeOf.number.greaterThanOrEquals("row",n,0),r.typeOf.number.lessThanOrEquals("row",n,3),r.typeOf.number.greaterThanOrEquals("column",t,0),r.typeOf.number.lessThanOrEquals("column",t,3),4*t+n},Y.getColumn=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,3),r.typeOf.object("result",e);const i=4*n,o=t[i],u=t[i+1],s=t[i+2],c=t[i+3];return e.x=o,e.y=u,e.z=s,e.w=c,e},Y.setColumn=function(t,n,e,i){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,3),r.typeOf.object("cartesian",e),r.typeOf.object("result",i);const o=4*n;return(i=Y.clone(t,i))[o]=e.x,i[o+1]=e.y,i[o+2]=e.z,i[o+3]=e.w,i},Y.getRow=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,3),r.typeOf.object("result",e);const i=t[n],o=t[n+4],u=t[n+8],s=t[n+12];return e.x=i,e.y=o,e.z=u,e.w=s,e},Y.setRow=function(t,n,e,i){return r.typeOf.object("matrix",t),r.typeOf.number.greaterThanOrEquals("index",n,0),r.typeOf.number.lessThanOrEquals("index",n,3),r.typeOf.object("cartesian",e),r.typeOf.object("result",i),(i=Y.clone(t,i))[n]=e.x,i[n+4]=e.y,i[n+8]=e.z,i[n+12]=e.w,i},Y.setTranslation=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.object("translation",n),r.typeOf.object("result",e),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]=n.x,e[13]=n.y,e[14]=n.z,e[15]=t[15],e};const J=new m;Y.setScale=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("scale",n),r.typeOf.object("result",e);const i=Y.getScale(t,J),o=n.x/i.x,u=n.y/i.y,s=n.z/i.z;return e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3],e[4]=t[4]*u,e[5]=t[5]*u,e[6]=t[6]*u,e[7]=t[7],e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e};const G=new m;Y.setUniformScale=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.number("scale",n),r.typeOf.object("result",e);const i=Y.getScale(t,G),o=n/i.x,u=n/i.y,s=n/i.z;return e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3],e[4]=t[4]*u,e[5]=t[5]*u,e[6]=t[6]*u,e[7]=t[7],e[8]=t[8]*s,e[9]=t[9]*s,e[10]=t[10]*s,e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e};const X=new m;Y.getScale=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n.x=m.magnitude(m.fromElements(t[0],t[1],t[2],X)),n.y=m.magnitude(m.fromElements(t[4],t[5],t[6],X)),n.z=m.magnitude(m.fromElements(t[8],t[9],t[10],X)),n};const K=new m;Y.getMaximumScale=function(t){return Y.getScale(t,K),m.maximumComponent(K)};const tt=new m;Y.setRotation=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("result",e);const i=Y.getScale(t,tt);return e[0]=n[0]*i.x,e[1]=n[1]*i.x,e[2]=n[2]*i.x,e[3]=t[3],e[4]=n[3]*i.y,e[5]=n[4]*i.y,e[6]=n[5]*i.y,e[7]=t[7],e[8]=n[6]*i.z,e[9]=n[7]*i.z,e[10]=n[8]*i.z,e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e};const nt=new m;Y.getRotation=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=Y.getScale(t,nt);return n[0]=t[0]/e.x,n[1]=t[1]/e.x,n[2]=t[2]/e.x,n[3]=t[4]/e.y,n[4]=t[5]/e.y,n[5]=t[6]/e.y,n[6]=t[8]/e.z,n[7]=t[9]/e.z,n[8]=t[10]/e.z,n},Y.multiply=function(t,n,e){r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e);const i=t[0],o=t[1],u=t[2],s=t[3],c=t[4],a=t[5],f=t[6],h=t[7],l=t[8],d=t[9],w=t[10],m=t[11],g=t[12],v=t[13],p=t[14],y=t[15],b=n[0],M=n[1],A=n[2],x=n[3],E=n[4],k=n[5],q=n[6],$=n[7],S=n[8],I=n[9],O=n[10],R=n[11],P=n[12],j=n[13],F=n[14],N=n[15],U=i*b+c*M+l*A+g*x,T=o*b+a*M+d*A+v*x,z=u*b+f*M+w*A+p*x,C=s*b+h*M+m*A+y*x,D=i*E+c*k+l*q+g*$,B=o*E+a*k+d*q+v*$,L=u*E+f*k+w*q+p*$,_=s*E+h*k+m*q+y*$,V=i*S+c*I+l*O+g*R,H=o*S+a*I+d*O+v*R,Y=u*S+f*I+w*O+p*R,Z=s*S+h*I+m*O+y*R,W=i*P+c*j+l*F+g*N,Q=o*P+a*j+d*F+v*N,J=u*P+f*j+w*F+p*N,G=s*P+h*j+m*F+y*N;return e[0]=U,e[1]=T,e[2]=z,e[3]=C,e[4]=D,e[5]=B,e[6]=L,e[7]=_,e[8]=V,e[9]=H,e[10]=Y,e[11]=Z,e[12]=W,e[13]=Q,e[14]=J,e[15]=G,e},Y.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),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},Y.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),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},Y.multiplyTransformation=function(t,n,e){r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e);const i=t[0],o=t[1],u=t[2],s=t[4],c=t[5],a=t[6],f=t[8],h=t[9],l=t[10],d=t[12],w=t[13],m=t[14],g=n[0],v=n[1],p=n[2],y=n[4],b=n[5],M=n[6],A=n[8],x=n[9],E=n[10],k=n[12],q=n[13],$=n[14],S=i*g+s*v+f*p,I=o*g+c*v+h*p,O=u*g+a*v+l*p,R=i*y+s*b+f*M,P=o*y+c*b+h*M,j=u*y+a*b+l*M,F=i*A+s*x+f*E,N=o*A+c*x+h*E,U=u*A+a*x+l*E,T=i*k+s*q+f*$+d,z=o*k+c*q+h*$+w,C=u*k+a*q+l*$+m;return e[0]=S,e[1]=I,e[2]=O,e[3]=0,e[4]=R,e[5]=P,e[6]=j,e[7]=0,e[8]=F,e[9]=N,e[10]=U,e[11]=0,e[12]=T,e[13]=z,e[14]=C,e[15]=1,e},Y.multiplyByMatrix3=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("rotation",n),r.typeOf.object("result",e);const i=t[0],o=t[1],u=t[2],s=t[4],c=t[5],a=t[6],f=t[8],h=t[9],l=t[10],d=n[0],w=n[1],m=n[2],g=n[3],v=n[4],p=n[5],y=n[6],b=n[7],M=n[8],A=i*d+s*w+f*m,x=o*d+c*w+h*m,E=u*d+a*w+l*m,k=i*g+s*v+f*p,q=o*g+c*v+h*p,$=u*g+a*v+l*p,S=i*y+s*b+f*M,I=o*y+c*b+h*M,O=u*y+a*b+l*M;return e[0]=A,e[1]=x,e[2]=E,e[3]=0,e[4]=k,e[5]=q,e[6]=$,e[7]=0,e[8]=S,e[9]=I,e[10]=O,e[11]=0,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},Y.multiplyByTranslation=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("translation",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z,s=i*t[0]+o*t[4]+u*t[8]+t[12],c=i*t[1]+o*t[5]+u*t[9]+t[13],a=i*t[2]+o*t[6]+u*t[10]+t[14];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]=s,e[13]=c,e[14]=a,e[15]=t[15],e},Y.multiplyByScale=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("scale",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z;return 1===i&&1===o&&1===u?Y.clone(t,e):(e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=t[3],e[4]=o*t[4],e[5]=o*t[5],e[6]=o*t[6],e[7]=t[7],e[8]=u*t[8],e[9]=u*t[9],e[10]=u*t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e)},Y.multiplyByUniformScale=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.number("scale",n),r.typeOf.object("result",e),e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3],e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7],e[8]=t[8]*n,e[9]=t[9]*n,e[10]=t[10]*n,e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},Y.multiplyByVector=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("cartesian",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z,s=n.w,c=t[0]*i+t[4]*o+t[8]*u+t[12]*s,a=t[1]*i+t[5]*o+t[9]*u+t[13]*s,f=t[2]*i+t[6]*o+t[10]*u+t[14]*s,h=t[3]*i+t[7]*o+t[11]*u+t[15]*s;return e.x=c,e.y=a,e.z=f,e.w=h,e},Y.multiplyByPointAsVector=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("cartesian",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z,s=t[0]*i+t[4]*o+t[8]*u,c=t[1]*i+t[5]*o+t[9]*u,a=t[2]*i+t[6]*o+t[10]*u;return e.x=s,e.y=c,e.z=a,e},Y.multiplyByPoint=function(t,n,e){r.typeOf.object("matrix",t),r.typeOf.object("cartesian",n),r.typeOf.object("result",e);const i=n.x,o=n.y,u=n.z,s=t[0]*i+t[4]*o+t[8]*u+t[12],c=t[1]*i+t[5]*o+t[9]*u+t[13],a=t[2]*i+t[6]*o+t[10]*u+t[14];return e.x=s,e.y=c,e.z=a,e},Y.multiplyByScalar=function(t,n,e){return r.typeOf.object("matrix",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),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},Y.negate=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n[0]=-t[0],n[1]=-t[1],n[2]=-t[2],n[3]=-t[3],n[4]=-t[4],n[5]=-t[5],n[6]=-t[6],n[7]=-t[7],n[8]=-t[8],n[9]=-t[9],n[10]=-t[10],n[11]=-t[11],n[12]=-t[12],n[13]=-t[13],n[14]=-t[14],n[15]=-t[15],n},Y.transpose=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=t[1],i=t[2],o=t[3],u=t[6],s=t[7],c=t[11];return n[0]=t[0],n[1]=t[4],n[2]=t[8],n[3]=t[12],n[4]=e,n[5]=t[5],n[6]=t[9],n[7]=t[13],n[8]=i,n[9]=u,n[10]=t[10],n[11]=t[14],n[12]=o,n[13]=s,n[14]=c,n[15]=t[15],n},Y.abs=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n[0]=Math.abs(t[0]),n[1]=Math.abs(t[1]),n[2]=Math.abs(t[2]),n[3]=Math.abs(t[3]),n[4]=Math.abs(t[4]),n[5]=Math.abs(t[5]),n[6]=Math.abs(t[6]),n[7]=Math.abs(t[7]),n[8]=Math.abs(t[8]),n[9]=Math.abs(t[9]),n[10]=Math.abs(t[10]),n[11]=Math.abs(t[11]),n[12]=Math.abs(t[12]),n[13]=Math.abs(t[13]),n[14]=Math.abs(t[14]),n[15]=Math.abs(t[15]),n},Y.equals=function(t,e){return t===e||n(t)&&n(e)&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[3]===e[3]&&t[7]===e[7]&&t[11]===e[11]&&t[15]===e[15]},Y.equalsEpsilon=function(t,e,r){return r=o(r,0),t===e||n(t)&&n(e)&&Math.abs(t[0]-e[0])<=r&&Math.abs(t[1]-e[1])<=r&&Math.abs(t[2]-e[2])<=r&&Math.abs(t[3]-e[3])<=r&&Math.abs(t[4]-e[4])<=r&&Math.abs(t[5]-e[5])<=r&&Math.abs(t[6]-e[6])<=r&&Math.abs(t[7]-e[7])<=r&&Math.abs(t[8]-e[8])<=r&&Math.abs(t[9]-e[9])<=r&&Math.abs(t[10]-e[10])<=r&&Math.abs(t[11]-e[11])<=r&&Math.abs(t[12]-e[12])<=r&&Math.abs(t[13]-e[13])<=r&&Math.abs(t[14]-e[14])<=r&&Math.abs(t[15]-e[15])<=r},Y.getTranslation=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n.x=t[12],n.y=t[13],n.z=t[14],n},Y.getMatrix3=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[4],n[4]=t[5],n[5]=t[6],n[6]=t[8],n[7]=t[9],n[8]=t[10],n};const et=new R,rt=new R,it=new x,ot=new x(0,0,0,1);Y.inverse=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=t[0],i=t[4],o=t[8],u=t[12],s=t[1],c=t[5],a=t[9],f=t[13],h=t[2],d=t[6],w=t[10],m=t[14],g=t[3],v=t[7],p=t[11],y=t[15];let b=w*y,M=m*p,A=d*y,E=m*v,k=d*p,q=w*v,$=h*y,S=m*g,I=h*p,O=w*g,P=h*v,j=d*g;const F=b*c+E*a+k*f-(M*c+A*a+q*f),N=M*s+$*a+O*f-(b*s+S*a+I*f),U=A*s+S*c+P*f-(E*s+$*c+j*f),T=q*s+I*c+j*a-(k*s+O*c+P*a),z=M*i+A*o+q*u-(b*i+E*o+k*u),C=b*e+S*o+I*u-(M*e+$*o+O*u),D=E*e+$*i+j*u-(A*e+S*i+P*u),B=k*e+O*i+P*o-(q*e+I*i+j*o);b=o*f,M=u*a,A=i*f,E=u*c,k=i*a,q=o*c,$=e*f,S=u*s,I=e*a,O=o*s,P=e*c,j=i*s;const L=b*v+E*p+k*y-(M*v+A*p+q*y),_=M*g+$*p+O*y-(b*g+S*p+I*y),V=A*g+S*v+P*y-(E*g+$*v+j*y),Z=q*g+I*v+j*p-(k*g+O*v+P*p),W=A*w+q*m+M*d-(k*m+b*d+E*w),Q=I*m+b*h+S*w-($*w+O*m+M*h),J=$*d+j*m+E*h-(P*m+A*h+S*d),G=P*w+k*h+O*d-(I*d+j*w+q*h);let X=e*F+i*N+o*U+u*T;if(Math.abs(X)<l.EPSILON21){if(R.equalsEpsilon(Y.getMatrix3(t,et),rt,l.EPSILON7)&&x.equals(Y.getRow(t,3,it),ot))return n[0]=0,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=0,n[6]=0,n[7]=0,n[8]=0,n[9]=0,n[10]=0,n[11]=0,n[12]=-t[12],n[13]=-t[13],n[14]=-t[14],n[15]=1,n;throw new H("matrix is not invertible because its determinate is zero.")}return X=1/X,n[0]=F*X,n[1]=N*X,n[2]=U*X,n[3]=T*X,n[4]=z*X,n[5]=C*X,n[6]=D*X,n[7]=B*X,n[8]=L*X,n[9]=_*X,n[10]=V*X,n[11]=Z*X,n[12]=W*X,n[13]=Q*X,n[14]=J*X,n[15]=G*X,n},Y.inverseTransformation=function(t,n){r.typeOf.object("matrix",t),r.typeOf.object("result",n);const e=t[0],i=t[1],o=t[2],u=t[4],s=t[5],c=t[6],a=t[8],f=t[9],h=t[10],l=t[12],d=t[13],w=t[14],m=-e*l-i*d-o*w,g=-u*l-s*d-c*w,v=-a*l-f*d-h*w;return n[0]=e,n[1]=u,n[2]=a,n[3]=0,n[4]=i,n[5]=s,n[6]=f,n[7]=0,n[8]=o,n[9]=c,n[10]=h,n[11]=0,n[12]=m,n[13]=g,n[14]=v,n[15]=1,n};const ut=new Y;let st;Y.inverseTranspose=function(t,n){return r.typeOf.object("matrix",t),r.typeOf.object("result",n),Y.inverse(Y.transpose(t,ut),n)},Y.IDENTITY=Object.freeze(new Y(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)),Y.ZERO=Object.freeze(new Y(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)),Y.COLUMN0ROW0=0,Y.COLUMN0ROW1=1,Y.COLUMN0ROW2=2,Y.COLUMN0ROW3=3,Y.COLUMN1ROW0=4,Y.COLUMN1ROW1=5,Y.COLUMN1ROW2=6,Y.COLUMN1ROW3=7,Y.COLUMN2ROW0=8,Y.COLUMN2ROW1=9,Y.COLUMN2ROW2=10,Y.COLUMN2ROW3=11,Y.COLUMN3ROW0=12,Y.COLUMN3ROW1=13,Y.COLUMN3ROW2=14,Y.COLUMN3ROW3=15,Object.defineProperties(Y.prototype,{length:{get:function(){return Y.packedLength}}}),Y.prototype.clone=function(t){return Y.clone(this,t)},Y.prototype.equals=function(t){return Y.equals(this,t)},Y.equalsArray=function(t,n,e){return t[0]===n[e]&&t[1]===n[e+1]&&t[2]===n[e+2]&&t[3]===n[e+3]&&t[4]===n[e+4]&&t[5]===n[e+5]&&t[6]===n[e+6]&&t[7]===n[e+7]&&t[8]===n[e+8]&&t[9]===n[e+9]&&t[10]===n[e+10]&&t[11]===n[e+11]&&t[12]===n[e+12]&&t[13]===n[e+13]&&t[14]===n[e+14]&&t[15]===n[e+15]},Y.prototype.equalsEpsilon=function(t,n){return Y.equalsEpsilon(this,t,n)},Y.prototype.toString=function(){return`(${this[0]}, ${this[4]}, ${this[8]}, ${this[12]})\\n(${this[1]}, ${this[5]}, ${this[9]}, ${this[13]})\\n(${this[2]}, ${this[6]}, ${this[10]}, ${this[14]})\\n(${this[3]}, ${this[7]}, ${this[11]}, ${this[15]})`};const ct={requestFullscreen:void 0,exitFullscreen:void 0,fullscreenEnabled:void 0,fullscreenElement:void 0,fullscreenchange:void 0,fullscreenerror:void 0},at={};let ft,ht,lt,dt,wt,mt,gt,vt,pt,yt,bt,Mt,At,xt,Et,kt,qt,$t;function St(t){const n=t.split(".");for(let t=0,e=n.length;t<e;++t)n[t]=parseInt(n[t],10);return n}function It(){if(!n(ht)&&(ht=!1,!jt())){const t=/ Chrome\\/([\\.0-9]+)/.exec(ft.userAgent);null!==t&&(ht=!0,lt=St(t[1]))}return ht}function Ot(){if(!n(dt)&&(dt=!1,!It()&&!jt()&&/ Safari\\/[\\.0-9]+/.test(ft.userAgent))){const t=/ Version\\/([\\.0-9]+)/.exec(ft.userAgent);null!==t&&(dt=!0,wt=St(t[1]))}return dt}function Rt(){if(!n(mt)){mt=!1;const t=/ AppleWebKit\\/([\\.0-9]+)(\\+?)/.exec(ft.userAgent);null!==t&&(mt=!0,gt=St(t[1]),gt.isNightly=!!t[2])}return mt}function Pt(){if(!n(vt)){let t;vt=!1,"Microsoft Internet Explorer"===ft.appName?(t=/MSIE ([0-9]{1,}[\\.0-9]{0,})/.exec(ft.userAgent),null!==t&&(vt=!0,pt=St(t[1]))):"Netscape"===ft.appName&&(t=/Trident\\/.*rv:([0-9]{1,}[\\.0-9]{0,})/.exec(ft.userAgent),null!==t&&(vt=!0,pt=St(t[1])))}return vt}function jt(){if(!n(yt)){yt=!1;const t=/ Edg\\/([\\.0-9]+)/.exec(ft.userAgent);null!==t&&(yt=!0,bt=St(t[1]))}return yt}function Ft(){if(!n(Mt)){Mt=!1;const t=/Firefox\\/([\\.0-9]+)/.exec(ft.userAgent);null!==t&&(Mt=!0,At=St(t[1]))}return Mt}function Nt(){if(!n($t)){const t=document.createElement("canvas");t.setAttribute("style","image-rendering: -moz-crisp-edges;image-rendering: pixelated;");const e=t.style.imageRendering;$t=n(e)&&""!==e,$t&&(qt=e)}return $t}function Ut(){if(!Ut.initialized)throw new e("You must call FeatureDetection.supportsWebP.initialize and wait for the promise to resolve before calling FeatureDetection.supportsWebP");return Ut.u}Object.defineProperties(at,{element:{get:function(){if(at.supportsFullscreen())return document[ct.fullscreenElement]}},changeEventName:{get:function(){if(at.supportsFullscreen())return ct.fullscreenchange}},errorEventName:{get:function(){if(at.supportsFullscreen())return ct.fullscreenerror}},enabled:{get:function(){if(at.supportsFullscreen())return document[ct.fullscreenEnabled]}},fullscreen:{get:function(){if(at.supportsFullscreen())return null!==at.element}}}),at.supportsFullscreen=function(){if(n(st))return st;st=!1;const t=document.body;if("function"==typeof t.requestFullscreen)return ct.requestFullscreen="requestFullscreen",ct.exitFullscreen="exitFullscreen",ct.fullscreenEnabled="fullscreenEnabled",ct.fullscreenElement="fullscreenElement",ct.fullscreenchange="fullscreenchange",ct.fullscreenerror="fullscreenerror",st=!0,st;const e=["webkit","moz","o","ms","khtml"];let r;for(let n=0,i=e.length;n<i;++n){const i=e[n];r=`${i}RequestFullscreen`,"function"==typeof t[r]?(ct.requestFullscreen=r,st=!0):(r=`${i}RequestFullScreen`,"function"==typeof t[r]&&(ct.requestFullscreen=r,st=!0)),r=`${i}ExitFullscreen`,"function"==typeof document[r]?ct.exitFullscreen=r:(r=`${i}CancelFullScreen`,"function"==typeof document[r]&&(ct.exitFullscreen=r)),r=`${i}FullscreenEnabled`,void 0!==document[r]?ct.fullscreenEnabled=r:(r=`${i}FullScreenEnabled`,void 0!==document[r]&&(ct.fullscreenEnabled=r)),r=`${i}FullscreenElement`,void 0!==document[r]?ct.fullscreenElement=r:(r=`${i}FullScreenElement`,void 0!==document[r]&&(ct.fullscreenElement=r)),r=`${i}fullscreenchange`,void 0!==document[`on${r}`]&&("ms"===i&&(r="MSFullscreenChange"),ct.fullscreenchange=r),r=`${i}fullscreenerror`,void 0!==document[`on${r}`]&&("ms"===i&&(r="MSFullscreenError"),ct.fullscreenerror=r)}return st},at.requestFullscreen=function(t,n){at.supportsFullscreen()&&t[ct.requestFullscreen]({vrDisplay:n})},at.exitFullscreen=function(){at.supportsFullscreen()&&document[ct.exitFullscreen]()},at.h=ct,ft="undefined"!=typeof navigator?navigator:{},Ut.l=void 0,Ut.u=void 0,Ut.initialize=function(){return n(Ut.l)||(Ut.l=new Promise((t=>{const n=new Image;n.onload=function(){Ut.u=n.width>0&&n.height>0,t(Ut.u)},n.onerror=function(){Ut.u=!1,t(Ut.u)},n.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA"}))),Ut.l},Object.defineProperties(Ut,{initialized:{get:function(){return n(Ut.u)}}});const Tt=[];"undefined"!=typeof ArrayBuffer&&(Tt.push(Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array),"undefined"!=typeof Uint8ClampedArray&&Tt.push(Uint8ClampedArray),"undefined"!=typeof Uint8ClampedArray&&Tt.push(Uint8ClampedArray),"undefined"!=typeof BigInt64Array&&Tt.push(BigInt64Array),"undefined"!=typeof BigUint64Array&&Tt.push(BigUint64Array));const zt={isChrome:It,chromeVersion:function(){return It()&<},isSafari:Ot,safariVersion:function(){return Ot()&&wt},isWebkit:Rt,webkitVersion:function(){return Rt()&>},isInternetExplorer:Pt,internetExplorerVersion:function(){return Pt()&&pt},isEdge:jt,edgeVersion:function(){return jt()&&bt},isFirefox:Ft,firefoxVersion:function(){return Ft()&&At},isWindows:function(){return n(xt)||(xt=/Windows/i.test(ft.appVersion)),xt},isIPadOrIOS:function(){return n(Et)||(Et="iPhone"===navigator.platform||"iPod"===navigator.platform||"iPad"===navigator.platform),Et},hardwareConcurrency:o(ft.hardwareConcurrency,3),supportsPointerEvents:function(){return n(kt)||(kt=!Ft()&&"undefined"!=typeof PointerEvent&&(!n(ft.pointerEnabled)||ft.pointerEnabled)),kt},supportsImageRenderingPixelated:Nt,supportsWebP:Ut,imageRenderingValue:function(){return Nt()?qt:void 0},typedArrayTypes:Tt};function Ct(t,n){this.x=o(t,0),this.y=o(n,0)}zt.supportsBasis=function(t){return zt.supportsWebAssembly()&&t.context.supportsBasis},zt.supportsFullscreen=function(){return at.supportsFullscreen()},zt.supportsTypedArrays=function(){return"undefined"!=typeof ArrayBuffer},zt.supportsBigInt64Array=function(){return"undefined"!=typeof BigInt64Array},zt.supportsBigUint64Array=function(){return"undefined"!=typeof BigUint64Array},zt.supportsBigInt=function(){return"undefined"!=typeof BigInt},zt.supportsWebWorkers=function(){return"undefined"!=typeof Worker},zt.supportsWebAssembly=function(){return"undefined"!=typeof WebAssembly},zt.supportsWebgl2=function(t){return r.defined("scene",t),t.context.webgl2},zt.supportsEsmWebWorkers=function(){return!Ft()||parseInt(At)>=114},Ct.fromElements=function(t,e,r){return n(r)?(r.x=t,r.y=e,r):new Ct(t,e)},Ct.clone=function(t,e){if(n(t))return n(e)?(e.x=t.x,e.y=t.y,e):new Ct(t.x,t.y)},Ct.fromCartesian3=Ct.clone,Ct.fromCartesian4=Ct.clone,Ct.packedLength=2,Ct.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t.x,n[e]=t.y,n},Ct.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new Ct),i.x=t[e++],i.y=t[e],i},Ct.packArray=function(t,i){r.defined("array",t);const o=t.length,u=2*o;if(n(i)){if(!Array.isArray(i)&&i.length!==u)throw new e("If result is a typed array, it must have exactly array.length * 2 elements");i.length!==u&&(i.length=u)}else i=new Array(u);for(let n=0;n<o;++n)Ct.pack(t[n],i,2*n);return i},Ct.unpackArray=function(t,i){if(r.defined("array",t),r.typeOf.number.greaterThanOrEquals("array.length",t.length,2),t.length%2!=0)throw new e("array length must be a multiple of 2.");const o=t.length;n(i)?i.length=o/2:i=new Array(o/2);for(let n=0;n<o;n+=2){const e=n/2;i[e]=Ct.unpack(t,n,i[e])}return i},Ct.fromArray=Ct.unpack,Ct.maximumComponent=function(t){return r.typeOf.object("cartesian",t),Math.max(t.x,t.y)},Ct.minimumComponent=function(t){return r.typeOf.object("cartesian",t),Math.min(t.x,t.y)},Ct.minimumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.min(t.x,n.x),e.y=Math.min(t.y,n.y),e},Ct.maximumByComponent=function(t,n,e){return r.typeOf.object("first",t),r.typeOf.object("second",n),r.typeOf.object("result",e),e.x=Math.max(t.x,n.x),e.y=Math.max(t.y,n.y),e},Ct.clamp=function(t,n,e,i){r.typeOf.object("value",t),r.typeOf.object("min",n),r.typeOf.object("max",e),r.typeOf.object("result",i);const o=l.clamp(t.x,n.x,e.x),u=l.clamp(t.y,n.y,e.y);return i.x=o,i.y=u,i},Ct.magnitudeSquared=function(t){return r.typeOf.object("cartesian",t),t.x*t.x+t.y*t.y},Ct.magnitude=function(t){return Math.sqrt(Ct.magnitudeSquared(t))};const Dt=new Ct;Ct.distance=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),Ct.subtract(t,n,Dt),Ct.magnitude(Dt)},Ct.distanceSquared=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),Ct.subtract(t,n,Dt),Ct.magnitudeSquared(Dt)},Ct.normalize=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const i=Ct.magnitude(t);if(n.x=t.x/i,n.y=t.y/i,isNaN(n.x)||isNaN(n.y))throw new e("normalized result is not a number");return n},Ct.dot=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),t.x*n.x+t.y*n.y},Ct.cross=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),t.x*n.y-t.y*n.x},Ct.multiplyComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x*n.x,e.y=t.y*n.y,e},Ct.divideComponents=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x/n.x,e.y=t.y/n.y,e},Ct.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x+n.x,e.y=t.y+n.y,e},Ct.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x-n.x,e.y=t.y-n.y,e},Ct.multiplyByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x*n,e.y=t.y*n,e},Ct.divideByScalar=function(t,n,e){return r.typeOf.object("cartesian",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x/n,e.y=t.y/n,e},Ct.negate=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=-t.x,n.y=-t.y,n},Ct.abs=function(t,n){return r.typeOf.object("cartesian",t),r.typeOf.object("result",n),n.x=Math.abs(t.x),n.y=Math.abs(t.y),n};const Bt=new Ct;Ct.lerp=function(t,n,e,i){return r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i),Ct.multiplyByScalar(n,e,Bt),i=Ct.multiplyByScalar(t,1-e,i),Ct.add(Bt,i,i)};const Lt=new Ct,_t=new Ct;Ct.angleBetween=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),Ct.normalize(t,Lt),Ct.normalize(n,_t),l.acosClamped(Ct.dot(Lt,_t))};const Vt=new Ct;Ct.mostOrthogonalAxis=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const e=Ct.normalize(t,Vt);return Ct.abs(e,e),e.x<=e.y?Ct.clone(Ct.UNIT_X,n):Ct.clone(Ct.UNIT_Y,n)},Ct.equals=function(t,e){return t===e||n(t)&&n(e)&&t.x===e.x&&t.y===e.y},Ct.equalsArray=function(t,n,e){return t.x===n[e]&&t.y===n[e+1]},Ct.equalsEpsilon=function(t,e,r,i){return t===e||n(t)&&n(e)&&l.equalsEpsilon(t.x,e.x,r,i)&&l.equalsEpsilon(t.y,e.y,r,i)},Ct.ZERO=Object.freeze(new Ct(0,0)),Ct.ONE=Object.freeze(new Ct(1,1)),Ct.UNIT_X=Object.freeze(new Ct(1,0)),Ct.UNIT_Y=Object.freeze(new Ct(0,1)),Ct.prototype.clone=function(t){return Ct.clone(this,t)},Ct.prototype.equals=function(t){return Ct.equals(this,t)},Ct.prototype.equalsEpsilon=function(t,n,e){return Ct.equalsEpsilon(this,t,n,e)},Ct.prototype.toString=function(){return`(${this.x}, ${this.y})`};const Ht=new m,Yt=new m;function Zt(t,r,i,o,u){if(!n(t))throw new e("cartesian is required.");if(!n(r))throw new e("oneOverRadii is required.");if(!n(i))throw new e("oneOverRadiiSquared is required.");if(!n(o))throw new e("centerToleranceSquared is required.");const s=t.x,c=t.y,a=t.z,f=r.x,h=r.y,d=r.z,w=s*s*f*f,g=c*c*h*h,v=a*a*d*d,p=w+g+v,y=Math.sqrt(1/p),b=m.multiplyByScalar(t,y,Ht);if(p<o)return isFinite(y)?m.clone(b,u):void 0;const M=i.x,A=i.y,x=i.z,E=Yt;E.x=b.x*M*2,E.y=b.y*A*2,E.z=b.z*x*2;let k,q,$,S,I,O,R,P,j,F,N,U=(1-y)*m.magnitude(t)/(.5*m.magnitude(E)),T=0;do{U-=T,$=1/(1+U*M),S=1/(1+U*A),I=1/(1+U*x),O=$*$,R=S*S,P=I*I,j=O*$,F=R*S,N=P*I,k=w*O+g*R+v*P-1,q=w*j*M+g*F*A+v*N*x,T=k/(-2*q)}while(Math.abs(k)>l.EPSILON12);return n(u)?(u.x=s*$,u.y=c*S,u.z=a*I,u):new m(s*$,c*S,a*I)}function Wt(t,n,e){this.longitude=o(t,0),this.latitude=o(n,0),this.height=o(e,0)}Wt.fromRadians=function(t,e,i,u){return r.typeOf.number("longitude",t),r.typeOf.number("latitude",e),i=o(i,0),n(u)?(u.longitude=t,u.latitude=e,u.height=i,u):new Wt(t,e,i)},Wt.fromDegrees=function(t,n,e,i){return r.typeOf.number("longitude",t),r.typeOf.number("latitude",n),t=l.toRadians(t),n=l.toRadians(n),Wt.fromRadians(t,n,e,i)};const Qt=new m,Jt=new m,Gt=new m;function Xt(t,n,e,i){n=o(n,0),e=o(e,0),i=o(i,0),r.typeOf.number.greaterThanOrEquals("x",n,0),r.typeOf.number.greaterThanOrEquals("y",e,0),r.typeOf.number.greaterThanOrEquals("z",i,0),t.m=new m(n,e,i),t.v=new m(n*n,e*e,i*i),t.p=new m(n*n*n*n,e*e*e*e,i*i*i*i),t.A=new m(0===n?0:1/n,0===e?0:1/e,0===i?0:1/i),t.k=new m(0===n?0:1/(n*n),0===e?0:1/(e*e),0===i?0:1/(i*i)),t.q=Math.min(n,e,i),t.$=Math.max(n,e,i),t.S=l.EPSILON1,0!==t.v.z&&(t.I=t.v.x/t.v.z)}function Kt(t,n,e){this.m=void 0,this.v=void 0,this.p=void 0,this.A=void 0,this.k=void 0,this.q=void 0,this.$=void 0,this.S=void 0,this.I=void 0,Xt(this,t,n,e)}Wt.O=new m(1/6378137,1/6378137,1/6356752.314245179),Wt.R=new m(1/40680631590769,1/40680631590769,1/40408299984661.445),Wt.P=l.EPSILON1,Wt.fromCartesian=function(t,e,r){const i=n(e)?e.oneOverRadii:Wt.O,o=n(e)?e.oneOverRadiiSquared:Wt.R,u=Zt(t,i,o,n(e)?e.S:Wt.P,Jt);if(!n(u))return;let s=m.multiplyComponents(u,o,Qt);s=m.normalize(s,s);const c=m.subtract(t,u,Gt),a=Math.atan2(s.y,s.x),f=Math.asin(s.z),h=l.sign(m.dot(c,t))*m.magnitude(c);return n(r)?(r.longitude=a,r.latitude=f,r.height=h,r):new Wt(a,f,h)},Wt.toCartesian=function(t,n,e){return r.defined("cartographic",t),m.fromRadians(t.longitude,t.latitude,t.height,n,e)},Wt.clone=function(t,e){if(n(t))return n(e)?(e.longitude=t.longitude,e.latitude=t.latitude,e.height=t.height,e):new Wt(t.longitude,t.latitude,t.height)},Wt.equals=function(t,e){return t===e||n(t)&&n(e)&&t.longitude===e.longitude&&t.latitude===e.latitude&&t.height===e.height},Wt.equalsEpsilon=function(t,e,r){return r=o(r,0),t===e||n(t)&&n(e)&&Math.abs(t.longitude-e.longitude)<=r&&Math.abs(t.latitude-e.latitude)<=r&&Math.abs(t.height-e.height)<=r},Wt.ZERO=Object.freeze(new Wt(0,0,0)),Wt.prototype.clone=function(t){return Wt.clone(this,t)},Wt.prototype.equals=function(t){return Wt.equals(this,t)},Wt.prototype.equalsEpsilon=function(t,n){return Wt.equalsEpsilon(this,t,n)},Wt.prototype.toString=function(){return`(${this.longitude}, ${this.latitude}, ${this.height})`},Object.defineProperties(Kt.prototype,{radii:{get:function(){return this.m}},radiiSquared:{get:function(){return this.v}},radiiToTheFourth:{get:function(){return this.p}},oneOverRadii:{get:function(){return this.A}},oneOverRadiiSquared:{get:function(){return this.k}},minimumRadius:{get:function(){return this.q}},maximumRadius:{get:function(){return this.$}}}),Kt.clone=function(t,e){if(!n(t))return;const r=t.m;return n(e)?(m.clone(r,e.m),m.clone(t.v,e.v),m.clone(t.p,e.p),m.clone(t.A,e.A),m.clone(t.k,e.k),e.q=t.q,e.$=t.$,e.S=t.S,e):new Kt(r.x,r.y,r.z)},Kt.fromCartesian3=function(t,e){return n(e)||(e=new Kt),n(t)?(Xt(e,t.x,t.y,t.z),e):e},Kt.WGS84=Object.freeze(new Kt(6378137,6378137,6356752.314245179)),Kt.UNIT_SPHERE=Object.freeze(new Kt(1,1,1)),Kt.MOON=Object.freeze(new Kt(l.LUNAR_RADIUS,l.LUNAR_RADIUS,l.LUNAR_RADIUS)),Kt.j=Kt.WGS84,Object.defineProperties(Kt,{default:{get:function(){return Kt.j},set:function(t){r.typeOf.object("value",t),Kt.j=t,m.o=t.radiiSquared,Wt.O=t.oneOverRadii,Wt.R=t.oneOverRadiiSquared,Wt.P=t.S}}}),Kt.prototype.clone=function(t){return Kt.clone(this,t)},Kt.packedLength=m.packedLength,Kt.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),m.pack(t.m,n,e),n},Kt.unpack=function(t,n,e){r.defined("array",t),n=o(n,0);const i=m.unpack(t,n);return Kt.fromCartesian3(i,e)},Kt.prototype.geocentricSurfaceNormal=m.normalize,Kt.prototype.geodeticSurfaceNormalCartographic=function(t,e){r.typeOf.object("cartographic",t);const i=t.longitude,o=t.latitude,u=Math.cos(o),s=u*Math.cos(i),c=u*Math.sin(i),a=Math.sin(o);return n(e)||(e=new m),e.x=s,e.y=c,e.z=a,m.normalize(e,e)},Kt.prototype.geodeticSurfaceNormal=function(t,i){if(r.typeOf.object("cartesian",t),isNaN(t.x)||isNaN(t.y)||isNaN(t.z))throw new e("cartesian has a NaN component");if(!m.equalsEpsilon(t,m.ZERO,l.EPSILON14))return n(i)||(i=new m),i=m.multiplyComponents(t,this.k,i),m.normalize(i,i)};const tn=new m,nn=new m;Kt.prototype.cartographicToCartesian=function(t,e){const r=tn,i=nn;this.geodeticSurfaceNormalCartographic(t,r),m.multiplyComponents(this.v,r,i);const o=Math.sqrt(m.dot(r,i));return m.divideByScalar(i,o,i),m.multiplyByScalar(r,t.height,r),n(e)||(e=new m),m.add(i,r,e)},Kt.prototype.cartographicArrayToCartesianArray=function(t,e){r.defined("cartographics",t);const i=t.length;n(e)?e.length=i:e=new Array(i);for(let n=0;n<i;n++)e[n]=this.cartographicToCartesian(t[n],e[n]);return e};const en=new m,rn=new m,on=new m;Kt.prototype.cartesianToCartographic=function(t,e){const r=this.scaleToGeodeticSurface(t,rn);if(!n(r))return;const i=this.geodeticSurfaceNormal(r,en),o=m.subtract(t,r,on),u=Math.atan2(i.y,i.x),s=Math.asin(i.z),c=l.sign(m.dot(o,t))*m.magnitude(o);return n(e)?(e.longitude=u,e.latitude=s,e.height=c,e):new Wt(u,s,c)},Kt.prototype.cartesianArrayToCartographicArray=function(t,e){r.defined("cartesians",t);const i=t.length;n(e)?e.length=i:e=new Array(i);for(let n=0;n<i;++n)e[n]=this.cartesianToCartographic(t[n],e[n]);return e},Kt.prototype.scaleToGeodeticSurface=function(t,n){return Zt(t,this.A,this.k,this.S,n)},Kt.prototype.scaleToGeocentricSurface=function(t,e){r.typeOf.object("cartesian",t),n(e)||(e=new m);const i=t.x,o=t.y,u=t.z,s=this.k,c=1/Math.sqrt(i*i*s.x+o*o*s.y+u*u*s.z);return m.multiplyByScalar(t,c,e)},Kt.prototype.transformPositionToScaledSpace=function(t,e){return n(e)||(e=new m),m.multiplyComponents(t,this.A,e)},Kt.prototype.transformPositionFromScaledSpace=function(t,e){return n(e)||(e=new m),m.multiplyComponents(t,this.m,e)},Kt.prototype.equals=function(t){return this===t||n(t)&&m.equals(this.m,t.m)},Kt.prototype.toString=function(){return this.m.toString()},Kt.prototype.getSurfaceNormalIntersectionWithZAxis=function(t,i,u){if(r.typeOf.object("position",t),!l.equalsEpsilon(this.m.x,this.m.y,l.EPSILON15))throw new e("Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)");r.typeOf.number.greaterThan("Ellipsoid.radii.z",this.m.z,0),i=o(i,0);const s=this.I;if(n(u)||(u=new m),u.x=0,u.y=0,u.z=t.z*(1-s),!(Math.abs(u.z)>=this.m.z-i))return u};const un=new m;Kt.prototype.getLocalCurvature=function(t,e){r.typeOf.object("surfacePosition",t),n(e)||(e=new Ct);const i=this.getSurfaceNormalIntersectionWithZAxis(t,0,un),o=m.distance(t,i),u=o*(this.minimumRadius*o/this.maximumRadius**2)**2;return Ct.fromElements(1/o,1/u,e)};const sn=[.14887433898163,.43339539412925,.67940956829902,.86506336668898,.97390652851717,0],cn=[.29552422471475,.26926671930999,.21908636251598,.14945134915058,.066671344308684,0];function an(t,n,e){r.typeOf.number("a",t),r.typeOf.number("b",n),r.typeOf.func("func",e);const i=.5*(n+t),o=.5*(n-t);let u=0;for(let t=0;t<5;t++){const n=o*sn[t];u+=cn[t]*(e(i+n)+e(i-n))}return u*=o,u}function fn(t,n,e){r.defined("array",t),r.defined("itemToFind",n),r.defined("comparator",e);let i,o,u=0,s=t.length-1;for(;u<=s;)if(i=~~((u+s)/2),o=e(t[i],n),o<0)u=i+1;else{if(!(o>0))return i;s=i-1}return~(s+1)}function hn(t,n,e,r,i){this.xPoleWander=t,this.yPoleWander=n,this.xPoleOffset=e,this.yPoleOffset=r,this.ut1MinusUtc=i}function ln(t){if(null===t||isNaN(t))throw new e("year is required and must be a number.");return t%4==0&&t%100!=0||t%400==0}Kt.prototype.surfaceArea=function(t){r.typeOf.object("rectangle",t);const n=t.west;let e=t.east;const i=t.south,o=t.north;for(;e<n;)e+=l.TWO_PI;const u=this.v,s=u.x,c=u.y,a=u.z,f=s*c;return an(i,o,(function(t){const r=Math.cos(t),i=Math.sin(t);return Math.cos(t)*an(n,e,(function(t){const n=Math.cos(t),e=Math.sin(t);return Math.sqrt(f*i*i+a*(c*n*n+s*e*e)*r*r)}))}))};const dn=[31,28,31,30,31,30,31,31,30,31,30,31];function wn(t,n,i,u,s,c,a,f){t=o(t,1),n=o(n,1),i=o(i,1),u=o(u,0),s=o(s,0),c=o(c,0),a=o(a,0),f=o(f,!1),r.typeOf.number.greaterThanOrEquals("Year",t,1),r.typeOf.number.lessThanOrEquals("Year",t,9999),r.typeOf.number.greaterThanOrEquals("Month",n,1),r.typeOf.number.lessThanOrEquals("Month",n,12),r.typeOf.number.greaterThanOrEquals("Day",i,1),r.typeOf.number.lessThanOrEquals("Day",i,31),r.typeOf.number.greaterThanOrEquals("Hour",u,0),r.typeOf.number.lessThanOrEquals("Hour",u,23),r.typeOf.number.greaterThanOrEquals("Minute",s,0),r.typeOf.number.lessThanOrEquals("Minute",s,59),r.typeOf.bool("IsLeapSecond",f),r.typeOf.number.greaterThanOrEquals("Second",c,0),r.typeOf.number.lessThanOrEquals("Second",c,f?60:59),r.typeOf.number.greaterThanOrEquals("Millisecond",a,0),r.typeOf.number.lessThan("Millisecond",a,1e3),function(){const r=2===n&&ln(t)?dn[n-1]+1:dn[n-1];if(i>r)throw new e("Month and Day represents invalid date")}(),this.year=t,this.month=n,this.day=i,this.hour=u,this.minute=s,this.second=c,this.millisecond=a,this.isLeapSecond=f}function mn(t,n){this.julianDate=t,this.offset=n}var gn=Object.freeze({SECONDS_PER_MILLISECOND:.001,SECONDS_PER_MINUTE:60,MINUTES_PER_HOUR:60,HOURS_PER_DAY:24,SECONDS_PER_HOUR:3600,MINUTES_PER_DAY:1440,SECONDS_PER_DAY:86400,DAYS_PER_JULIAN_CENTURY:36525,PICOSECOND:1e-9,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5}),vn=Object.freeze({UTC:0,TAI:1});const pn=new wn,yn=[31,28,31,30,31,30,31,31,30,31,30,31];function bn(t,n){return Un.compare(t.julianDate,n.julianDate)}const Mn=new mn;function An(t){Mn.julianDate=t;const n=Un.leapSeconds;let e=fn(n,Mn,bn);e<0&&(e=~e),e>=n.length&&(e=n.length-1);let r=n[e].offset;e>0&&Un.secondsDifference(n[e].julianDate,t)>r&&(e--,r=n[e].offset),Un.addSeconds(t,r,t)}function xn(t,n){Mn.julianDate=t;const e=Un.leapSeconds;let r=fn(e,Mn,bn);if(r<0&&(r=~r),0===r)return Un.addSeconds(t,-e[0].offset,n);if(r>=e.length)return Un.addSeconds(t,-e[r-1].offset,n);const i=Un.secondsDifference(e[r].julianDate,t);return 0===i?Un.addSeconds(t,-e[r].offset,n):i<=1?void 0:Un.addSeconds(t,-e[--r].offset,n)}function En(t,n,e){const r=n/gn.SECONDS_PER_DAY|0;return t+=r,(n-=gn.SECONDS_PER_DAY*r)<0&&(t--,n+=gn.SECONDS_PER_DAY),e.dayNumber=t,e.secondsOfDay=n,e}function kn(t,n,e,r,i,o,u){const s=(n-14)/12|0,c=t+4800+s;let a=(1461*c/4|0)+(367*(n-2-12*s)/12|0)-(3*((c+100)/100|0)/4|0)+e-32075;(r-=12)<0&&(r+=24);const f=o+(r*gn.SECONDS_PER_HOUR+i*gn.SECONDS_PER_MINUTE+u*gn.SECONDS_PER_MILLISECOND);return f>=43200&&(a-=1),[a,f]}const qn=/^(\\d{4})$/,$n=/^(\\d{4})-(\\d{2})$/,Sn=/^(\\d{4})-?(\\d{3})$/,In=/^(\\d{4})-?W(\\d{2})-?(\\d{1})?$/,On=/^(\\d{4})-?(\\d{2})-?(\\d{2})$/,Rn=/([Z+\\-])?(\\d{2})?:?(\\d{2})?$/,Pn=/^(\\d{2})(\\.\\d+)?/.source+Rn.source,jn=/^(\\d{2}):?(\\d{2})(\\.\\d+)?/.source+Rn.source,Fn=/^(\\d{2}):?(\\d{2}):?(\\d{2})(\\.\\d+)?/.source+Rn.source,Nn="Invalid ISO 8601 date.";function Un(t,n,e){this.dayNumber=void 0,this.secondsOfDay=void 0,t=o(t,0),n=o(n,0),e=o(e,vn.UTC);const r=0|t;En(r,n+=(t-r)*gn.SECONDS_PER_DAY,this),e===vn.UTC&&An(this)}Un.fromGregorianDate=function(t,r){if(!(t instanceof wn))throw new e("date must be a valid GregorianDate.");const i=kn(t.year,t.month,t.day,t.hour,t.minute,t.second,t.millisecond);return n(r)?(En(i[0],i[1],r),An(r),r):new Un(i[0],i[1],vn.UTC)},Un.fromDate=function(t,r){if(!(t instanceof Date)||isNaN(t.getTime()))throw new e("date must be a valid JavaScript Date.");const i=kn(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds());return n(r)?(En(i[0],i[1],r),An(r),r):new Un(i[0],i[1],vn.UTC)},Un.fromIso8601=function(t,r){if("string"!=typeof t)throw new e(Nn);let i,o=(t=t.replace(",",".")).split("T"),u=1,s=1,c=0,a=0,f=0,h=0;const l=o[0],d=o[1];let w,m,g,v;if(!n(l))throw new e(Nn);if(o=l.match(On),null!==o){if(g=l.split("-").length-1,g>0&&2!==g)throw new e(Nn);i=+o[1],u=+o[2],s=+o[3]}else if(o=l.match($n),null!==o)i=+o[1],u=+o[2];else if(o=l.match(qn),null!==o)i=+o[1];else{let t;if(o=l.match(Sn),null!==o){if(i=+o[1],t=+o[2],m=ln(i),t<1||m&&t>366||!m&&t>365)throw new e(Nn)}else{if(o=l.match(In),null===o)throw new e(Nn);{i=+o[1];const r=+o[2],u=+o[3]||0;if(g=l.split("-").length-1,g>0&&(!n(o[3])&&1!==g||n(o[3])&&2!==g))throw new e(Nn);t=7*r+u-new Date(Date.UTC(i,0,4)).getUTCDay()-3}}w=new Date(Date.UTC(i,0,1)),w.setUTCDate(t),u=w.getUTCMonth()+1,s=w.getUTCDate()}if(m=ln(i),u<1||u>12||s<1||(2!==u||!m)&&s>yn[u-1]||m&&2===u&&s>29)throw new e(Nn);if(n(d)){if(o=d.match(Fn),null!==o){if(g=d.split(":").length-1,g>0&&2!==g&&3!==g)throw new e(Nn);c=+o[1],a=+o[2],f=+o[3],h=1e3*+(o[4]||0),v=5}else if(o=d.match(jn),null!==o){if(g=d.split(":").length-1,g>2)throw new e(Nn);c=+o[1],a=+o[2],f=60*+(o[3]||0),v=4}else{if(o=d.match(Pn),null===o)throw new e(Nn);c=+o[1],a=60*+(o[2]||0),v=3}if(a>=60||f>=61||c>24||24===c&&(a>0||f>0||h>0))throw new e(Nn);const t=o[v],n=+o[v+1],r=+(o[v+2]||0);switch(t){case"+":c-=n,a-=r;break;case"-":c+=n,a+=r;break;case"Z":break;default:a+=new Date(Date.UTC(i,u-1,s,c,a)).getTimezoneOffset()}}const p=60===f;for(p&&f--;a>=60;)a-=60,c++;for(;c>=24;)c-=24,s++;for(w=m&&2===u?29:yn[u-1];s>w;)s-=w,u++,u>12&&(u-=12,i++),w=m&&2===u?29:yn[u-1];for(;a<0;)a+=60,c--;for(;c<0;)c+=24,s--;for(;s<1;)u--,u<1&&(u+=12,i--),w=m&&2===u?29:yn[u-1],s+=w;const y=kn(i,u,s,c,a,f,h);return n(r)?(En(y[0],y[1],r),An(r)):r=new Un(y[0],y[1],vn.UTC),p&&Un.addSeconds(r,1,r),r},Un.now=function(t){return Un.fromDate(new Date,t)};const Tn=new Un(0,0,vn.TAI);Un.toGregorianDate=function(t,r){if(!n(t))throw new e("julianDate is required.");let i=!1,o=xn(t,Tn);n(o)||(Un.addSeconds(t,-1,Tn),o=xn(Tn,Tn),i=!0);let u=o.dayNumber;const s=o.secondsOfDay;s>=43200&&(u+=1);let c=u+68569|0;const a=4*c/146097|0;c=c-((146097*a+3)/4|0)|0;const f=4e3*(c+1)/1461001|0;c=c-(1461*f/4|0)+31|0;const h=80*c/2447|0,l=c-(2447*h/80|0)|0;c=h/11|0;const d=h+2-12*c|0,w=100*(a-49)+f+c|0;let m=s/gn.SECONDS_PER_HOUR|0,g=s-m*gn.SECONDS_PER_HOUR;const v=g/gn.SECONDS_PER_MINUTE|0;g-=v*gn.SECONDS_PER_MINUTE;let p=0|g;const y=(g-p)/gn.SECONDS_PER_MILLISECOND;return m+=12,m>23&&(m-=24),i&&(p+=1),n(r)?(r.year=w,r.month=d,r.day=l,r.hour=m,r.minute=v,r.second=p,r.millisecond=y,r.isLeapSecond=i,r):new wn(w,d,l,m,v,p,y,i)},Un.toDate=function(t){if(!n(t))throw new e("julianDate is required.");const r=Un.toGregorianDate(t,pn);let i=r.second;return r.isLeapSecond&&(i-=1),new Date(Date.UTC(r.year,r.month-1,r.day,r.hour,r.minute,i,r.millisecond))},Un.toIso8601=function(t,r){if(!n(t))throw new e("julianDate is required.");const i=Un.toGregorianDate(t,pn);let o=i.year,u=i.month,s=i.day,c=i.hour;const a=i.minute,f=i.second,h=i.millisecond;let l;if(1e4===o&&1===u&&1===s&&0===c&&0===a&&0===f&&0===h&&(o=9999,u=12,s=31,c=24),!n(r)&&0!==h){const t=.01*h;return l=t<1e-6?t.toFixed(20).replace(".","").replace(/0+$/,""):t.toString().replace(".",""),`${o.toString().padStart(4,"0")}-${u.toString().padStart(2,"0")}-${s.toString().padStart(2,"0")}T${c.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}.${l}Z`}return n(r)&&0!==r?(l=(.01*h).toFixed(r).replace(".","").slice(0,r),`${o.toString().padStart(4,"0")}-${u.toString().padStart(2,"0")}-${s.toString().padStart(2,"0")}T${c.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}.${l}Z`):`${o.toString().padStart(4,"0")}-${u.toString().padStart(2,"0")}-${s.toString().padStart(2,"0")}T${c.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}:${f.toString().padStart(2,"0")}Z`},Un.clone=function(t,e){if(n(t))return n(e)?(e.dayNumber=t.dayNumber,e.secondsOfDay=t.secondsOfDay,e):new Un(t.dayNumber,t.secondsOfDay,vn.TAI)},Un.compare=function(t,r){if(!n(t))throw new e("left is required.");if(!n(r))throw new e("right is required.");const i=t.dayNumber-r.dayNumber;return 0!==i?i:t.secondsOfDay-r.secondsOfDay},Un.equals=function(t,e){return t===e||n(t)&&n(e)&&t.dayNumber===e.dayNumber&&t.secondsOfDay===e.secondsOfDay},Un.equalsEpsilon=function(t,e,r){return r=o(r,0),t===e||n(t)&&n(e)&&Math.abs(Un.secondsDifference(t,e))<=r},Un.totalDays=function(t){if(!n(t))throw new e("julianDate is required.");return t.dayNumber+t.secondsOfDay/gn.SECONDS_PER_DAY},Un.secondsDifference=function(t,r){if(!n(t))throw new e("left is required.");if(!n(r))throw new e("right is required.");return(t.dayNumber-r.dayNumber)*gn.SECONDS_PER_DAY+(t.secondsOfDay-r.secondsOfDay)},Un.daysDifference=function(t,r){if(!n(t))throw new e("left is required.");if(!n(r))throw new e("right is required.");return t.dayNumber-r.dayNumber+(t.secondsOfDay-r.secondsOfDay)/gn.SECONDS_PER_DAY},Un.computeTaiMinusUtc=function(t){Mn.julianDate=t;const n=Un.leapSeconds;let e=fn(n,Mn,bn);return e<0&&(e=~e,--e,e<0&&(e=0)),n[e].offset},Un.addSeconds=function(t,r,i){if(!n(t))throw new e("julianDate is required.");if(!n(r))throw new e("seconds is required.");if(!n(i))throw new e("result is required.");return En(t.dayNumber,t.secondsOfDay+r,i)},Un.addMinutes=function(t,r,i){if(!n(t))throw new e("julianDate is required.");if(!n(r))throw new e("minutes is required.");if(!n(i))throw new e("result is required.");const o=t.secondsOfDay+r*gn.SECONDS_PER_MINUTE;return En(t.dayNumber,o,i)},Un.addHours=function(t,r,i){if(!n(t))throw new e("julianDate is required.");if(!n(r))throw new e("hours is required.");if(!n(i))throw new e("result is required.");const o=t.secondsOfDay+r*gn.SECONDS_PER_HOUR;return En(t.dayNumber,o,i)},Un.addDays=function(t,r,i){if(!n(t))throw new e("julianDate is required.");if(!n(r))throw new e("days is required.");if(!n(i))throw new e("result is required.");return En(t.dayNumber+r,t.secondsOfDay,i)},Un.lessThan=function(t,n){return Un.compare(t,n)<0},Un.lessThanOrEquals=function(t,n){return Un.compare(t,n)<=0},Un.greaterThan=function(t,n){return Un.compare(t,n)>0},Un.greaterThanOrEquals=function(t,n){return Un.compare(t,n)>=0},Un.prototype.clone=function(t){return Un.clone(this,t)},Un.prototype.equals=function(t){return Un.equals(this,t)},Un.prototype.equalsEpsilon=function(t,n){return Un.equalsEpsilon(this,t,n)},Un.prototype.toString=function(){return Un.toIso8601(this)},Un.leapSeconds=[new mn(new Un(2441317,43210,vn.TAI),10),new mn(new Un(2441499,43211,vn.TAI),11),new mn(new Un(2441683,43212,vn.TAI),12),new mn(new Un(2442048,43213,vn.TAI),13),new mn(new Un(2442413,43214,vn.TAI),14),new mn(new Un(2442778,43215,vn.TAI),15),new mn(new Un(2443144,43216,vn.TAI),16),new mn(new Un(2443509,43217,vn.TAI),17),new mn(new Un(2443874,43218,vn.TAI),18),new mn(new Un(2444239,43219,vn.TAI),19),new mn(new Un(2444786,43220,vn.TAI),20),new mn(new Un(2445151,43221,vn.TAI),21),new mn(new Un(2445516,43222,vn.TAI),22),new mn(new Un(2446247,43223,vn.TAI),23),new mn(new Un(2447161,43224,vn.TAI),24),new mn(new Un(2447892,43225,vn.TAI),25),new mn(new Un(2448257,43226,vn.TAI),26),new mn(new Un(2448804,43227,vn.TAI),27),new mn(new Un(2449169,43228,vn.TAI),28),new mn(new Un(2449534,43229,vn.TAI),29),new mn(new Un(2450083,43230,vn.TAI),30),new mn(new Un(2450630,43231,vn.TAI),31),new mn(new Un(2451179,43232,vn.TAI),32),new mn(new Un(2453736,43233,vn.TAI),33),new mn(new Un(2454832,43234,vn.TAI),34),new mn(new Un(2456109,43235,vn.TAI),35),new mn(new Un(2457204,43236,vn.TAI),36),new mn(new Un(2457754,43237,vn.TAI),37)];var zn,Cn,Dn,Bn,Ln,_n,Vn,Hn={exports:{}},Yn={exports:{}},Zn=Yn.exports,Wn={exports:{}},Qn=Wn.exports,Jn={exports:{}},Gn=Jn.exports,Xn=(Bn||(Bn=1,_n=Hn.exports,Vn=function(t,n,e,r){var i=r&&r.URI;function o(t,n){var e=arguments.length>=1;if(!(this instanceof o))return e?arguments.length>=2?new o(t,n):new o(t):new o;if(void 0===t){if(e)throw new TypeError("undefined is not a valid argument for URI");t="undefined"!=typeof location?location.href+"":""}if(null===t&&e)throw new TypeError("null is not a valid argument for URI");return this.href(t),void 0!==n?this.absoluteTo(n):this}o.version="1.19.11";var u=o.prototype,s={}.hasOwnProperty;function c(t){return t.replace(/([.*+?^=!:${}()|[\\]\\/\\\\])/g,"\\\\$1")}function a(t){return void 0===t?"Undefined":String({}.toString.call(t)).slice(8,-1)}function f(t){return"Array"===a(t)}function h(t,n){var e,r,i={};if("RegExp"===a(n))i=null;else if(f(n))for(e=0,r=n.length;e<r;e++)i[n[e]]=!0;else i[n]=!0;for(e=0,r=t.length;e<r;e++)(i&&void 0!==i[t[e]]||!i&&n.test(t[e]))&&(t.splice(e,1),r--,e--);return t}function l(t,n){var e,r;if(f(n)){for(e=0,r=n.length;e<r;e++)if(!l(t,n[e]))return!1;return!0}var i=a(n);for(e=0,r=t.length;e<r;e++)if("RegExp"===i){if("string"==typeof t[e]&&t[e].match(n))return!0}else if(t[e]===n)return!0;return!1}function d(t,n){if(!f(t)||!f(n))return!1;if(t.length!==n.length)return!1;t.sort(),n.sort();for(var e=0,r=t.length;e<r;e++)if(t[e]!==n[e])return!1;return!0}function w(t){return t.replace(/^\\/+|\\/+$/g,"")}function m(t){return escape(t)}function g(t){return encodeURIComponent(t).replace(/[!\'()*]/g,m).replace(/\\*/g,"%2A")}o.F=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,preventInvalidHostname:o.preventInvalidHostname,duplicateQueryParameters:o.duplicateQueryParameters,escapeQuerySpace:o.escapeQuerySpace}},o.preventInvalidHostname=!1,o.duplicateQueryParameters=!1,o.escapeQuerySpace=!0,o.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,o.idn_expression=/[^a-z0-9\\._-]/i,o.punycode_expression=/(xn--)/i,o.ip4_expression=/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/,o.ip6_expression=/^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$/,o.find_uri_expression=/\\b((?:[a-z][\\w-]+:(?:\\/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}\\/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:\'".,<>?«»“”‘’]))/gi,o.findUri={start:/\\b(?:([a-z][a-z0-9.+-]*:\\/\\/)|www\\.)/gi,end:/[\\s\\r\\n]|$/,trim:/[`!()\\[\\]{};:\'".,<>?«»“”„‘’]+$/,parens:/(\\([^\\)]*\\)|\\[[^\\]]*\\]|\\{[^}]*\\}|<[^>]*>)/g},o.leading_whitespace_expression=/^[\\x00-\\x20\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000\\ufeff]+/,o.ascii_tab_whitespace=/[\\u0009\\u000A\\u000D]+/g,o.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},o.hostProtocols=["http","https"],o.invalid_hostname_characters=/[^a-zA-Z0-9\\.\\-:_]/,o.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"},o.getDomAttribute=function(t){if(t&&t.nodeName){var n=t.nodeName.toLowerCase();if("input"!==n||"image"===t.type)return o.domAttributes[n]}},o.encode=g,o.decode=decodeURIComponent,o.iso8859=function(){o.encode=escape,o.decode=unescape},o.unicode=function(){o.encode=g,o.decode=decodeURIComponent},o.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\\/\\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"\'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/gi,map:{"%21":"!","%24":"$","%27":"\'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\\/\\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}},o.encodeQuery=function(t,n){var e=o.encode(t+"");return void 0===n&&(n=o.escapeQuerySpace),n?e.replace(/%20/g,"+"):e},o.decodeQuery=function(t,n){t+="",void 0===n&&(n=o.escapeQuerySpace);try{return o.decode(n?t.replace(/\\+/g,"%20"):t)}catch(n){return t}};var v,p={encode:"encode",decode:"decode"},y=function(t,n){return function(e){try{return o[n](e+"").replace(o.characters[t][n].expression,(function(e){return o.characters[t][n].map[e]}))}catch(t){return e}}};for(v in p)o[v+"PathSegment"]=y("pathname",p[v]),o[v+"UrnPathSegment"]=y("urnpath",p[v]);var b=function(t,n,e){return function(r){var i;i=e?function(t){return o[n](o[e](t))}:o[n];for(var u=(r+"").split(t),s=0,c=u.length;s<c;s++)u[s]=i(u[s]);return u.join(t)}};function M(t){return function(n,e){return void 0===n?this.F[t]||"":(this.F[t]=n||null,this.build(!e),this)}}function A(t,n){return function(e,r){return void 0===e?this.F[t]||"":(null!==e&&(e+="").charAt(0)===n&&(e=e.substring(1)),this.F[t]=e,this.build(!r),this)}}o.decodePath=b("/","decodePathSegment"),o.decodeUrnPath=b(":","decodeUrnPathSegment"),o.recodePath=b("/","encodePathSegment","decode"),o.recodeUrnPath=b(":","encodeUrnPathSegment","decode"),o.encodeReserved=y("reserved","encode"),o.parse=function(t,n){var e;return n||(n={preventInvalidHostname:o.preventInvalidHostname}),(e=(t=(t=t.replace(o.leading_whitespace_expression,"")).replace(o.ascii_tab_whitespace,"")).indexOf("#"))>-1&&(n.fragment=t.substring(e+1)||null,t=t.substring(0,e)),(e=t.indexOf("?"))>-1&&(n.query=t.substring(e+1)||null,t=t.substring(0,e)),"//"===(t=(t=t.replace(/^(https?|ftp|wss?)?:+[/\\\\]*/i,"$1://")).replace(/^[/\\\\]{2,}/i,"//")).substring(0,2)?(n.protocol=null,t=t.substring(2),t=o.parseAuthority(t,n)):(e=t.indexOf(":"))>-1&&(n.protocol=t.substring(0,e)||null,n.protocol&&!n.protocol.match(o.protocol_expression)?n.protocol=void 0:"//"===t.substring(e+1,e+3).replace(/\\\\/g,"/")?(t=t.substring(e+3),t=o.parseAuthority(t,n)):(t=t.substring(e+1),n.urn=!0)),n.path=t,n},o.parseHost=function(t,n){t||(t="");var e,r,i=(t=t.replace(/\\\\/g,"/")).indexOf("/");if(-1===i&&(i=t.length),"["===t.charAt(0))e=t.indexOf("]"),n.hostname=t.substring(1,e)||null,n.port=t.substring(e+2,i)||null,"/"===n.port&&(n.port=null);else{var u=t.indexOf(":"),s=t.indexOf("/"),c=t.indexOf(":",u+1);-1!==c&&(-1===s||c<s)?(n.hostname=t.substring(0,i)||null,n.port=null):(r=t.substring(0,i).split(":"),n.hostname=r[0]||null,n.port=r[1]||null)}return n.hostname&&"/"!==t.substring(i).charAt(0)&&(i++,t="/"+t),n.preventInvalidHostname&&o.ensureValidHostname(n.hostname,n.protocol),n.port&&o.ensureValidPort(n.port),t.substring(i)||"/"},o.parseAuthority=function(t,n){return t=o.parseUserinfo(t,n),o.parseHost(t,n)},o.parseUserinfo=function(t,n){var e=t;-1!==t.indexOf("\\\\")&&(t=t.replace(/\\\\/g,"/"));var r,i=t.indexOf("/"),u=t.lastIndexOf("@",i>-1?i:t.length-1);return u>-1&&(-1===i||u<i)?(r=t.substring(0,u).split(":"),n.username=r[0]?o.decode(r[0]):null,r.shift(),n.password=r[0]?o.decode(r.join(":")):null,t=e.substring(u+1)):(n.username=null,n.password=null),t},o.parseQuery=function(t,n){if(!t)return{};if(!(t=t.replace(/&+/g,"&").replace(/^\\?*&*|&+$/g,"")))return{};for(var e,r,i,u={},c=t.split("&"),a=c.length,f=0;f<a;f++)e=c[f].split("="),r=o.decodeQuery(e.shift(),n),i=e.length?o.decodeQuery(e.join("="),n):null,"__proto__"!==r&&(s.call(u,r)?("string"!=typeof u[r]&&null!==u[r]||(u[r]=[u[r]]),u[r].push(i)):u[r]=i);return u},o.build=function(t){var n="",e=!1;return t.protocol&&(n+=t.protocol+":"),t.urn||!n&&!t.hostname||(n+="//",e=!0),n+=o.buildAuthority(t)||"","string"==typeof t.path&&("/"!==t.path.charAt(0)&&e&&(n+="/"),n+=t.path),"string"==typeof t.query&&t.query&&(n+="?"+t.query),"string"==typeof t.fragment&&t.fragment&&(n+="#"+t.fragment),n},o.buildHost=function(t){var n="";return t.hostname?(o.ip6_expression.test(t.hostname)?n+="["+t.hostname+"]":n+=t.hostname,t.port&&(n+=":"+t.port),n):""},o.buildAuthority=function(t){return o.buildUserinfo(t)+o.buildHost(t)},o.buildUserinfo=function(t){var n="";return t.username&&(n+=o.encode(t.username)),t.password&&(n+=":"+o.encode(t.password)),n&&(n+="@"),n},o.buildQuery=function(t,n,e){var r,i,u,c,a="";for(i in t)if("__proto__"!==i&&s.call(t,i))if(f(t[i]))for(r={},u=0,c=t[i].length;u<c;u++)void 0!==t[i][u]&&void 0===r[t[i][u]+""]&&(a+="&"+o.buildQueryParameter(i,t[i][u],e),!0!==n&&(r[t[i][u]+""]=!0));else void 0!==t[i]&&(a+="&"+o.buildQueryParameter(i,t[i],e));return a.substring(1)},o.buildQueryParameter=function(t,n,e){return o.encodeQuery(t,e)+(null!==n?"="+o.encodeQuery(n,e):"")},o.addQuery=function(t,n,e){if("object"==typeof n)for(var r in n)s.call(n,r)&&o.addQuery(t,r,n[r]);else{if("string"!=typeof n)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");if(void 0===t[n])return void(t[n]=e);"string"==typeof t[n]&&(t[n]=[t[n]]),f(e)||(e=[e]),t[n]=(t[n]||[]).concat(e)}},o.setQuery=function(t,n,e){if("object"==typeof n)for(var r in n)s.call(n,r)&&o.setQuery(t,r,n[r]);else{if("string"!=typeof n)throw new TypeError("URI.setQuery() accepts an object, string as the name parameter");t[n]=void 0===e?null:e}},o.removeQuery=function(t,n,e){var r,i,u;if(f(n))for(r=0,i=n.length;r<i;r++)t[n[r]]=void 0;else if("RegExp"===a(n))for(u in t)n.test(u)&&(t[u]=void 0);else if("object"==typeof n)for(u in n)s.call(n,u)&&o.removeQuery(t,u,n[u]);else{if("string"!=typeof n)throw new TypeError("URI.removeQuery() accepts an object, string, RegExp as the first parameter");void 0!==e?"RegExp"===a(e)?!f(t[n])&&e.test(t[n])?t[n]=void 0:t[n]=h(t[n],e):t[n]!==String(e)||f(e)&&1!==e.length?f(t[n])&&(t[n]=h(t[n],e)):t[n]=void 0:t[n]=void 0}},o.hasQuery=function(t,n,e,r){switch(a(n)){case"String":break;case"RegExp":for(var i in t)if(s.call(t,i)&&n.test(i)&&(void 0===e||o.hasQuery(t,i,e)))return!0;return!1;case"Object":for(var u in n)if(s.call(n,u)&&!o.hasQuery(t,u,n[u]))return!1;return!0;default:throw new TypeError("URI.hasQuery() accepts a string, regular expression or object as the name parameter")}switch(a(e)){case"Undefined":return n in t;case"Boolean":return e===Boolean(f(t[n])?t[n].length:t[n]);case"Function":return!!e(t[n],n,t);case"Array":return!!f(t[n])&&(r?l:d)(t[n],e);case"RegExp":return f(t[n])?!!r&&l(t[n],e):Boolean(t[n]&&t[n].match(e));case"Number":e=String(e);case"String":return f(t[n])?!!r&&l(t[n],e):t[n]===e;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},o.joinPaths=function(){for(var t=[],n=[],e=0,r=0;r<arguments.length;r++){var i=new o(arguments[r]);t.push(i);for(var u=i.segment(),s=0;s<u.length;s++)"string"==typeof u[s]&&n.push(u[s]),u[s]&&e++}if(!n.length||!e)return new o("");var c=new o("").segment(n);return""!==t[0].path()&&"/"!==t[0].path().slice(0,1)||c.path("/"+c.path()),c.normalize()},o.commonPath=function(t,n){var e,r=Math.min(t.length,n.length);for(e=0;e<r;e++)if(t.charAt(e)!==n.charAt(e)){e--;break}return e<1?t.charAt(0)===n.charAt(0)&&"/"===t.charAt(0)?"/":"":("/"===t.charAt(e)&&"/"===n.charAt(e)||(e=t.substring(0,e).lastIndexOf("/")),t.substring(0,e+1))},o.withinString=function(t,n,e){e||(e={});var r=e.start||o.findUri.start,i=e.end||o.findUri.end,u=e.trim||o.findUri.trim,s=e.parens||o.findUri.parens,c=/[a-z0-9-]=["\']?$/i;for(r.lastIndex=0;;){var a=r.exec(t);if(!a)break;var f=a.index;if(e.ignoreHtml){var h=t.slice(Math.max(f-3,0),f);if(h&&c.test(h))continue}for(var l=f+t.slice(f).search(i),d=t.slice(f,l),w=-1;;){var m=s.exec(d);if(!m)break;var g=m.index+m[0].length;w=Math.max(w,g)}if(!((d=w>-1?d.slice(0,w)+d.slice(w).replace(u,""):d.replace(u,"")).length<=a[0].length||e.ignore&&e.ignore.test(d))){var v=n(d,f,l=f+d.length,t);void 0!==v?(v=String(v),t=t.slice(0,f)+v+t.slice(l),r.lastIndex=f+v.length):r.lastIndex=l}}return r.lastIndex=0,t},o.ensureValidHostname=function(n,e){var r=!!n,i=!1;if(!!e&&(i=l(o.hostProtocols,e)),i&&!r)throw new TypeError("Hostname cannot be empty, if protocol is "+e);if(n&&n.match(o.invalid_hostname_characters)){if(!t)throw new TypeError(\'Hostname "\'+n+\'" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available\');if(t.toASCII(n).match(o.invalid_hostname_characters))throw new TypeError(\'Hostname "\'+n+\'" contains characters other than [A-Z0-9.-:_]\')}},o.ensureValidPort=function(t){if(t){var n=Number(t);if(!(/^[0-9]+$/.test(n)&&n>0&&n<65536))throw new TypeError(\'Port "\'+t+\'" is not a valid port\')}},o.noConflict=function(t){if(t){var n={URI:this.noConflict()};return r.URITemplate&&"function"==typeof r.URITemplate.noConflict&&(n.URITemplate=r.URITemplate.noConflict()),r.IPv6&&"function"==typeof r.IPv6.noConflict&&(n.IPv6=r.IPv6.noConflict()),r.SecondLevelDomains&&"function"==typeof r.SecondLevelDomains.noConflict&&(n.SecondLevelDomains=r.SecondLevelDomains.noConflict()),n}return r.URI===this&&(r.URI=i),this},u.build=function(t){return!0===t?this.U=!0:(void 0===t||this.U)&&(this.T=o.build(this.F),this.U=!1),this},u.clone=function(){return new o(this)},u.valueOf=u.toString=function(){return this.build(!1).T},u.protocol=M("protocol"),u.username=M("username"),u.password=M("password"),u.hostname=M("hostname"),u.port=M("port"),u.query=A("query","?"),u.fragment=A("fragment","#"),u.search=function(t,n){var e=this.query(t,n);return"string"==typeof e&&e.length?"?"+e:e},u.hash=function(t,n){var e=this.fragment(t,n);return"string"==typeof e&&e.length?"#"+e:e},u.pathname=function(t,n){if(void 0===t||!0===t){var e=this.F.path||(this.F.hostname?"/":"");return t?(this.F.urn?o.decodeUrnPath:o.decodePath)(e):e}return this.F.urn?this.F.path=t?o.recodeUrnPath(t):"":this.F.path=t?o.recodePath(t):"/",this.build(!n),this},u.path=u.pathname,u.href=function(t,n){var e;if(void 0===t)return this.toString();this.T="",this.F=o.F();var r=t instanceof o,i="object"==typeof t&&(t.hostname||t.path||t.pathname);if(t.nodeName&&(t=t[o.getDomAttribute(t)]||"",i=!1),!r&&i&&void 0!==t.pathname&&(t=t.toString()),"string"==typeof t||t instanceof String)this.F=o.parse(String(t),this.F);else{if(!r&&!i)throw new TypeError("invalid input");var u=r?t.F:t;for(e in u)"query"!==e&&s.call(this.F,e)&&(this.F[e]=u[e]);u.query&&this.query(u.query,!1)}return this.build(!n),this},u.is=function(t){var n=!1,r=!1,i=!1,u=!1,s=!1,c=!1,a=!1,f=!this.F.urn;switch(this.F.hostname&&(f=!1,r=o.ip4_expression.test(this.F.hostname),i=o.ip6_expression.test(this.F.hostname),s=(u=!(n=r||i))&&e&&e.has(this.F.hostname),c=u&&o.idn_expression.test(this.F.hostname),a=u&&o.punycode_expression.test(this.F.hostname)),t.toLowerCase()){case"relative":return f;case"absolute":return!f;case"domain":case"name":return u;case"sld":return s;case"ip":return n;case"ip4":case"ipv4":case"inet4":return r;case"ip6":case"ipv6":case"inet6":return i;case"idn":return c;case"url":return!this.F.urn;case"urn":return!!this.F.urn;case"punycode":return a}return null};var x=u.protocol,E=u.port,k=u.hostname;u.protocol=function(t,n){if(t&&!(t=t.replace(/:(\\/\\/)?$/,"")).match(o.protocol_expression))throw new TypeError(\'Protocol "\'+t+"\\" contains characters other than [A-Z0-9.+-] or doesn\'t start with [A-Z]");return x.call(this,t,n)},u.scheme=u.protocol,u.port=function(t,n){return this.F.urn?void 0===t?"":this:(void 0!==t&&(0===t&&(t=null),t&&(":"===(t+="").charAt(0)&&(t=t.substring(1)),o.ensureValidPort(t))),E.call(this,t,n))},u.hostname=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0!==t){var e={preventInvalidHostname:this.F.preventInvalidHostname};if("/"!==o.parseHost(t,e))throw new TypeError(\'Hostname "\'+t+\'" contains characters other than [A-Z0-9.-]\');t=e.hostname,this.F.preventInvalidHostname&&o.ensureValidHostname(t,this.F.protocol)}return k.call(this,t,n)},u.origin=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t){var e=this.protocol();return this.authority()?(e?e+"://":"")+this.authority():""}var r=o(t);return this.protocol(r.protocol()).authority(r.authority()).build(!n),this},u.host=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t)return this.F.hostname?o.buildHost(this.F):"";if("/"!==o.parseHost(t,this.F))throw new TypeError(\'Hostname "\'+t+\'" contains characters other than [A-Z0-9.-]\');return this.build(!n),this},u.authority=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t)return this.F.hostname?o.buildAuthority(this.F):"";if("/"!==o.parseAuthority(t,this.F))throw new TypeError(\'Hostname "\'+t+\'" contains characters other than [A-Z0-9.-]\');return this.build(!n),this},u.userinfo=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t){var e=o.buildUserinfo(this.F);return e?e.substring(0,e.length-1):e}return"@"!==t[t.length-1]&&(t+="@"),o.parseUserinfo(t,this.F),this.build(!n),this},u.resource=function(t,n){var e;return void 0===t?this.path()+this.search()+this.hash():(e=o.parse(t),this.F.path=e.path,this.F.query=e.query,this.F.fragment=e.fragment,this.build(!n),this)},u.subdomain=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t){if(!this.F.hostname||this.is("IP"))return"";var e=this.F.hostname.length-this.domain().length-1;return this.F.hostname.substring(0,e)||""}var r=this.F.hostname.length-this.domain().length,i=this.F.hostname.substring(0,r),u=new RegExp("^"+c(i));if(t&&"."!==t.charAt(t.length-1)&&(t+="."),-1!==t.indexOf(":"))throw new TypeError("Domains cannot contain colons");return t&&o.ensureValidHostname(t,this.F.protocol),this.F.hostname=this.F.hostname.replace(u,t),this.build(!n),this},u.domain=function(t,n){if(this.F.urn)return void 0===t?"":this;if("boolean"==typeof t&&(n=t,t=void 0),void 0===t){if(!this.F.hostname||this.is("IP"))return"";var e=this.F.hostname.match(/\\./g);if(e&&e.length<2)return this.F.hostname;var r=this.F.hostname.length-this.tld(n).length-1;return r=this.F.hostname.lastIndexOf(".",r-1)+1,this.F.hostname.substring(r)||""}if(!t)throw new TypeError("cannot set domain empty");if(-1!==t.indexOf(":"))throw new TypeError("Domains cannot contain colons");if(o.ensureValidHostname(t,this.F.protocol),!this.F.hostname||this.is("IP"))this.F.hostname=t;else{var i=new RegExp(c(this.domain())+"$");this.F.hostname=this.F.hostname.replace(i,t)}return this.build(!n),this},u.tld=function(t,n){if(this.F.urn)return void 0===t?"":this;if("boolean"==typeof t&&(n=t,t=void 0),void 0===t){if(!this.F.hostname||this.is("IP"))return"";var r=this.F.hostname.lastIndexOf("."),i=this.F.hostname.substring(r+1);return!0!==n&&e&&e.list[i.toLowerCase()]&&e.get(this.F.hostname)||i}var o;if(!t)throw new TypeError("cannot set TLD empty");if(t.match(/[^a-zA-Z0-9-]/)){if(!e||!e.is(t))throw new TypeError(\'TLD "\'+t+\'" contains characters other than [A-Z0-9]\');o=new RegExp(c(this.tld())+"$"),this.F.hostname=this.F.hostname.replace(o,t)}else{if(!this.F.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");o=new RegExp(c(this.tld())+"$"),this.F.hostname=this.F.hostname.replace(o,t)}return this.build(!n),this},u.directory=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this.F.path&&!this.F.hostname)return"";if("/"===this.F.path)return"/";var e=this.F.path.length-this.filename().length-1,r=this.F.path.substring(0,e)||(this.F.hostname?"/":"");return t?o.decodePath(r):r}var i=this.F.path.length-this.filename().length,u=this.F.path.substring(0,i),s=new RegExp("^"+c(u));return this.is("relative")||(t||(t="/"),"/"!==t.charAt(0)&&(t="/"+t)),t&&"/"!==t.charAt(t.length-1)&&(t+="/"),t=o.recodePath(t),this.F.path=this.F.path.replace(s,t),this.build(!n),this},u.filename=function(t,n){if(this.F.urn)return void 0===t?"":this;if("string"!=typeof t){if(!this.F.path||"/"===this.F.path)return"";var e=this.F.path.lastIndexOf("/"),r=this.F.path.substring(e+1);return t?o.decodePathSegment(r):r}var i=!1;"/"===t.charAt(0)&&(t=t.substring(1)),t.match(/\\.?\\//)&&(i=!0);var u=new RegExp(c(this.filename())+"$");return t=o.recodePath(t),this.F.path=this.F.path.replace(u,t),i?this.normalizePath(n):this.build(!n),this},u.suffix=function(t,n){if(this.F.urn)return void 0===t?"":this;if(void 0===t||!0===t){if(!this.F.path||"/"===this.F.path)return"";var e,r,i=this.filename(),u=i.lastIndexOf(".");return-1===u?"":(e=i.substring(u+1),r=/^[a-z0-9%]+$/i.test(e)?e:"",t?o.decodePathSegment(r):r)}"."===t.charAt(0)&&(t=t.substring(1));var s,a=this.suffix();if(a)s=t?new RegExp(c(a)+"$"):new RegExp(c("."+a)+"$");else{if(!t)return this;this.F.path+="."+o.recodePath(t)}return s&&(t=o.recodePath(t),this.F.path=this.F.path.replace(s,t)),this.build(!n),this},u.segment=function(t,n,e){var r=this.F.urn?":":"/",i=this.path(),o="/"===i.substring(0,1),u=i.split(r);if(void 0!==t&&"number"!=typeof t&&(e=n,n=t,t=void 0),void 0!==t&&"number"!=typeof t)throw new Error(\'Bad segment "\'+t+\'", must be 0-based integer\');if(o&&u.shift(),t<0&&(t=Math.max(u.length+t,0)),void 0===n)return void 0===t?u:u[t];if(null===t||void 0===u[t])if(f(n)){u=[];for(var s=0,c=n.length;s<c;s++)(n[s].length||u.length&&u[u.length-1].length)&&(u.length&&!u[u.length-1].length&&u.pop(),u.push(w(n[s])))}else(n||"string"==typeof n)&&(n=w(n),""===u[u.length-1]?u[u.length-1]=n:u.push(n));else n?u[t]=w(n):u.splice(t,1);return o&&u.unshift(""),this.path(u.join(r),e)},u.segmentCoded=function(t,n,e){var r,i,u;if("number"!=typeof t&&(e=n,n=t,t=void 0),void 0===n){if(f(r=this.segment(t,n,e)))for(i=0,u=r.length;i<u;i++)r[i]=o.decode(r[i]);else r=void 0!==r?o.decode(r):void 0;return r}if(f(n))for(i=0,u=n.length;i<u;i++)n[i]=o.encode(n[i]);else n="string"==typeof n||n instanceof String?o.encode(n):n;return this.segment(t,n,e)};var q=u.query;return u.query=function(t,n){if(!0===t)return o.parseQuery(this.F.query,this.F.escapeQuerySpace);if("function"==typeof t){var e=o.parseQuery(this.F.query,this.F.escapeQuerySpace),r=t.call(this,e);return this.F.query=o.buildQuery(r||e,this.F.duplicateQueryParameters,this.F.escapeQuerySpace),this.build(!n),this}return void 0!==t&&"string"!=typeof t?(this.F.query=o.buildQuery(t,this.F.duplicateQueryParameters,this.F.escapeQuerySpace),this.build(!n),this):q.call(this,t,n)},u.setQuery=function(t,n,e){var r=o.parseQuery(this.F.query,this.F.escapeQuerySpace);if("string"==typeof t||t instanceof String)r[t]=void 0!==n?n:null;else{if("object"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");for(var i in t)s.call(t,i)&&(r[i]=t[i])}return this.F.query=o.buildQuery(r,this.F.duplicateQueryParameters,this.F.escapeQuerySpace),"string"!=typeof t&&(e=n),this.build(!e),this},u.addQuery=function(t,n,e){var r=o.parseQuery(this.F.query,this.F.escapeQuerySpace);return o.addQuery(r,t,void 0===n?null:n),this.F.query=o.buildQuery(r,this.F.duplicateQueryParameters,this.F.escapeQuerySpace),"string"!=typeof t&&(e=n),this.build(!e),this},u.removeQuery=function(t,n,e){var r=o.parseQuery(this.F.query,this.F.escapeQuerySpace);return o.removeQuery(r,t,n),this.F.query=o.buildQuery(r,this.F.duplicateQueryParameters,this.F.escapeQuerySpace),"string"!=typeof t&&(e=n),this.build(!e),this},u.hasQuery=function(t,n,e){var r=o.parseQuery(this.F.query,this.F.escapeQuerySpace);return o.hasQuery(r,t,n,e)},u.setSearch=u.setQuery,u.addSearch=u.addQuery,u.removeSearch=u.removeQuery,u.hasSearch=u.hasQuery,u.normalize=function(){return this.F.urn?this.normalizeProtocol(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},u.normalizeProtocol=function(t){return"string"==typeof this.F.protocol&&(this.F.protocol=this.F.protocol.toLowerCase(),this.build(!t)),this},u.normalizeHostname=function(e){return this.F.hostname&&(this.is("IDN")&&t?this.F.hostname=t.toASCII(this.F.hostname):this.is("IPv6")&&n&&(this.F.hostname=n.best(this.F.hostname)),this.F.hostname=this.F.hostname.toLowerCase(),this.build(!e)),this},u.normalizePort=function(t){return"string"==typeof this.F.protocol&&this.F.port===o.defaultPorts[this.F.protocol]&&(this.F.port=null,this.build(!t)),this},u.normalizePath=function(t){var n,e=this.F.path;if(!e)return this;if(this.F.urn)return this.F.path=o.recodeUrnPath(this.F.path),this.build(!t),this;if("/"===this.F.path)return this;var r,i,u="";for("/"!==(e=o.recodePath(e)).charAt(0)&&(n=!0,e="/"+e),"/.."!==e.slice(-3)&&"/."!==e.slice(-2)||(e+="/"),e=e.replace(/(\\/(\\.\\/)+)|(\\/\\.$)/g,"/").replace(/\\/{2,}/g,"/"),n&&(u=e.substring(1).match(/^(\\.\\.\\/)+/)||"")&&(u=u[0]);-1!==(r=e.search(/\\/\\.\\.(\\/|$)/));)0!==r?(-1===(i=e.substring(0,r).lastIndexOf("/"))&&(i=r),e=e.substring(0,i)+e.substring(r+3)):e=e.substring(3);return n&&this.is("relative")&&(e=u+e.substring(1)),this.F.path=e,this.build(!t),this},u.normalizePathname=u.normalizePath,u.normalizeQuery=function(t){return"string"==typeof this.F.query&&(this.F.query.length?this.query(o.parseQuery(this.F.query,this.F.escapeQuerySpace)):this.F.query=null,this.build(!t)),this},u.normalizeFragment=function(t){return this.F.fragment||(this.F.fragment=null,this.build(!t)),this},u.normalizeSearch=u.normalizeQuery,u.normalizeHash=u.normalizeFragment,u.iso8859=function(){var t=o.encode,n=o.decode;o.encode=escape,o.decode=decodeURIComponent;try{this.normalize()}finally{o.encode=t,o.decode=n}return this},u.unicode=function(){var t=o.encode,n=o.decode;o.encode=g,o.decode=unescape;try{this.normalize()}finally{o.encode=t,o.decode=n}return this},u.readable=function(){var n=this.clone();n.username("").password("").normalize();var e="";if(n.F.protocol&&(e+=n.F.protocol+"://"),n.F.hostname&&(n.is("punycode")&&t?(e+=t.toUnicode(n.F.hostname),n.F.port&&(e+=":"+n.F.port)):e+=n.host()),n.F.hostname&&n.F.path&&"/"!==n.F.path.charAt(0)&&(e+="/"),e+=n.path(!0),n.F.query){for(var r="",i=0,u=n.F.query.split("&"),s=u.length;i<s;i++){var c=(u[i]||"").split("=");r+="&"+o.decodeQuery(c[0],this.F.escapeQuerySpace).replace(/&/g,"%26"),void 0!==c[1]&&(r+="="+o.decodeQuery(c[1],this.F.escapeQuerySpace).replace(/&/g,"%26"))}e+="?"+r.substring(1)}return e+o.decodeQuery(n.hash(),!0)},u.absoluteTo=function(t){var n,e,r,i=this.clone(),u=["protocol","username","password","hostname","port"];if(this.F.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t instanceof o||(t=new o(t)),i.F.protocol)return i;if(i.F.protocol=t.F.protocol,this.F.hostname)return i;for(e=0;r=u[e];e++)i.F[r]=t.F[r];return i.F.path?(".."===i.F.path.substring(-2)&&(i.F.path+="/"),"/"!==i.path().charAt(0)&&(n=(n=t.directory())||(0===t.path().indexOf("/")?"/":""),i.F.path=(n?n+"/":"")+i.F.path,i.normalizePath())):(i.F.path=t.F.path,i.F.query||(i.F.query=t.F.query)),i.build(),i},u.relativeTo=function(t){var n,e,r,i,u,s=this.clone().normalize();if(s.F.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t=new o(t).normalize(),n=s.F,e=t.F,i=s.path(),u=t.path(),"/"!==i.charAt(0))throw new Error("URI is already relative");if("/"!==u.charAt(0))throw new Error("Cannot calculate a URI relative to another relative URI");if(n.protocol===e.protocol&&(n.protocol=null),n.username!==e.username||n.password!==e.password)return s.build();if(null!==n.protocol||null!==n.username||null!==n.password)return s.build();if(n.hostname!==e.hostname||n.port!==e.port)return s.build();if(n.hostname=null,n.port=null,i===u)return n.path="",s.build();if(!(r=o.commonPath(i,u)))return s.build();var c=e.path.substring(r.length).replace(/[^\\/]*$/,"").replace(/.*?\\//g,"../");return n.path=c+n.path.substring(r.length)||"./",s.build()},u.equals=function(t){var n,e,r,i,u,c=this.clone(),a=new o(t),h={};if(c.normalize(),a.normalize(),c.toString()===a.toString())return!0;if(r=c.query(),i=a.query(),c.query(""),a.query(""),c.toString()!==a.toString())return!1;if(r.length!==i.length)return!1;for(u in n=o.parseQuery(r,this.F.escapeQuerySpace),e=o.parseQuery(i,this.F.escapeQuerySpace),n)if(s.call(n,u)){if(f(n[u])){if(!d(n[u],e[u]))return!1}else if(n[u]!==e[u])return!1;h[u]=!0}for(u in e)if(s.call(e,u)&&!h[u])return!1;return!0},u.preventInvalidHostname=function(t){return this.F.preventInvalidHostname=!!t,this},u.duplicateQueryParameters=function(t){return this.F.duplicateQueryParameters=!!t,this},u.escapeQuerySpace=function(t){return this.F.escapeQuerySpace=!!t,this},o},(Ln=Hn).exports?Ln.exports=Vn(function(){return zn||(zn=1,t=Yn,n=Yn.exports,function(e){var r=n&&!n.nodeType&&n,i=!t.nodeType&&t,o="object"==typeof c&&c;o.global!==o&&o.window!==o&&o.self!==o||(e=o);var u,s,a=2147483647,f=36,h=/^xn--/,l=/[^\\x20-\\x7E]/,d={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=Math.floor,m=String.fromCharCode;function g(t){throw new RangeError(d[t])}function v(t,n){for(var e=t.length,r=[];e--;)r[e]=n(t[e]);return r}function p(t,n){var e=t.split("@"),r="";return e.length>1&&(r=e[0]+"@",t=e[1]),r+v((t=t.replace(/[\\x2E\\u3002\\uFF0E\\uFF61]/g,".")).split("."),n).join(".")}function y(t){for(var n,e,r=[],i=0,o=t.length;i<o;)(n=t.charCodeAt(i++))>=55296&&n<=56319&&i<o?56320==(64512&(e=t.charCodeAt(i++)))?r.push(((1023&n)<<10)+(1023&e)+65536):(r.push(n),i--):r.push(n);return r}function b(t){return v(t,(function(t){var n="";return t>65535&&(n+=m((t-=65536)>>>10&1023|55296),t=56320|1023&t),n+m(t)})).join("")}function M(t,n){return t+22+75*(t<26)-((0!=n)<<5)}function A(t,n,e){var r=0;for(t=e?w(t/700):t>>1,t+=w(t/n);t>455;r+=f)t=w(t/35);return w(r+36*t/(t+38))}function x(t){var n,e,r,i,o,u,s,c,h,l,d,m=[],v=t.length,p=0,y=128,M=72;for((e=t.lastIndexOf("-"))<0&&(e=0),r=0;r<e;++r)t.charCodeAt(r)>=128&&g("not-basic"),m.push(t.charCodeAt(r));for(i=e>0?e+1:0;i<v;){for(o=p,u=1,s=f;i>=v&&g("invalid-input"),((c=(d=t.charCodeAt(i++))-48<10?d-22:d-65<26?d-65:d-97<26?d-97:f)>=f||c>w((a-p)/u))&&g("overflow"),p+=c*u,!(c<(h=s<=M?1:s>=M+26?26:s-M));s+=f)u>w(a/(l=f-h))&&g("overflow"),u*=l;M=A(p-o,n=m.length+1,0==o),w(p/n)>a-y&&g("overflow"),y+=w(p/n),p%=n,m.splice(p++,0,y)}return b(m)}function E(t){var n,e,r,i,o,u,s,c,h,l,d,v,p,b,x,E=[];for(v=(t=y(t)).length,n=128,e=0,o=72,u=0;u<v;++u)(d=t[u])<128&&E.push(m(d));for(r=i=E.length,i&&E.push("-");r<v;){for(s=a,u=0;u<v;++u)(d=t[u])>=n&&d<s&&(s=d);for(s-n>w((a-e)/(p=r+1))&&g("overflow"),e+=(s-n)*p,n=s,u=0;u<v;++u)if((d=t[u])<n&&++e>a&&g("overflow"),d==n){for(c=e,h=f;!(c<(l=h<=o?1:h>=o+26?26:h-o));h+=f)x=c-l,b=f-l,E.push(m(M(l+x%b,0))),c=w(x/b);E.push(m(M(c,0))),o=A(e,p,r==i),e=0,++r}++e,++n}return E.join("")}if(u={version:"1.3.2",ucs2:{decode:y,encode:b},decode:x,encode:E,toASCII:function(t){return p(t,(function(t){return l.test(t)?"xn--"+E(t):t}))},toUnicode:function(t){return p(t,(function(t){return h.test(t)?x(t.slice(4).toLowerCase()):t}))}},r&&i)if(t.exports==r)i.exports=u;else for(s in u)u.hasOwnProperty(s)&&(r[s]=u[s]);else e.punycode=u}(Zn)),Yn.exports;var t,n}(),function(){return Cn||(Cn=1,n=Qn,e=function(t){var n=t&&t.IPv6;return{best:function(t){var n,e,r=t.toLowerCase().split(":"),i=r.length,o=8;for(""===r[0]&&""===r[1]&&""===r[2]?(r.shift(),r.shift()):""===r[0]&&""===r[1]?r.shift():""===r[i-1]&&""===r[i-2]&&r.pop(),-1!==r[(i=r.length)-1].indexOf(".")&&(o=7),n=0;n<i&&""!==r[n];n++);if(n<o)for(r.splice(n,1,"0000");r.length<o;)r.splice(n,0,"0000");for(var u=0;u<o;u++){e=r[u].split("");for(var s=0;s<3&&"0"===e[0]&&e.length>1;s++)e.splice(0,1);r[u]=e.join("")}var c=-1,a=0,f=0,h=-1,l=!1;for(u=0;u<o;u++)l?"0"===r[u]?f+=1:(l=!1,f>a&&(c=h,a=f)):"0"===r[u]&&(l=!0,h=u,f=1);f>a&&(c=h,a=f),a>1&&r.splice(c,a,""),i=r.length;var d="";for(""===r[0]&&(d=":"),u=0;u<i&&(d+=r[u],u!==i-1);u++)d+=":";return""===r[i-1]&&(d+=":"),d},noConflict:function(){return t.IPv6===this&&(t.IPv6=n),this}}},(t=Wn).exports?t.exports=e():n.IPv6=e(n)),Wn.exports;var t,n,e}(),function(){return Dn||(Dn=1,n=Gn,e=function(t){var n=t&&t.SecondLevelDomains,e={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ",bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ",ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ",do:" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ",es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ",id:" ac co go mil net or sch web ",il:" ac co gov idf k12 muni net org ",in:" ac co edu ernet firm gen gov i ind mil net nic org res ",iq:" com edu gov i mil net org ",ir:" ac co dnssec gov i id net org sch ",it:" edu gov ",je:" co net org ",jo:" com edu gov mil name net org sch ",jp:" ac ad co ed go gr lg ne or ",ke:" ac co go info me mobi ne or sc ",kh:" com edu gov mil net org per ",ki:" biz com de edu gov info mob net org tel ",km:" asso com coop edu gouv k medecin mil nom notaires pharmaciens presse tm veterinaire ",kn:" edu gov net org ",kr:" ac busan chungbuk chungnam co daegu daejeon es gangwon go gwangju gyeongbuk gyeonggi gyeongnam hs incheon jeju jeonbuk jeonnam k kg mil ms ne or pe re sc seoul ulsan ",kw:" com edu gov net org ",ky:" com edu gov net org ",kz:" com edu gov mil net org ",lb:" com edu gov net org ",lk:" assn com edu gov grp hotel int ltd net ngo org sch soc web ",lr:" com edu gov net org ",lv:" asn com conf edu gov id mil net org ",ly:" com edu gov id med net org plc sch ",ma:" ac co gov m net org press ",mc:" asso tm ",me:" ac co edu gov its net org priv ",mg:" com edu gov mil nom org prd tm ",mk:" com edu gov inf name net org pro ",ml:" com edu gov net org presse ",mn:" edu gov org ",mo:" com edu gov net org ",mt:" com edu gov net org ",mv:" aero biz com coop edu gov info int mil museum name net org pro ",mw:" ac co com coop edu gov int museum net org ",mx:" com edu gob net org ",my:" com edu gov mil name net org sch ",nf:" arts com firm info net other per rec store web ",ng:" biz com edu gov mil mobi name net org sch ",ni:" ac co com edu gob mil net nom org ",np:" com edu gov mil net org ",nr:" biz com edu gov info net org ",om:" ac biz co com edu gov med mil museum net org pro sch ",pe:" com edu gob mil net nom org sld ",ph:" com edu gov i mil net ngo org ",pk:" biz com edu fam gob gok gon gop gos gov net org web ",pl:" art bialystok biz com edu gda gdansk gorzow gov info katowice krakow lodz lublin mil net ngo olsztyn org poznan pwr radom slupsk szczecin torun warszawa waw wroc wroclaw zgora ",pr:" ac biz com edu est gov info isla name net org pro prof ",ps:" com edu gov net org plo sec ",pw:" belau co ed go ne or ",ro:" arts com firm info nom nt org rec store tm www ",rs:" ac co edu gov in org ",sb:" com edu gov net org ",sc:" com edu gov net org ",sh:" co com edu gov net nom org ",sl:" com edu gov net org ",st:" co com consulado edu embaixada gov mil net org principe saotome store ",sv:" com edu gob org red ",sz:" ac co org ",tr:" av bbs bel biz com dr edu gen gov info k12 name net org pol tel tsk tv web ",tt:" aero biz cat co com coop edu gov info int jobs mil mobi museum name net org pro tel travel ",tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org ",mz:" ac co edu gov org ",na:" co com ",nz:" ac co cri geek gen govt health iwi maori mil net org parliament school ",pa:" abo ac com edu gob ing med net nom org sld ",pt:" com edu gov int net nome org publ ",py:" com edu gov mil net org ",qa:" com edu gov mil net org ",re:" asso com nom ",ru:" ac adygeya altai amur arkhangelsk astrakhan bashkiria belgorod bir bryansk buryatia cbg chel chelyabinsk chita chukotka chuvashia com dagestan e-burg edu gov grozny int irkutsk ivanovo izhevsk jar joshkar-ola kalmykia kaluga kamchatka karelia kazan kchr kemerovo khabarovsk khakassia khv kirov koenig komi kostroma kranoyarsk kuban kurgan kursk lipetsk magadan mari mari-el marine mil mordovia mosreg msk murmansk nalchik net nnov nov novosibirsk nsk omsk orenburg org oryol penza perm pp pskov ptz rnd ryazan sakhalin samara saratov simbirsk smolensk spb stavropol stv surgut tambov tatarstan tom tomsk tsaritsyn tsk tula tuva tver tyumen udm udmurtia ulan-ude vladikavkaz vladimir vladivostok volgograd vologda voronezh vrn vyatka yakutia yamal yekaterinburg yuzhno-sakhalinsk ",rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ",tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ",us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ",org:"ae",de:"com "},has:function(t){var n=t.lastIndexOf(".");if(n<=0||n>=t.length-1)return!1;var r=t.lastIndexOf(".",n-1);if(r<=0||r>=n-1)return!1;var i=e.list[t.slice(n+1)];return!!i&&i.indexOf(" "+t.slice(r+1,n)+" ")>=0},is:function(t){var n=t.lastIndexOf(".");if(n<=0||n>=t.length-1)return!1;if(t.lastIndexOf(".",n-1)>=0)return!1;var r=e.list[t.slice(n+1)];return!!r&&r.indexOf(" "+t.slice(0,n)+" ")>=0},get:function(t){var n=t.lastIndexOf(".");if(n<=0||n>=t.length-1)return null;var r=t.lastIndexOf(".",n-1);if(r<=0||r>=n-1)return null;var i=e.list[t.slice(n+1)];return i?i.indexOf(" "+t.slice(r+1,n)+" ")<0?null:t.slice(r+1):null},noConflict:function(){return t.SecondLevelDomains===this&&(t.SecondLevelDomains=n),this}};return e},(t=Jn).exports?t.exports=e():n.SecondLevelDomains=e(n)),Jn.exports;var t,n,e}()):_n.URI=Vn(_n.punycode,_n.IPv6,_n.SecondLevelDomains,_n)),Hn.exports),Kn=a(Xn);function te(t,n){if(null===t||"object"!=typeof t)return t;n=o(n,!1);const e=new t.constructor;for(const r in t)if(t.hasOwnProperty(r)){let i=t[r];n&&(i=te(i,n)),e[r]=i}return e}function ne(t,e,r){r=o(r,!1);const i={},u=n(t),s=n(e);let c,a,f;if(u)for(c in t)t.hasOwnProperty(c)&&(a=t[c],s&&r&&"object"==typeof a&&e.hasOwnProperty(c)?(f=e[c],i[c]="object"==typeof f?ne(a,f,r):a):i[c]=a);if(s)for(c in e)e.hasOwnProperty(c)&&!i.hasOwnProperty(c)&&(f=e[c],i[c]=f);return i}function ee(){let t,n;const e=new Promise((function(e,r){t=e,n=r}));return{resolve:t,reject:n,promise:e}}function re(t,n){let e;return"undefined"!=typeof document&&(e=document),re.C(t,n,e)}re.C=function(t,r,i){if(!n(t))throw new e("relative uri is required.");if(!n(r)){if(void 0===i)return t;r=o(i.baseURI,i.location.href)}const u=new Kn(t);return""!==u.scheme()?u.toString():u.absoluteTo(r).toString()};const ie={};function oe(t,e,r){n(e)||(e=t.width),n(r)||(r=t.height);let i=ie[e];n(i)||(i={},ie[e]=i);let o=i[r];if(!n(o)){const t=document.createElement("canvas");t.width=e,t.height=r,o=t.getContext("2d",{willReadFrequently:!0}),o.globalCompositeOperation="copy",i[r]=o}return o.drawImage(t,0,0,e,r),o.getImageData(0,0,e,r).data}const ue=/^blob:/i;function se(t){return r.typeOf.string("uri",t),ue.test(t)}let ce;const ae=/^data:/i;function fe(t){return r.typeOf.string("uri",t),ae.test(t)}var he=Object.freeze({UNISSUED:0,ISSUED:1,ACTIVE:2,RECEIVED:3,CANCELLED:4,FAILED:5}),le=Object.freeze({TERRAIN:0,IMAGERY:1,TILES3D:2,OTHER:3});function de(t){t=o(t,o.EMPTY_OBJECT);const n=o(t.throttleByServer,!1),e=o(t.throttle,!1);this.url=t.url,this.requestFunction=t.requestFunction,this.cancelFunction=t.cancelFunction,this.priorityFunction=t.priorityFunction,this.priority=o(t.priority,0),this.throttle=e,this.throttleByServer=n,this.type=o(t.type,le.OTHER),this.serverKey=t.serverKey,this.state=he.UNISSUED,this.deferred=void 0,this.cancelled=!1}function we(t,n,e){this.statusCode=t,this.response=n,this.responseHeaders=e,"string"==typeof this.responseHeaders&&(this.responseHeaders=function(t){const n={};if(!t)return n;const e=t.split("\\r\\n");for(let t=0;t<e.length;++t){const r=e[t],i=r.indexOf(": ");if(i>0){const t=r.substring(0,i),e=r.substring(i+2);n[t]=e}}return n}(this.responseHeaders))}function me(){this.D=[],this.B=[],this.L=[],this._=!1}function ge(t,n){return n-t}function ve(t){r.typeOf.object("options",t),r.defined("options.comparator",t.comparator),this.V=t.comparator,this.H=[],this.Y=0,this.Z=void 0}function pe(t,n,e){const r=t[n];t[n]=t[e],t[e]=r}de.prototype.cancel=function(){this.cancelled=!0},de.prototype.clone=function(t){return n(t)?(t.url=this.url,t.requestFunction=this.requestFunction,t.cancelFunction=this.cancelFunction,t.priorityFunction=this.priorityFunction,t.priority=this.priority,t.throttle=this.throttle,t.throttleByServer=this.throttleByServer,t.type=this.type,t.serverKey=this.serverKey,t.state=he.UNISSUED,t.deferred=void 0,t.cancelled=!1,t):new de(this)},we.prototype.toString=function(){let t="Request has failed.";return n(this.statusCode)&&(t+=` Status Code: ${this.statusCode}`),t},Object.defineProperties(me.prototype,{numberOfListeners:{get:function(){return this.D.length-this.L.length}}}),me.prototype.addEventListener=function(t,n){r.typeOf.func("listener",t),this.D.push(t),this.B.push(n);const e=this;return function(){e.removeEventListener(t,n)}},me.prototype.removeEventListener=function(t,n){r.typeOf.func("listener",t);const e=this.D,i=this.B;let o=-1;for(let r=0;r<e.length;r++)if(e[r]===t&&i[r]===n){o=r;break}return-1!==o&&(this._?(this.L.push(o),e[o]=void 0,i[o]=void 0):(e.splice(o,1),i.splice(o,1)),!0)},me.prototype.raiseEvent=function(){let t;this._=!0;const e=this.D,r=this.B;let i=e.length;for(t=0;t<i;t++)n(e[t])&&e[t].apply(r[t],arguments);const o=this.L;if(i=o.length,i>0){for(o.sort(ge),t=0;t<i;t++){const n=o[t];e.splice(n,1),r.splice(n,1)}o.length=0}this._=!1},Object.defineProperties(ve.prototype,{length:{get:function(){return this.Y}},internalArray:{get:function(){return this.H}},maximumLength:{get:function(){return this.Z},set:function(t){r.typeOf.number.greaterThanOrEquals("maximumLength",t,0);const n=this.Y;if(t<n){const e=this.H;for(let r=t;r<n;++r)e[r]=void 0;this.Y=t,e.length=t}this.Z=t}},comparator:{get:function(){return this.V}}}),ve.prototype.reserve=function(t){t=o(t,this.Y),this.H.length=t},ve.prototype.heapify=function(t){t=o(t,0);const n=this.Y,e=this.V,r=this.H;let i=-1,u=!0;for(;u;){const o=2*(t+1),s=o-1;i=s<n&&e(r[s],r[t])<0?s:t,o<n&&e(r[o],r[i])<0&&(i=o),i!==t?(pe(r,i,t),t=i):u=!1}},ve.prototype.resort=function(){const t=this.Y;for(let n=Math.ceil(t/2);n>=0;--n)this.heapify(n)},ve.prototype.insert=function(t){r.defined("element",t);const e=this.H,i=this.V,o=this.Z;let u,s=this.Y++;for(s<e.length?e[s]=t:e.push(t);0!==s;){const t=Math.floor((s-1)/2);if(!(i(e[s],e[t])<0))break;pe(e,s,t),s=t}return n(o)&&this.Y>o&&(u=e[o],this.Y=o),u},ve.prototype.pop=function(t){if(t=o(t,0),0===this.Y)return;r.typeOf.number.lessThan("index",t,this.Y);const n=this.H,e=n[t];return pe(n,t,--this.Y),this.heapify(t),n[this.Y]=void 0,e};const ye={numberOfAttemptedRequests:0,numberOfActiveRequests:0,numberOfCancelledRequests:0,numberOfCancelledActiveRequests:0,numberOfFailedRequests:0,numberOfActiveRequestsEver:0,lastNumberOfActiveRequests:0};let be=20;const Me=new ve({comparator:function(t,n){return t.priority-n.priority}});Me.maximumLength=be,Me.reserve(be);const Ae=[];let xe={};const Ee="undefined"!=typeof document?new Kn(document.location.href):new Kn,ke=new me;function qe(){}function $e(t){n(t.priorityFunction)&&(t.priority=t.priorityFunction())}function Se(t){return t.state===he.UNISSUED&&(t.state=he.ISSUED,t.deferred=ee()),t.deferred.promise}function Ie(t){const n=Se(t);return t.state=he.ACTIVE,Ae.push(t),++ye.numberOfActiveRequests,++ye.numberOfActiveRequestsEver,++xe[t.serverKey],t.requestFunction().then(function(t){return function(n){if(t.state===he.CANCELLED)return;const e=t.deferred;--ye.numberOfActiveRequests,--xe[t.serverKey],ke.raiseEvent(),t.state=he.RECEIVED,t.deferred=void 0,e.resolve(n)}}(t)).catch(function(t){return function(n){t.state!==he.CANCELLED&&(++ye.numberOfFailedRequests,--ye.numberOfActiveRequests,--xe[t.serverKey],ke.raiseEvent(n),t.state=he.FAILED,t.deferred.reject(n))}}(t)),n}function Oe(t){const e=t.state===he.ACTIVE;if(t.state=he.CANCELLED,++ye.numberOfCancelledRequests,n(t.deferred)){const n=t.deferred;t.deferred=void 0,n.reject()}e&&(--ye.numberOfActiveRequests,--xe[t.serverKey],++ye.numberOfCancelledActiveRequests),n(t.cancelFunction)&&t.cancelFunction()}qe.maximumRequests=50,qe.maximumRequestsPerServer=18,qe.requestsByServer={},qe.throttleRequests=!0,qe.debugShowStatistics=!1,qe.requestCompletedEvent=ke,Object.defineProperties(qe,{statistics:{get:function(){return ye}},priorityHeapLength:{get:function(){return be},set:function(t){if(t<be)for(;Me.length>t;)Oe(Me.pop());be=t,Me.maximumLength=t,Me.reserve(t)}}}),qe.serverHasOpenSlots=function(t,n){n=o(n,1);const e=o(qe.requestsByServer[t],qe.maximumRequestsPerServer);return xe[t]+n<=e},qe.heapHasOpenSlots=function(t){return Me.length+t<=be},qe.update=function(){let t,n,e=0;const r=Ae.length;for(t=0;t<r;++t)n=Ae[t],n.cancelled&&Oe(n),n.state===he.ACTIVE?e>0&&(Ae[t-e]=n):++e;Ae.length-=e;const i=Me.internalArray,o=Me.length;for(t=0;t<o;++t)$e(i[t]);Me.resort();const u=Math.max(qe.maximumRequests-Ae.length,0);let s=0;for(;s<u&&Me.length>0;)n=Me.pop(),n.cancelled?Oe(n):!n.throttleByServer||qe.serverHasOpenSlots(n.serverKey)?(Ie(n),++s):Oe(n);qe.debugShowStatistics&&(0===ye.numberOfActiveRequests&&ye.lastNumberOfActiveRequests>0&&(ye.numberOfAttemptedRequests>0&&(ye.numberOfAttemptedRequests=0),ye.numberOfCancelledRequests>0&&(ye.numberOfCancelledRequests=0),ye.numberOfCancelledActiveRequests>0&&(ye.numberOfCancelledActiveRequests=0),ye.numberOfFailedRequests>0&&(ye.numberOfFailedRequests=0)),ye.lastNumberOfActiveRequests=ye.numberOfActiveRequests)},qe.getServerKey=function(t){r.typeOf.string("url",t);let e=new Kn(t);""===e.scheme()&&(e=e.absoluteTo(Ee),e.normalize());let i=e.authority();return/:/.test(i)||(i=`${i}:${"https"===e.scheme()?"443":"80"}`),n(xe[i])||(xe[i]=0),i},qe.request=function(t){if(r.typeOf.object("request",t),r.typeOf.string("request.url",t.url),r.typeOf.func("request.requestFunction",t.requestFunction),fe(t.url)||se(t.url))return ke.raiseEvent(),t.state=he.RECEIVED,t.requestFunction();if(++ye.numberOfAttemptedRequests,n(t.serverKey)||(t.serverKey=qe.getServerKey(t.url)),qe.throttleRequests&&t.throttleByServer&&!qe.serverHasOpenSlots(t.serverKey))return;if(!qe.throttleRequests||!t.throttle)return Ie(t);if(Ae.length>=qe.maximumRequests)return;$e(t);const e=Me.insert(t);if(n(e)){if(e===t)return;Oe(e)}return Se(t)},qe.clearForSpecs=function(){for(;Me.length>0;)Oe(Me.pop());const t=Ae.length;for(let n=0;n<t;++n)Oe(Ae[n]);Ae.length=0,xe={},ye.numberOfAttemptedRequests=0,ye.numberOfActiveRequests=0,ye.numberOfCancelledRequests=0,ye.numberOfCancelledActiveRequests=0,ye.numberOfFailedRequests=0,ye.numberOfActiveRequestsEver=0,ye.lastNumberOfActiveRequests=0},qe.numberOfActiveRequestsByServer=function(t){return xe[t]},qe.requestHeap=Me;const Re={};let Pe={};Re.add=function(t,r){if(!n(t))throw new e("host is required.");if(!n(r)||r<=0)throw new e("port is required to be greater than 0.");const i=`${t.toLowerCase()}:${r}`;n(Pe[i])||(Pe[i]=!0)},Re.remove=function(t,r){if(!n(t))throw new e("host is required.");if(!n(r)||r<=0)throw new e("port is required to be greater than 0.");const i=`${t.toLowerCase()}:${r}`;n(Pe[i])&&delete Pe[i]},Re.contains=function(t){if(!n(t))throw new e("url is required.");const r=function(t){const n=new Kn(t);n.normalize();let e=n.authority();if(0!==e.length){if(n.authority(e),-1!==e.indexOf("@")){const t=e.split("@");e=t[1]}if(-1===e.indexOf(":")){let t=n.scheme();if(0===t.length&&(t=window.location.protocol,t=t.substring(0,t.length-1)),"http"===t)e+=":80";else{if("https"!==t)return;e+=":443"}}return e}}(t);return!(!n(r)||!n(Pe[r]))},Re.clear=function(){Pe={}};const je=function(){try{const t=new XMLHttpRequest;return t.open("GET","#",!0),t.responseType="blob","blob"===t.responseType}catch(t){return!1}}();function Fe(t){"string"==typeof(t=o(t,o.EMPTY_OBJECT))&&(t={url:t}),r.typeOf.string("options.url",t.url),this.W=void 0,this.J=Ne(t.templateValues,{}),this.G=Ne(t.queryParameters,{}),this.headers=Ne(t.headers,{}),this.request=o(t.request,new de),this.proxy=t.proxy,this.retryCallback=t.retryCallback,this.retryAttempts=o(t.retryAttempts,0),this.X=0,o(t.parseUrl,!0)?this.parseUrl(t.url,!0,!0):this.W=t.url,this.K=t.credits}function Ne(t,e){return n(t)?te(t):e}let Ue;function Te(t,e,r){if(!r)return ne(t,e);const i=te(t,!0);for(const t in e)if(e.hasOwnProperty(t)){let r=i[t];const o=e[t];n(r)?(Array.isArray(r)||(r=i[t]=[r]),i[t]=r.concat(o)):i[t]=Array.isArray(o)?o.slice():o}return i}function ze(t){const e=t.resource,r=t.flipY,i=t.skipColorSpaceConversion,o=t.preferImageBitmap,u=e.request;u.url=e.url,u.requestFunction=function(){let t=!1;e.isDataUri||e.isBlobUri||(t=e.isCrossOriginUrl);const n=ee();return Fe.nt.createImage(u,t,n,r,i,o),n.promise};const s=qe.request(u);if(n(s))return s.catch((function(t){return u.state!==he.FAILED?Promise.reject(t):e.retryOnError(t).then((function(n){return n?(u.state=he.UNISSUED,u.deferred=void 0,ze({resource:e,flipY:r,skipColorSpaceConversion:i,preferImageBitmap:o})):Promise.reject(t)}))}))}function Ce(t,e,r){const i={};i[e]=r,t.setQueryParameters(i);const o=t.request,u=t.url;o.url=u,o.requestFunction=function(){const t=ee();return window[r]=function(n){t.resolve(n);try{delete window[r]}catch(t){window[r]=void 0}},Fe.nt.loadAndExecuteScript(u,r,t),t.promise};const s=qe.request(o);if(n(s))return s.catch((function(n){return o.state!==he.FAILED?Promise.reject(n):t.retryOnError(n).then((function(i){return i?(o.state=he.UNISSUED,o.deferred=void 0,Ce(t,e,r)):Promise.reject(n)}))}))}function De(t){if(t.state===he.ISSUED||t.state===he.ACTIVE)throw new H("The Resource is already being fetched.");t.state=he.UNISSUED,t.deferred=void 0}Fe.createIfNeeded=function(t){return t instanceof Fe?t.getDerivedResource({request:t.request}):"string"!=typeof t?t:new Fe({url:t})},Fe.supportsImageBitmapOptions=function(){return n(Ue)?Ue:"function"!=typeof createImageBitmap?(Ue=Promise.resolve(!1),Ue):(Ue=Fe.fetchBlob({url:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAABGdBTUEAAE4g3rEiDgAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAADElEQVQI12Ng6GAAAAEUAIngE3ZiAAAAAElFTkSuQmCC"}).then((function(t){return Promise.all([createImageBitmap(t,{imageOrientation:"flipY",premultiplyAlpha:"none",colorSpaceConversion:"none"}),createImageBitmap(t)])})).then((function(t){const n=oe(t[0]),e=oe(t[1]);return n[1]!==e[1]})).catch((function(){return!1})),Ue)},Object.defineProperties(Fe,{isBlobSupported:{get:function(){return je}}}),Object.defineProperties(Fe.prototype,{queryParameters:{get:function(){return this.G}},templateValues:{get:function(){return this.J}},url:{get:function(){return this.getUrlComponent(!0,!0)},set:function(t){this.parseUrl(t,!1,!1)}},extension:{get:function(){return function(t){if(!n(t))throw new e("uri is required.");const r=new Kn(t);r.normalize();let i=r.path(),o=i.lastIndexOf("/");return-1!==o&&(i=i.substr(o+1)),o=i.lastIndexOf("."),i=-1===o?"":i.substr(o+1),i}(this.W)}},isDataUri:{get:function(){return fe(this.W)}},isBlobUri:{get:function(){return se(this.W)}},isCrossOriginUrl:{get:function(){return function(t){n(ce)||(ce=document.createElement("a")),ce.href=window.location.href;const e=ce.host,r=ce.protocol;return ce.href=t,ce.href=ce.href,r!==ce.protocol||e!==ce.host}(this.W)}},hasHeaders:{get:function(){return Object.keys(this.headers).length>0}},credits:{get:function(){return this.K}}}),Fe.prototype.toString=function(){return this.getUrlComponent(!0,!0)},Fe.prototype.parseUrl=function(t,r,i,o){let u=new Kn(t);const s=0===(c=u.query()).length?{}:-1===c.indexOf("=")?{[c]:void 0}:function(t){if(!n(t))throw new e("queryString is required.");const r={};if(""===t)return r;const i=t.replace(/\\+/g,"%20").split(/[&;]/);for(let t=0,e=i.length;t<e;++t){const e=i[t].split("="),o=decodeURIComponent(e[0]);let u=e[1];u=n(u)?decodeURIComponent(u):"";const s=r[o];"string"==typeof s?r[o]=[s,u]:Array.isArray(s)?s.push(u):r[o]=u}return r}(c);var c;this.G=r?Te(s,this.queryParameters,i):s,u.search(""),u.fragment(""),n(o)&&""===u.scheme()&&(u=u.absoluteTo(re(o))),this.W=u.toString()},Fe.prototype.getUrlComponent=function(t,r){if(this.isDataUri)return this.W;let i=this.W;t&&(i=`${i}${function(t){const r=Object.keys(t);return 0===r.length?"":1!==r.length||n(t[r[0]])?`?${function(t){if(!n(t))throw new e("obj is required.");let r="";for(const n in t)if(t.hasOwnProperty(n)){const e=t[n],i=`${encodeURIComponent(n)}=`;if(Array.isArray(e))for(let t=0,n=e.length;t<n;++t)r+=`${i+encodeURIComponent(e[t])}&`;else r+=`${i+encodeURIComponent(e)}&`}return r=r.slice(0,-1),r}(t)}`:`?${r[0]}`}(this.queryParameters)}`),i=i.replace(/%7B/g,"{").replace(/%7D/g,"}");const o=this.J;return Object.keys(o).length>0&&(i=i.replace(/{(.*?)}/g,(function(t,e){const r=o[e];return n(r)?encodeURIComponent(r):t}))),r&&n(this.proxy)&&(i=this.proxy.getURL(i)),i},Fe.prototype.setQueryParameters=function(t,n){this.G=n?Te(this.G,t,!1):Te(t,this.G,!1)},Fe.prototype.appendQueryParameters=function(t){this.G=Te(t,this.G,!0)},Fe.prototype.setTemplateValues=function(t,n){this.J=n?ne(this.J,t):ne(t,this.J)},Fe.prototype.getDerivedResource=function(t){const e=this.clone();if(e.X=0,n(t.url)){const n=o(t.preserveQueryParameters,!1);e.parseUrl(t.url,!0,n,this.W)}return n(t.queryParameters)&&(e.G=ne(t.queryParameters,e.queryParameters)),n(t.templateValues)&&(e.J=ne(t.templateValues,e.templateValues)),n(t.headers)&&(e.headers=ne(t.headers,e.headers)),n(t.proxy)&&(e.proxy=t.proxy),n(t.request)&&(e.request=t.request),n(t.retryCallback)&&(e.retryCallback=t.retryCallback),n(t.retryAttempts)&&(e.retryAttempts=t.retryAttempts),e},Fe.prototype.retryOnError=function(t){const n=this.retryCallback;if("function"!=typeof n||this.X>=this.retryAttempts)return Promise.resolve(!1);const e=this;return Promise.resolve(n(this,t)).then((function(t){return++e.X,t}))},Fe.prototype.clone=function(t){return n(t)?(t.W=this.W,t.G=te(this.G),t.J=te(this.J),t.headers=te(this.headers),t.proxy=this.proxy,t.retryCallback=this.retryCallback,t.retryAttempts=this.retryAttempts,t.X=0,t.request=this.request.clone(),t):new Fe({url:this.W,queryParameters:this.queryParameters,templateValues:this.templateValues,headers:this.headers,proxy:this.proxy,retryCallback:this.retryCallback,retryAttempts:this.retryAttempts,request:this.request.clone(),parseUrl:!1,credits:n(this.credits)?this.credits.slice():void 0})},Fe.prototype.getBaseUri=function(t){return function(t,r){if(!n(t))throw new e("uri is required.");let i="";const o=t.lastIndexOf("/");return-1!==o&&(i=t.substring(0,o+1)),r?(0!==(t=new Kn(t)).query().length&&(i+=`?${t.query()}`),0!==t.fragment().length&&(i+=`#${t.fragment()}`),i):i}(this.getUrlComponent(t),t)},Fe.prototype.appendForwardSlash=function(){var t;this.W=(0!==(t=this.W).length&&"/"===t[t.length-1]||(t=`${t}/`),t)},Fe.prototype.fetchArrayBuffer=function(){return this.fetch({responseType:"arraybuffer"})},Fe.fetchArrayBuffer=function(t){return new Fe(t).fetchArrayBuffer()},Fe.prototype.fetchBlob=function(){return this.fetch({responseType:"blob"})},Fe.fetchBlob=function(t){return new Fe(t).fetchBlob()},Fe.prototype.fetchImage=function(t){t=o(t,o.EMPTY_OBJECT);const e=o(t.preferImageBitmap,!1),r=o(t.preferBlob,!1),i=o(t.flipY,!1),u=o(t.skipColorSpaceConversion,!1);if(De(this.request),!je||this.isDataUri||this.isBlobUri||!this.hasHeaders&&!r)return ze({resource:this,flipY:i,skipColorSpaceConversion:u,preferImageBitmap:e});const s=this.fetchBlob();if(!n(s))return;let c,a,f,h;return Fe.supportsImageBitmapOptions().then((function(t){return c=t,a=c&&e,s})).then((function(t){if(!n(t))return;if(h=t,a)return Fe.createImageBitmapFromBlob(t,{flipY:i,premultiplyAlpha:!1,skipColorSpaceConversion:u});const e=window.URL.createObjectURL(t);return f=new Fe({url:e}),ze({resource:f,flipY:i,skipColorSpaceConversion:u,preferImageBitmap:!1})})).then((function(t){if(n(t))return t.blob=h,a||window.URL.revokeObjectURL(f.url),t})).catch((function(t){return n(f)&&window.URL.revokeObjectURL(f.url),t.blob=h,Promise.reject(t)}))},Fe.fetchImage=function(t){return new Fe(t).fetchImage({flipY:t.flipY,skipColorSpaceConversion:t.skipColorSpaceConversion,preferBlob:t.preferBlob,preferImageBitmap:t.preferImageBitmap})},Fe.prototype.fetchText=function(){return this.fetch({responseType:"text"})},Fe.fetchText=function(t){return new Fe(t).fetchText()},Fe.prototype.fetchJson=function(){const t=this.fetch({responseType:"text",headers:{Accept:"application/json,*/*;q=0.01"}});if(n(t))return t.then((function(t){if(n(t))return JSON.parse(t)}))},Fe.fetchJson=function(t){return new Fe(t).fetchJson()},Fe.prototype.fetchXML=function(){return this.fetch({responseType:"document",overrideMimeType:"text/xml"})},Fe.fetchXML=function(t){return new Fe(t).fetchXML()},Fe.prototype.fetchJsonp=function(t){let e;t=o(t,"callback"),De(this.request);do{e=`loadJsonp${l.nextRandomNumber().toString().substring(2,8)}`}while(n(window[e]));return Ce(this,t,e)},Fe.fetchJsonp=function(t){return new Fe(t).fetchJsonp(t.callbackParameterName)},Fe.prototype.rt=function(t){const e=this;De(e.request);const r=e.request,i=e.url;r.url=i,r.requestFunction=function(){const o=t.responseType,u=ne(t.headers,e.headers),s=t.overrideMimeType,c=t.method,a=t.data,f=ee(),h=Fe.nt.loadWithXhr(i,o,c,a,u,f,s);return n(h)&&n(h.abort)&&(r.cancelFunction=function(){h.abort()}),f.promise};const o=qe.request(r);if(n(o))return o.then((function(t){return r.cancelFunction=void 0,t})).catch((function(n){return r.cancelFunction=void 0,r.state!==he.FAILED?Promise.reject(n):e.retryOnError(n).then((function(i){return i?(r.state=he.UNISSUED,r.deferred=void 0,e.fetch(t)):Promise.reject(n)}))}))};const Be=/^data:(.*?)(;base64)?,(.*)$/;function Le(t,n){const e=decodeURIComponent(n);return t?atob(e):e}function _e(t,n){const e=Le(t,n),r=new ArrayBuffer(e.length),i=new Uint8Array(r);for(let t=0;t<e.length;t++)i[t]=e.charCodeAt(t);return r}Fe.prototype.fetch=function(t){return(t=Ne(t,{})).method="GET",this.rt(t)},Fe.fetch=function(t){return new Fe(t).fetch({responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.prototype.delete=function(t){return(t=Ne(t,{})).method="DELETE",this.rt(t)},Fe.delete=function(t){return new Fe(t).delete({responseType:t.responseType,overrideMimeType:t.overrideMimeType,data:t.data})},Fe.prototype.head=function(t){return(t=Ne(t,{})).method="HEAD",this.rt(t)},Fe.head=function(t){return new Fe(t).head({responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.prototype.options=function(t){return(t=Ne(t,{})).method="OPTIONS",this.rt(t)},Fe.options=function(t){return new Fe(t).options({responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.prototype.post=function(t,n){return r.defined("data",t),(n=Ne(n,{})).method="POST",n.data=t,this.rt(n)},Fe.post=function(t){return new Fe(t).post(t.data,{responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.prototype.put=function(t,n){return r.defined("data",t),(n=Ne(n,{})).method="PUT",n.data=t,this.rt(n)},Fe.put=function(t){return new Fe(t).put(t.data,{responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.prototype.patch=function(t,n){return r.defined("data",t),(n=Ne(n,{})).method="PATCH",n.data=t,this.rt(n)},Fe.patch=function(t){return new Fe(t).patch(t.data,{responseType:t.responseType,overrideMimeType:t.overrideMimeType})},Fe.nt={},Fe.nt.loadImageElement=function(t,n,e){const r=new Image;r.onload=function(){0===r.naturalWidth&&0===r.naturalHeight&&0===r.width&&0===r.height&&(r.width=300,r.height=150),e.resolve(r)},r.onerror=function(t){e.reject(t)},n&&(Re.contains(t)?r.crossOrigin="use-credentials":r.crossOrigin=""),r.src=t},Fe.nt.createImage=function(t,e,r,i,o,u){const s=t.url;Fe.supportsImageBitmapOptions().then((function(c){if(!c||!u)return void Fe.nt.loadImageElement(s,e,r);const a=ee(),f=Fe.nt.loadWithXhr(s,"blob","GET",void 0,void 0,a,void 0,void 0,void 0);return n(f)&&n(f.abort)&&(t.cancelFunction=function(){f.abort()}),a.promise.then((function(t){if(n(t))return Fe.createImageBitmapFromBlob(t,{flipY:i,premultiplyAlpha:!1,skipColorSpaceConversion:o});r.reject(new H(`Successfully retrieved ${s} but it contained no content.`))})).then((function(t){r.resolve(t)}))})).catch((function(t){r.reject(t)}))},Fe.createImageBitmapFromBlob=function(t,n){return r.defined("options",n),r.typeOf.bool("options.flipY",n.flipY),r.typeOf.bool("options.premultiplyAlpha",n.premultiplyAlpha),r.typeOf.bool("options.skipColorSpaceConversion",n.skipColorSpaceConversion),createImageBitmap(t,{imageOrientation:n.flipY?"flipY":"none",premultiplyAlpha:n.premultiplyAlpha?"premultiply":"none",colorSpaceConversion:n.skipColorSpaceConversion?"none":"default"})};const Ve="undefined"==typeof XMLHttpRequest;function He(t){t=o(t,o.EMPTY_OBJECT),this.ot=void 0,this.ut=void 0,this.ct=-1,this.ft=-1,this.ht=-1,this.lt=-1,this.dt=-1,this.wt=-1,this.vt=-1,this.yt=0,this.bt=-1,this.Mt=o(t.addNewLeapSeconds,!0),n(t.data)?Ze(this,t.data):Ze(this,{columnNames:["dateIso8601","modifiedJulianDateUtc","xPoleWanderRadians","yPoleWanderRadians","ut1MinusUtcSeconds","lengthOfDayCorrectionSeconds","xCelestialPoleOffsetRadians","yCelestialPoleOffsetRadians","taiMinusUtcSeconds"],samples:[]})}function Ye(t,n){return Un.compare(t.julianDate,n)}function Ze(t,e){if(!n(e.columnNames))throw new H("Error in loaded EOP data: The columnNames property is required.");if(!n(e.samples))throw new H("Error in loaded EOP data: The samples property is required.");const r=e.columnNames.indexOf("modifiedJulianDateUtc"),i=e.columnNames.indexOf("xPoleWanderRadians"),o=e.columnNames.indexOf("yPoleWanderRadians"),u=e.columnNames.indexOf("ut1MinusUtcSeconds"),s=e.columnNames.indexOf("xCelestialPoleOffsetRadians"),c=e.columnNames.indexOf("yCelestialPoleOffsetRadians"),a=e.columnNames.indexOf("taiMinusUtcSeconds");if(r<0||i<0||o<0||u<0||s<0||c<0||a<0)throw new H("Error in loaded EOP data: The columnNames property must include modifiedJulianDateUtc, xPoleWanderRadians, yPoleWanderRadians, ut1MinusUtcSeconds, xCelestialPoleOffsetRadians, yCelestialPoleOffsetRadians, and taiMinusUtcSeconds columns");const f=t.ut=e.samples,h=t.ot=[];let l;t.ct=r,t.ft=i,t.ht=o,t.lt=u,t.dt=s,t.wt=c,t.vt=a,t.yt=e.columnNames.length,t.bt=void 0;const d=t.Mt;for(let e=0,i=f.length;e<i;e+=t.yt){const t=f[e+r],i=f[e+a],o=new Un(t+gn.MODIFIED_JULIAN_DATE_DIFFERENCE,i,vn.TAI);if(h.push(o),d){if(i!==l&&n(l)){const t=Un.leapSeconds,n=fn(t,o,Ye);if(n<0){const e=new mn(o,i);t.splice(~n,0,e)}}l=i}}}function We(t,n,e,r,i){const o=e*r;i.xPoleWander=n[o+t.ft],i.yPoleWander=n[o+t.ht],i.xPoleOffset=n[o+t.dt],i.yPoleOffset=n[o+t.wt],i.ut1MinusUtc=n[o+t.lt]}function Qe(t,n,e){return n+t*(e-n)}function Je(t,n,e,r,i,o,u){const s=t.yt;if(o>n.length-1)return u.xPoleWander=0,u.yPoleWander=0,u.xPoleOffset=0,u.yPoleOffset=0,u.ut1MinusUtc=0,u;const c=n[i],a=n[o];if(c.equals(a)||r.equals(c))return We(t,e,i,s,u),u;if(r.equals(a))return We(t,e,o,s,u),u;const f=Un.secondsDifference(r,c)/Un.secondsDifference(a,c),h=i*s,l=o*s;let d=e[h+t.lt],w=e[l+t.lt];const m=w-d;if(m>.5||m<-.5){const n=e[h+t.vt],i=e[l+t.vt];n!==i&&(a.equals(r)?d=w:w-=i-n)}return u.xPoleWander=Qe(f,e[h+t.ft],e[l+t.ft]),u.yPoleWander=Qe(f,e[h+t.ht],e[l+t.ht]),u.xPoleOffset=Qe(f,e[h+t.dt],e[l+t.dt]),u.yPoleOffset=Qe(f,e[h+t.wt],e[l+t.wt]),u.ut1MinusUtc=Qe(f,d,w),u}function Ge(t,n,e){this.heading=o(t,0),this.pitch=o(n,0),this.roll=o(e,0)}Fe.nt.loadWithXhr=function(t,r,i,u,s,c,a){const f=Be.exec(t);if(null!==f)return void c.resolve(function(t,n){n=o(n,"");const r=t[1],i=!!t[2],u=t[3];let s,c;switch(n){case"":case"text":return Le(i,u);case"arraybuffer":return _e(i,u);case"blob":return s=_e(i,u),new Blob([s],{type:r});case"document":return c=new DOMParser,c.parseFromString(Le(i,u),r);case"json":return JSON.parse(Le(i,u));default:throw new e(`Unhandled responseType: ${n}`)}}(f,r));if(Ve)return void function(t,n,e,r,i,o){fetch(t,{method:e,headers:i}).then((async t=>{if(!t.ok){const n={};return t.headers.forEach(((t,e)=>{n[e]=t})),void o.reject(new we(t.status,t,n))}switch(n){case"text":o.resolve(t.text());break;case"json":o.resolve(t.json());break;default:o.resolve(new Uint8Array(await t.arrayBuffer()).buffer)}})).catch((()=>{o.reject(new we)}))}(t,r,i,0,s,c);const h=new XMLHttpRequest;if(Re.contains(t)&&(h.withCredentials=!0),h.open(i,t,!0),n(a)&&n(h.overrideMimeType)&&h.overrideMimeType(a),n(s))for(const t in s)s.hasOwnProperty(t)&&h.setRequestHeader(t,s[t]);n(r)&&(h.responseType=r);let l=!1;return"string"==typeof t&&(l=0===t.indexOf("file://")||"undefined"!=typeof window&&"file://"===window.location.origin),h.onload=function(){if((h.status<200||h.status>=300)&&(!l||0!==h.status))return void c.reject(new we(h.status,h.response,h.getAllResponseHeaders()));const t=h.response,e=h.responseType;if("HEAD"===i||"OPTIONS"===i){const t=h.getAllResponseHeaders().trim().split(/[\\r\\n]+/),n={};return t.forEach((function(t){const e=t.split(": "),r=e.shift();n[r]=e.join(": ")})),void c.resolve(n)}if(204===h.status)c.resolve(void 0);else if(!n(t)||n(r)&&e!==r)if("json"===r&&"string"==typeof t)try{c.resolve(JSON.parse(t))}catch(t){c.reject(t)}else(""===e||"document"===e)&&n(h.responseXML)&&h.responseXML.hasChildNodes()?c.resolve(h.responseXML):""!==e&&"text"!==e||!n(h.responseText)?c.reject(new H("Invalid XMLHttpRequest response type.")):c.resolve(h.responseText);else c.resolve(t)},h.onerror=function(t){c.reject(new we)},h.send(u),h},Fe.nt.loadAndExecuteScript=function(t,n,e){return function(t){const n=document.createElement("script");return n.async=!0,n.src=t,new Promise(((t,e)=>{window.crossOriginIsolated&&n.setAttribute("crossorigin","anonymous");const r=document.getElementsByTagName("head")[0];n.onload=function(){n.onload=void 0,r.removeChild(n),t()},n.onerror=function(t){e(t)},r.appendChild(n)}))}(t).catch((function(t){e.reject(t)}))},Fe.At={},Fe.At.createImage=Fe.nt.createImage,Fe.At.loadWithXhr=Fe.nt.loadWithXhr,Fe.At.loadAndExecuteScript=Fe.nt.loadAndExecuteScript,Fe.DEFAULT=Object.freeze(new Fe({url:"undefined"==typeof document?"":document.location.href.split("?")[0]})),He.fromUrl=async function(t,n){r.defined("url",t),n=o(n,o.EMPTY_OBJECT);const e=Fe.createIfNeeded(t);let i;try{i=await e.fetchJson()}catch(t){throw new H(`An error occurred while retrieving the EOP data from the URL ${e.url}.`)}return new He({addNewLeapSeconds:n.addNewLeapSeconds,data:i})},He.NONE=Object.freeze({compute:function(t,e){return n(e)?(e.xPoleWander=0,e.yPoleWander=0,e.xPoleOffset=0,e.yPoleOffset=0,e.ut1MinusUtc=0):e=new hn(0,0,0,0,0),e}}),He.prototype.compute=function(t,e){if(!n(this.ut))return;if(n(e)||(e=new hn(0,0,0,0,0)),0===this.ut.length)return e.xPoleWander=0,e.yPoleWander=0,e.xPoleOffset=0,e.yPoleOffset=0,e.ut1MinusUtc=0,e;const r=this.ot,i=this.bt;let o=0,u=0;if(n(i)){const s=r[i],c=r[i+1],a=Un.lessThanOrEquals(s,t),f=!n(c),h=f||Un.greaterThanOrEquals(c,t);if(a&&h)return o=i,!f&&c.equals(t)&&++o,u=o+1,Je(this,r,this.ut,t,o,u,e),e}let s=fn(r,t,Un.compare,this.ct);return s>=0?(s<r.length-1&&r[s+1].equals(t)&&++s,o=s,u=s):(u=~s,o=u-1,o<0&&(o=0)),this.bt=o,Je(this,r,this.ut,t,o,u,e),e},Ge.fromQuaternion=function(t,r){if(!n(t))throw new e("quaternion is required");n(r)||(r=new Ge);const i=2*(t.w*t.y-t.z*t.x),o=1-2*(t.x*t.x+t.y*t.y),u=2*(t.w*t.x+t.y*t.z),s=1-2*(t.y*t.y+t.z*t.z),c=2*(t.w*t.z+t.x*t.y);return r.heading=-Math.atan2(c,s),r.roll=Math.atan2(u,o),r.pitch=-l.asinClamped(i),r},Ge.fromDegrees=function(t,r,i,o){if(!n(t))throw new e("heading is required");if(!n(r))throw new e("pitch is required");if(!n(i))throw new e("roll is required");return n(o)||(o=new Ge),o.heading=t*l.RADIANS_PER_DEGREE,o.pitch=r*l.RADIANS_PER_DEGREE,o.roll=i*l.RADIANS_PER_DEGREE,o},Ge.clone=function(t,e){if(n(t))return n(e)?(e.heading=t.heading,e.pitch=t.pitch,e.roll=t.roll,e):new Ge(t.heading,t.pitch,t.roll)},Ge.equals=function(t,e){return t===e||n(t)&&n(e)&&t.heading===e.heading&&t.pitch===e.pitch&&t.roll===e.roll},Ge.equalsEpsilon=function(t,e,r,i){return t===e||n(t)&&n(e)&&l.equalsEpsilon(t.heading,e.heading,r,i)&&l.equalsEpsilon(t.pitch,e.pitch,r,i)&&l.equalsEpsilon(t.roll,e.roll,r,i)},Ge.prototype.clone=function(t){return Ge.clone(this,t)},Ge.prototype.equals=function(t){return Ge.equals(this,t)},Ge.prototype.equalsEpsilon=function(t,n,e){return Ge.equalsEpsilon(this,t,n,e)},Ge.prototype.toString=function(){return`(${this.heading}, ${this.pitch}, ${this.roll})`};const Xe=/((?:.*\\/)|^)Cesium\\.js(?:\\?|\\#|$)/;let Ke,tr,nr;function er(t){return"undefined"==typeof document?t:(n(Ke)||(Ke=document.createElement("a")),Ke.href=t,Ke.href)}function rr(){if(n(tr))return tr;let r;if(r="undefined"!=typeof CESIUM_BASE_URL?CESIUM_BASE_URL:n("undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("building-worker.generated.js",document.baseURI).href)?re(".","undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:t&&"SCRIPT"===t.tagName.toUpperCase()&&t.src||new URL("building-worker.generated.js",document.baseURI).href):"object"==typeof define&&n(define.amd)&&!define.amd.toUrlUndefined&&n(require.toUrl)?re("..",ur("Core/buildModuleUrl.js")):function(){const t=document.getElementsByTagName("script");for(let n=0,e=t.length;n<e;++n){const e=t[n].getAttribute("src"),r=Xe.exec(e);if(null!==r)return r[1]}}(),!n(r))throw new e("Unable to determine Cesium base URL automatically, try defining a global variable called CESIUM_BASE_URL.");return tr=new Fe({url:er(r)}),tr.appendForwardSlash(),tr}function ir(t){return er(require.toUrl(`../${t}`))}function or(t){return rr().getDerivedResource({url:t}).url}function ur(t){return n(nr)||(nr="object"==typeof define&&n(define.amd)&&!define.amd.toUrlUndefined&&n(require.toUrl)?ir:or),nr(t)}function sr(t,n,e){this.x=t,this.y=n,this.s=e}function cr(t){t=o(t,o.EMPTY_OBJECT),this.xt=Fe.createIfNeeded(t.xysFileUrlTemplate),this.Et=o(t.interpolationOrder,9),this.kt=o(t.sampleZeroJulianEphemerisDate,2442396.5),this.qt=new Un(this.kt,0,vn.TAI),this.$t=o(t.stepSizeDays,1),this.St=o(t.samplesPerXysFile,1e3),this.It=o(t.totalSamples,27426),this.ut=new Array(3*this.It),this.Ot=[];const n=this.Et,e=this.Rt=new Array(n+1),r=this.Pt=new Array(n+1),i=Math.pow(this.$t,n);for(let t=0;t<=n;++t){e[t]=i,r[t]=t*this.$t;for(let r=0;r<=n;++r)r!==t&&(e[t]*=t-r);e[t]=1/e[t]}this.jt=new Array(n+1),this.Ft=new Array(n+1)}ur.Nt=Xe,ur.Ut=or,ur.Tt=function(){tr=void 0},ur.setBaseUrl=function(t){tr=Fe.DEFAULT.getDerivedResource({url:t})},ur.getCesiumBaseUrl=rr;const ar=new Un(0,0,vn.TAI);function fr(t,n,e){const r=ar;return r.dayNumber=n,r.secondsOfDay=e,Un.daysDifference(r,t.qt)}function hr(t,e){if(t.Ot[e])return t.Ot[e];let r;const i=t.xt;r=n(i)?i.getDerivedResource({templateValues:{0:e}}):new Fe({url:ur(`Assets/IAU2006_XYS/IAU2006_XYS_${e}.json`)});const o=r.fetchJson().then((function(n){t.Ot[e]=!1;const r=t.ut,i=n.samples,o=e*t.St*3;for(let t=0,n=i.length;t<n;++t)r[o+t]=i[t]}));return t.Ot[e]=o,o}function lr(t,n,e,r){this.x=o(t,0),this.y=o(n,0),this.z=o(e,0),this.w=o(r,0)}cr.prototype.preload=function(t,n,e,r){const i=fr(this,t,n),o=fr(this,e,r);let u=i/this.$t-this.Et/2|0;u<0&&(u=0);let s=o/this.$t-this.Et/2|0+this.Et;s>=this.It&&(s=this.It-1);const c=u/this.St|0,a=s/this.St|0,f=[];for(let t=c;t<=a;++t)f.push(hr(this,t));return Promise.all(f)},cr.prototype.computeXysRadians=function(t,e,r){const i=fr(this,t,e);if(i<0)return;const o=i/this.$t|0;if(o>=this.It)return;const u=this.Et;let s=o-(u/2|0);s<0&&(s=0);let c=s+u;c>=this.It&&(c=this.It-1,s=c-u,s<0&&(s=0));let a=!1;const f=this.ut;if(n(f[3*s])||(hr(this,s/this.St|0),a=!0),n(f[3*c])||(hr(this,c/this.St|0),a=!0),a)return;n(r)?(r.x=0,r.y=0,r.s=0):r=new sr(0,0,0);const h=i-s*this.$t,l=this.jt,d=this.Rt,w=this.Ft,m=this.Pt;let g,v;for(g=0;g<=u;++g)l[g]=h-m[g];for(g=0;g<=u;++g){for(w[g]=1,v=0;v<=u;++v)v!==g&&(w[g]*=l[v]);w[g]*=d[g];let t=3*(s+g);r.x+=w[g]*f[t++],r.y+=w[g]*f[t++],r.s+=w[g]*f[t]}return r};let dr=new m;lr.fromAxisAngle=function(t,e,i){r.typeOf.object("axis",t),r.typeOf.number("angle",e);const o=e/2,u=Math.sin(o);dr=m.normalize(t,dr);const s=dr.x*u,c=dr.y*u,a=dr.z*u,f=Math.cos(o);return n(i)?(i.x=s,i.y=c,i.z=a,i.w=f,i):new lr(s,c,a,f)};const wr=[1,2,0],mr=new Array(3);lr.fromRotationMatrix=function(t,e){let i,o,u,s,c;r.typeOf.object("matrix",t);const a=t[R.COLUMN0ROW0],f=t[R.COLUMN1ROW1],h=t[R.COLUMN2ROW2],l=a+f+h;if(l>0)i=Math.sqrt(l+1),c=.5*i,i=.5/i,o=(t[R.COLUMN1ROW2]-t[R.COLUMN2ROW1])*i,u=(t[R.COLUMN2ROW0]-t[R.COLUMN0ROW2])*i,s=(t[R.COLUMN0ROW1]-t[R.COLUMN1ROW0])*i;else{const n=wr;let e=0;f>a&&(e=1),h>a&&h>f&&(e=2);const r=n[e],l=n[r];i=Math.sqrt(t[R.getElementIndex(e,e)]-t[R.getElementIndex(r,r)]-t[R.getElementIndex(l,l)]+1);const d=mr;d[e]=.5*i,i=.5/i,c=(t[R.getElementIndex(l,r)]-t[R.getElementIndex(r,l)])*i,d[r]=(t[R.getElementIndex(r,e)]+t[R.getElementIndex(e,r)])*i,d[l]=(t[R.getElementIndex(l,e)]+t[R.getElementIndex(e,l)])*i,o=-d[0],u=-d[1],s=-d[2]}return n(e)?(e.x=o,e.y=u,e.z=s,e.w=c,e):new lr(o,u,s,c)};const gr=new lr;let vr=new lr,pr=new lr,yr=new lr;lr.fromHeadingPitchRoll=function(t,n){return r.typeOf.object("headingPitchRoll",t),yr=lr.fromAxisAngle(m.UNIT_X,t.roll,gr),pr=lr.fromAxisAngle(m.UNIT_Y,-t.pitch,n),n=lr.multiply(pr,yr,pr),vr=lr.fromAxisAngle(m.UNIT_Z,-t.heading,gr),lr.multiply(vr,n,n)};const br=new m,Mr=new m,Ar=new lr,xr=new lr,Er=new lr;lr.packedLength=4,lr.pack=function(t,n,e){return r.typeOf.object("value",t),r.defined("array",n),e=o(e,0),n[e++]=t.x,n[e++]=t.y,n[e++]=t.z,n[e]=t.w,n},lr.unpack=function(t,e,i){return r.defined("array",t),e=o(e,0),n(i)||(i=new lr),i.x=t[e],i.y=t[e+1],i.z=t[e+2],i.w=t[e+3],i},lr.packedInterpolationLength=3,lr.convertPackedArrayForInterpolation=function(t,e,r,i){lr.unpack(t,4*r,Er),lr.conjugate(Er,Er);for(let o=0,u=r-e+1;o<u;o++){const r=3*o;lr.unpack(t,4*(e+o),Ar),lr.multiply(Ar,Er,Ar),Ar.w<0&&lr.negate(Ar,Ar),lr.computeAxis(Ar,br);const u=lr.computeAngle(Ar);n(i)||(i=[]),i[r]=br.x*u,i[r+1]=br.y*u,i[r+2]=br.z*u}},lr.unpackInterpolationResult=function(t,e,r,i,o){n(o)||(o=new lr),m.fromArray(t,0,Mr);const u=m.magnitude(Mr);return lr.unpack(e,4*i,xr),0===u?lr.clone(lr.IDENTITY,Ar):lr.fromAxisAngle(Mr,u,Ar),lr.multiply(Ar,xr,o)},lr.clone=function(t,e){if(n(t))return n(e)?(e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e):new lr(t.x,t.y,t.z,t.w)},lr.conjugate=function(t,n){return r.typeOf.object("quaternion",t),r.typeOf.object("result",n),n.x=-t.x,n.y=-t.y,n.z=-t.z,n.w=t.w,n},lr.magnitudeSquared=function(t){return r.typeOf.object("quaternion",t),t.x*t.x+t.y*t.y+t.z*t.z+t.w*t.w},lr.magnitude=function(t){return Math.sqrt(lr.magnitudeSquared(t))},lr.normalize=function(t,n){r.typeOf.object("result",n);const e=1/lr.magnitude(t),i=t.x*e,o=t.y*e,u=t.z*e,s=t.w*e;return n.x=i,n.y=o,n.z=u,n.w=s,n},lr.inverse=function(t,n){r.typeOf.object("result",n);const e=lr.magnitudeSquared(t);return n=lr.conjugate(t,n),lr.multiplyByScalar(n,1/e,n)},lr.add=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x+n.x,e.y=t.y+n.y,e.z=t.z+n.z,e.w=t.w+n.w,e},lr.subtract=function(t,n,e){return r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e),e.x=t.x-n.x,e.y=t.y-n.y,e.z=t.z-n.z,e.w=t.w-n.w,e},lr.negate=function(t,n){return r.typeOf.object("quaternion",t),r.typeOf.object("result",n),n.x=-t.x,n.y=-t.y,n.z=-t.z,n.w=-t.w,n},lr.dot=function(t,n){return r.typeOf.object("left",t),r.typeOf.object("right",n),t.x*n.x+t.y*n.y+t.z*n.z+t.w*n.w},lr.multiply=function(t,n,e){r.typeOf.object("left",t),r.typeOf.object("right",n),r.typeOf.object("result",e);const i=t.x,o=t.y,u=t.z,s=t.w,c=n.x,a=n.y,f=n.z,h=n.w,l=s*c+i*h+o*f-u*a,d=s*a-i*f+o*h+u*c,w=s*f+i*a-o*c+u*h,m=s*h-i*c-o*a-u*f;return e.x=l,e.y=d,e.z=w,e.w=m,e},lr.multiplyByScalar=function(t,n,e){return r.typeOf.object("quaternion",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x*n,e.y=t.y*n,e.z=t.z*n,e.w=t.w*n,e},lr.divideByScalar=function(t,n,e){return r.typeOf.object("quaternion",t),r.typeOf.number("scalar",n),r.typeOf.object("result",e),e.x=t.x/n,e.y=t.y/n,e.z=t.z/n,e.w=t.w/n,e},lr.computeAxis=function(t,n){r.typeOf.object("quaternion",t),r.typeOf.object("result",n);const e=t.w;if(Math.abs(e-1)<l.EPSILON6||Math.abs(e+1)<l.EPSILON6)return n.x=1,n.y=n.z=0,n;const i=1/Math.sqrt(1-e*e);return n.x=t.x*i,n.y=t.y*i,n.z=t.z*i,n},lr.computeAngle=function(t){return r.typeOf.object("quaternion",t),Math.abs(t.w-1)<l.EPSILON6?0:2*Math.acos(t.w)};let kr=new lr;lr.lerp=function(t,n,e,i){return r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i),kr=lr.multiplyByScalar(n,e,kr),i=lr.multiplyByScalar(t,1-e,i),lr.add(kr,i,i)};let qr=new lr,$r=new lr,Sr=new lr;lr.slerp=function(t,n,e,i){r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i);let o=lr.dot(t,n),u=n;if(o<0&&(o=-o,u=qr=lr.negate(n,qr)),1-o<l.EPSILON6)return lr.lerp(t,u,e,i);const s=Math.acos(o);return $r=lr.multiplyByScalar(t,Math.sin((1-e)*s),$r),Sr=lr.multiplyByScalar(u,Math.sin(e*s),Sr),i=lr.add($r,Sr,i),lr.multiplyByScalar(i,1/Math.sin(s),i)},lr.log=function(t,n){r.typeOf.object("quaternion",t),r.typeOf.object("result",n);const e=l.acosClamped(t.w);let i=0;return 0!==e&&(i=e/Math.sin(e)),m.multiplyByScalar(t,i,n)},lr.exp=function(t,n){r.typeOf.object("cartesian",t),r.typeOf.object("result",n);const e=m.magnitude(t);let i=0;return 0!==e&&(i=Math.sin(e)/e),n.x=t.x*i,n.y=t.y*i,n.z=t.z*i,n.w=Math.cos(e),n};const Ir=new m,Or=new m,Rr=new lr,Pr=new lr;lr.computeInnerQuadrangle=function(t,n,e,i){r.typeOf.object("q0",t),r.typeOf.object("q1",n),r.typeOf.object("q2",e),r.typeOf.object("result",i);const o=lr.conjugate(n,Rr);lr.multiply(o,e,Pr);const u=lr.log(Pr,Ir);lr.multiply(o,t,Pr);const s=lr.log(Pr,Or);return m.add(u,s,u),m.multiplyByScalar(u,.25,u),m.negate(u,u),lr.exp(u,Rr),lr.multiply(n,Rr,i)},lr.squad=function(t,n,e,i,o,u){r.typeOf.object("q0",t),r.typeOf.object("q1",n),r.typeOf.object("s0",e),r.typeOf.object("s1",i),r.typeOf.number("t",o),r.typeOf.object("result",u);const s=lr.slerp(t,n,o,Rr),c=lr.slerp(e,i,o,Pr);return lr.slerp(s,c,2*o*(1-o),u)};const jr=new lr,Fr=1.9011074535173003,Nr=zt.supportsTypedArrays()?new Float32Array(8):[],Ur=zt.supportsTypedArrays()?new Float32Array(8):[],Tr=zt.supportsTypedArrays()?new Float32Array(8):[],zr=zt.supportsTypedArrays()?new Float32Array(8):[];for(let t=0;t<7;++t){const n=t+1,e=2*n+1;Nr[t]=1/(n*e),Ur[t]=n/e}Nr[7]=Fr/136,Ur[7]=8*Fr/17,lr.fastSlerp=function(t,n,e,i){r.typeOf.object("start",t),r.typeOf.object("end",n),r.typeOf.number("t",e),r.typeOf.object("result",i);let o,u=lr.dot(t,n);u>=0?o=1:(o=-1,u=-u);const s=u-1,c=1-e,a=e*e,f=c*c;for(let t=7;t>=0;--t)Tr[t]=(Nr[t]*a-Ur[t])*s,zr[t]=(Nr[t]*f-Ur[t])*s;const h=o*e*(1+Tr[0]*(1+Tr[1]*(1+Tr[2]*(1+Tr[3]*(1+Tr[4]*(1+Tr[5]*(1+Tr[6]*(1+Tr[7])))))))),l=c*(1+zr[0]*(1+zr[1]*(1+zr[2]*(1+zr[3]*(1+zr[4]*(1+zr[5]*(1+zr[6]*(1+zr[7])))))))),d=lr.multiplyByScalar(t,l,jr);return lr.multiplyByScalar(n,h,i),lr.add(d,i,i)},lr.fastSquad=function(t,n,e,i,o,u){r.typeOf.object("q0",t),r.typeOf.object("q1",n),r.typeOf.object("s0",e),r.typeOf.object("s1",i),r.typeOf.number("t",o),r.typeOf.object("result",u);const s=lr.fastSlerp(t,n,o,Rr),c=lr.fastSlerp(e,i,o,Pr);return lr.fastSlerp(s,c,2*o*(1-o),u)},lr.equals=function(t,e){return t===e||n(t)&&n(e)&&t.x===e.x&&t.y===e.y&&t.z===e.z&&t.w===e.w},lr.equalsEpsilon=function(t,e,r){return r=o(r,0),t===e||n(t)&&n(e)&&Math.abs(t.x-e.x)<=r&&Math.abs(t.y-e.y)<=r&&Math.abs(t.z-e.z)<=r&&Math.abs(t.w-e.w)<=r},lr.ZERO=Object.freeze(new lr(0,0,0,0)),lr.IDENTITY=Object.freeze(new lr(0,0,0,1)),lr.prototype.clone=function(t){return lr.clone(this,t)},lr.prototype.equals=function(t){return lr.equals(this,t)},lr.prototype.equalsEpsilon=function(t,n){return lr.equalsEpsilon(this,t,n)},lr.prototype.toString=function(){return`(${this.x}, ${this.y}, ${this.z}, ${this.w})`};const Cr={},Dr={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Br={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Lr={},_r={east:new m,north:new m,up:new m,west:new m,south:new m,down:new m};let Vr=new m,Hr=new m,Yr=new m;Cr.localFrameToFixedFrameGenerator=function(t,r){if(!Dr.hasOwnProperty(t)||!Dr[t].hasOwnProperty(r))throw new e("firstAxis and secondAxis must be east, north, up, west, south or down.");const i=Dr[t][r];let u;const s=t+r;return n(Lr[s])?u=Lr[s]:(u=function(u,s,c){if(!n(u))throw new e("origin is required.");if(isNaN(u.x)||isNaN(u.y)||isNaN(u.z))throw new e("origin has a NaN component");if(n(c)||(c=new Y),m.equalsEpsilon(u,m.ZERO,l.EPSILON14))m.unpack(Br[t],0,Vr),m.unpack(Br[r],0,Hr),m.unpack(Br[i],0,Yr);else if(l.equalsEpsilon(u.x,0,l.EPSILON14)&&l.equalsEpsilon(u.y,0,l.EPSILON14)){const n=l.sign(u.z);m.unpack(Br[t],0,Vr),"east"!==t&&"west"!==t&&m.multiplyByScalar(Vr,n,Vr),m.unpack(Br[r],0,Hr),"east"!==r&&"west"!==r&&m.multiplyByScalar(Hr,n,Hr),m.unpack(Br[i],0,Yr),"east"!==i&&"west"!==i&&m.multiplyByScalar(Yr,n,Yr)}else{(s=o(s,Kt.default)).geodeticSurfaceNormal(u,_r.up);const n=_r.up,e=_r.east;e.x=-u.y,e.y=u.x,e.z=0,m.normalize(e,_r.east),m.cross(n,e,_r.north),m.multiplyByScalar(_r.up,-1,_r.down),m.multiplyByScalar(_r.east,-1,_r.west),m.multiplyByScalar(_r.north,-1,_r.south),Vr=_r[t],Hr=_r[r],Yr=_r[i]}return c[0]=Vr.x,c[1]=Vr.y,c[2]=Vr.z,c[3]=0,c[4]=Hr.x,c[5]=Hr.y,c[6]=Hr.z,c[7]=0,c[8]=Yr.x,c[9]=Yr.y,c[10]=Yr.z,c[11]=0,c[12]=u.x,c[13]=u.y,c[14]=u.z,c[15]=1,c},Lr[s]=u),u},Cr.eastNorthUpToFixedFrame=Cr.localFrameToFixedFrameGenerator("east","north"),Cr.northEastDownToFixedFrame=Cr.localFrameToFixedFrameGenerator("north","east"),Cr.northUpEastToFixedFrame=Cr.localFrameToFixedFrameGenerator("north","up"),Cr.northWestUpToFixedFrame=Cr.localFrameToFixedFrameGenerator("north","west");const Zr=new lr,Wr=new m(1,1,1),Qr=new Y;Cr.headingPitchRollToFixedFrame=function(t,n,e,i,u){r.typeOf.object("HeadingPitchRoll",n),i=o(i,Cr.eastNorthUpToFixedFrame);const s=lr.fromHeadingPitchRoll(n,Zr),c=Y.fromTranslationQuaternionRotationScale(m.ZERO,s,Wr,Qr);return u=i(t,e,u),Y.multiply(u,c,u)};const Jr=new Y,Gr=new R;Cr.headingPitchRollQuaternion=function(t,n,e,i,o){r.typeOf.object("HeadingPitchRoll",n);const u=Cr.headingPitchRollToFixedFrame(t,n,e,i,Jr),s=Y.getMatrix3(u,Gr);return lr.fromRotationMatrix(s,o)};const Xr=new m(1,1,1),Kr=new m,ti=new Y,ni=new Y,ei=new R,ri=new lr;Cr.fixedFrameToHeadingPitchRoll=function(t,e,i,u){r.defined("transform",t),e=o(e,Kt.default),i=o(i,Cr.eastNorthUpToFixedFrame),n(u)||(u=new Ge);const s=Y.getTranslation(t,Kr);if(m.equals(s,m.ZERO))return u.heading=0,u.pitch=0,u.roll=0,u;let c=Y.inverseTransformation(i(s,e,ti),ti),a=Y.setScale(t,Xr,ni);a=Y.setTranslation(a,m.ZERO,a),c=Y.multiply(c,a,c);let f=lr.fromRotationMatrix(Y.getMatrix3(c,ei),ri);return f=lr.normalize(f,f),Ge.fromQuaternion(f,u)};const ii=l.TWO_PI/86400;let oi=new Un;Cr.computeIcrfToCentralBodyFixedMatrix=function(t,e){let r=Cr.computeIcrfToFixedMatrix(t,e);return n(r)||(r=Cr.computeTemeToPseudoFixedMatrix(t,e)),r},Cr.computeTemeToPseudoFixedMatrix=function(t,r){if(!n(t))throw new e("date is required.");oi=Un.addSeconds(t,-Un.computeTaiMinusUtc(t),oi);const i=oi.dayNumber,o=oi.secondsOfDay;let u;const s=i-2451545;u=o>=43200?(s+.5)/gn.DAYS_PER_JULIAN_CENTURY:(s-.5)/gn.DAYS_PER_JULIAN_CENTURY;const c=(24110.54841+u*(8640184.812866+u*(.093104+-62e-7*u)))*ii%l.TWO_PI+(72921158553e-15+11772758384668e-32*(i-2451545.5))*((o+.5*gn.SECONDS_PER_DAY)%gn.SECONDS_PER_DAY),a=Math.cos(c),f=Math.sin(c);return n(r)?(r[0]=a,r[1]=-f,r[2]=0,r[3]=f,r[4]=a,r[5]=0,r[6]=0,r[7]=0,r[8]=1,r):new R(a,f,0,-f,a,0,0,0,1)},Cr.iau2006XysData=new cr,Cr.earthOrientationParameters=He.NONE;const ui=32.184;Cr.preloadIcrfFixed=function(t){const n=t.start.dayNumber,e=t.start.secondsOfDay+ui,r=t.stop.dayNumber,i=t.stop.secondsOfDay+ui;return Cr.iau2006XysData.preload(n,e,r,i)},Cr.computeIcrfToFixedMatrix=function(t,r){if(!n(t))throw new e("date is required.");n(r)||(r=new R);const i=Cr.computeFixedToIcrfMatrix(t,r);if(n(i))return R.transpose(i,r)};const si=new Ge,ci=new R,ai=new Un;Cr.computeMoonFixedToIcrfMatrix=function(t,r){if(!n(t))throw new e("date is required.");const i=Un.addSeconds(t,32.184,ai),o=Un.totalDays(i)-2451545,u=l.toRadians(12.112)-l.toRadians(.052992)*o,s=l.toRadians(24.224)-l.toRadians(.105984)*o,c=l.toRadians(227.645)+l.toRadians(13.012)*o,a=l.toRadians(261.105)+l.toRadians(13.340716)*o,f=l.toRadians(358)+l.toRadians(.9856)*o;return si.pitch=l.toRadians(180)-l.toRadians(3.878)*Math.sin(u)-l.toRadians(.12)*Math.sin(s)+l.toRadians(.07)*Math.sin(c)-l.toRadians(.017)*Math.sin(a),si.roll=l.toRadians(-23.47)+l.toRadians(1.543)*Math.cos(u)+l.toRadians(.24)*Math.cos(s)-l.toRadians(.028)*Math.cos(c)+l.toRadians(.007)*Math.cos(a),si.heading=l.toRadians(154.375)+l.toRadians(13.17635831)*o+l.toRadians(3.558)*Math.sin(u)+l.toRadians(.121)*Math.sin(s)-l.toRadians(.064)*Math.sin(c)+l.toRadians(.016)*Math.sin(a)+l.toRadians(.025)*Math.sin(f),R.fromHeadingPitchRoll(si,ci)},Cr.computeIcrfToMoonFixedMatrix=function(t,r){if(!n(t))throw new e("date is required.");n(r)||(r=new R);const i=Cr.computeMoonFixedToIcrfMatrix(t,r);if(n(i))return R.transpose(i,r)};const fi=new sr(0,0,0),hi=new hn(0,0,0,0,0),li=new R,di=new R;Cr.computeFixedToIcrfMatrix=function(t,r){if(!n(t))throw new e("date is required.");n(r)||(r=new R);const i=Cr.earthOrientationParameters.compute(t,hi);if(!n(i))return;const o=t.dayNumber,u=t.secondsOfDay+ui,s=Cr.iau2006XysData.computeXysRadians(o,u,fi);if(!n(s))return;const c=s.x+i.xPoleOffset,a=s.y+i.yPoleOffset,f=1/(1+Math.sqrt(1-c*c-a*a)),h=li;h[0]=1-f*c*c,h[3]=-f*c*a,h[6]=c,h[1]=-f*c*a,h[4]=1-f*a*a,h[7]=a,h[2]=-c,h[5]=-a,h[8]=1-f*(c*c+a*a);const d=R.fromRotationZ(-s.s,di),w=R.multiply(h,d,li),m=t.dayNumber-2451545,g=(t.secondsOfDay-Un.computeTaiMinusUtc(t)+i.ut1MinusUtc)/gn.SECONDS_PER_DAY;let v=.779057273264+g+.00273781191135448*(m+g);v=v%1*l.TWO_PI;const p=R.fromRotationZ(v,di),y=R.multiply(w,p,li),b=Math.cos(i.xPoleWander),M=Math.cos(i.yPoleWander),A=Math.sin(i.xPoleWander),x=Math.sin(i.yPoleWander);let E=o-2451545+u/gn.SECONDS_PER_DAY;E/=36525;const k=-47e-6*E*l.RADIANS_PER_DEGREE/3600,q=Math.cos(k),$=Math.sin(k),S=di;return S[0]=b*q,S[1]=b*$,S[2]=A,S[3]=-M*$+x*A*q,S[4]=M*q+x*A*$,S[5]=-x*b,S[6]=-x*$-M*A*q,S[7]=x*q-M*A*$,S[8]=M*b,R.multiply(y,S,r)};const wi=new x;Cr.pointToWindowCoordinates=function(t,n,e,r){return(r=Cr.pointToGLWindowCoordinates(t,n,e,r)).y=2*n[5]-r.y,r},Cr.pointToGLWindowCoordinates=function(t,r,i,o){if(!n(t))throw new e("modelViewProjectionMatrix is required.");if(!n(r))throw new e("viewportTransformation is required.");if(!n(i))throw new e("point is required.");n(o)||(o=new Ct);const u=wi;return Y.multiplyByVector(t,x.fromElements(i.x,i.y,i.z,1,u),u),x.multiplyByScalar(u,1/u.w,u),Y.multiplyByVector(r,u,u),Ct.fromCartesian4(u,o)};const mi=new m,gi=new m,vi=new m;Cr.rotationMatrixFromPositionVelocity=function(t,r,i,u){if(!n(t))throw new e("position is required.");if(!n(r))throw new e("velocity is required.");const s=o(i,Kt.default).geodeticSurfaceNormal(t,mi);let c=m.cross(r,s,gi);m.equalsEpsilon(c,m.ZERO,l.EPSILON6)&&(c=m.clone(m.UNIT_X,c));const a=m.cross(c,r,vi);return m.normalize(a,a),m.cross(r,a,c),m.negate(c,c),m.normalize(c,c),n(u)||(u=new R),u[0]=r.x,u[1]=r.y,u[2]=r.z,u[3]=c.x,u[4]=c.y,u[5]=c.z,u[6]=a.x,u[7]=a.y,u[8]=a.z,u};const pi=new Y(0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,1),yi=new Wt,bi=new m,Mi=new m,Ai=new R,xi=new Y,Ei=new Y;function ki(t,n,e=2){const r=t.length;let i=function(t,n,e,r){let i;if(1==function(t,n,e,r){let i=0;for(let n=0,o=e-r;n<e;n+=r)i+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return i}(t,0,e,r)>0)for(let n=0;n<e;n+=r)i=Li(n/r|0,t[n],t[n+1],i);else for(let n=e-r;n>=0;n-=r)i=Li(n/r|0,t[n],t[n+1],i);return i&&Ui(i,i.next)&&(_i(i),i=i.next),i}(t,0,r,e);const o=[];if(!i||i.next===i.prev)return o;let u,s,c;if(t.length>80*e){u=1/0,s=1/0;let n=-1/0,i=-1/0;for(let o=e;o<r;o+=e){const e=t[o],r=t[o+1];e<u&&(u=e),r<s&&(s=r),e>n&&(n=e),r>i&&(i=r)}c=Math.max(n-u,i-s),c=0!==c?32767/c:0}return $i(i,o,e,u,s,c,0),o}function qi(t,n){if(!t)return t;n||(n=t);let e,r=t;do{if(e=!1,r.steiner||!Ui(r,r.next)&&0!==Ni(r.prev,r,r.next))r=r.next;else{if(_i(r),r=n=r.prev,r===r.next)break;e=!0}}while(e||r!==n);return n}function $i(t,n,e,r,i,o,u){if(!t)return;!u&&o&&function(t,n,e,r){let i=t;do{0===i.z&&(i.z=Pi(i.x,i.y,n,e,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next}while(i!==t);i.prevZ.nextZ=null,i.prevZ=null,function(t){let n,e=1;do{let r,i=t;t=null;let o=null;for(n=0;i;){n++;let u=i,s=0;for(let t=0;t<e&&(s++,u=u.nextZ,u);t++);let c=e;for(;s>0||c>0&&u;)0!==s&&(0===c||!u||i.z<=u.z)?(r=i,i=i.nextZ,s--):(r=u,u=u.nextZ,c--),o?o.nextZ=r:t=r,r.prevZ=o,o=r;i=u}o.nextZ=null,e*=2}while(n>1)}(i)}(t,r,i,o);let s=t;for(;t.prev!==t.next;){const c=t.prev,a=t.next;if(o?Ii(t,r,i,o):Si(t))n.push(c.i,t.i,a.i),_i(t),t=a.next,s=a.next;else if((t=a)===s){u?1===u?$i(t=Oi(qi(t),n),n,e,r,i,o,2):2===u&&Ri(t,n,e,r,i,o):$i(qi(t),n,e,r,i,o,1);break}}}function Si(t){const n=t.prev,e=t,r=t.next;if(Ni(n,e,r)>=0)return!1;const i=n.x,o=e.x,u=r.x,s=n.y,c=e.y,a=r.y,f=Math.min(i,o,u),h=Math.min(s,c,a),l=Math.max(i,o,u),d=Math.max(s,c,a);let w=r.next;for(;w!==n;){if(w.x>=f&&w.x<=l&&w.y>=h&&w.y<=d&&ji(i,s,o,c,u,a,w.x,w.y)&&Ni(w.prev,w,w.next)>=0)return!1;w=w.next}return!0}function Ii(t,n,e,r){const i=t.prev,o=t,u=t.next;if(Ni(i,o,u)>=0)return!1;const s=i.x,c=o.x,a=u.x,f=i.y,h=o.y,l=u.y,d=Math.min(s,c,a),w=Math.min(f,h,l),m=Math.max(s,c,a),g=Math.max(f,h,l),v=Pi(d,w,n,e,r),p=Pi(m,g,n,e,r);let y=t.prevZ,b=t.nextZ;for(;y&&y.z>=v&&b&&b.z<=p;){if(y.x>=d&&y.x<=m&&y.y>=w&&y.y<=g&&y!==i&&y!==u&&ji(s,f,c,h,a,l,y.x,y.y)&&Ni(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,b.x>=d&&b.x<=m&&b.y>=w&&b.y<=g&&b!==i&&b!==u&&ji(s,f,c,h,a,l,b.x,b.y)&&Ni(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;y&&y.z>=v;){if(y.x>=d&&y.x<=m&&y.y>=w&&y.y<=g&&y!==i&&y!==u&&ji(s,f,c,h,a,l,y.x,y.y)&&Ni(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=p;){if(b.x>=d&&b.x<=m&&b.y>=w&&b.y<=g&&b!==i&&b!==u&&ji(s,f,c,h,a,l,b.x,b.y)&&Ni(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Oi(t,n){let e=t;do{const r=e.prev,i=e.next.next;!Ui(r,i)&&Ti(r,e,e.next,i)&&Di(r,i)&&Di(i,r)&&(n.push(r.i,e.i,i.i),_i(e),_i(e.next),e=t=i),e=e.next}while(e!==t);return qi(e)}function Ri(t,n,e,r,i,o){let u=t;do{let t=u.next.next;for(;t!==u.prev;){if(u.i!==t.i&&Fi(u,t)){let s=Bi(u,t);return u=qi(u,u.next),s=qi(s,s.next),$i(u,n,e,r,i,o,0),void $i(s,n,e,r,i,o,0)}t=t.next}u=u.next}while(u!==t)}function Pi(t,n,e,r,i){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-e)*i|0)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=(n-r)*i|0)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function ji(t,n,e,r,i,o,u,s){return!(t===u&&n===s)&&function(t,n,e,r,i,o,u,s){return(i-u)*(n-s)>=(t-u)*(o-s)&&(t-u)*(r-s)>=(e-u)*(n-s)&&(e-u)*(o-s)>=(i-u)*(r-s)}(t,n,e,r,i,o,u,s)}function Fi(t,n){return t.next.i!==n.i&&t.prev.i!==n.i&&!function(t,n){let e=t;do{if(e.i!==t.i&&e.next.i!==t.i&&e.i!==n.i&&e.next.i!==n.i&&Ti(e,e.next,t,n))return!0;e=e.next}while(e!==t);return!1}(t,n)&&(Di(t,n)&&Di(n,t)&&function(t,n){let e=t,r=!1;const i=(t.x+n.x)/2,o=(t.y+n.y)/2;do{e.y>o!=e.next.y>o&&e.next.y!==e.y&&i<(e.next.x-e.x)*(o-e.y)/(e.next.y-e.y)+e.x&&(r=!r),e=e.next}while(e!==t);return r}(t,n)&&(Ni(t.prev,t,n.prev)||Ni(t,n.prev,n))||Ui(t,n)&&Ni(t.prev,t,t.next)>0&&Ni(n.prev,n,n.next)>0)}function Ni(t,n,e){return(n.y-t.y)*(e.x-n.x)-(n.x-t.x)*(e.y-n.y)}function Ui(t,n){return t.x===n.x&&t.y===n.y}function Ti(t,n,e,r){const i=Ci(Ni(t,n,e)),o=Ci(Ni(t,n,r)),u=Ci(Ni(e,r,t)),s=Ci(Ni(e,r,n));return i!==o&&u!==s||!(0!==i||!zi(t,e,n))||!(0!==o||!zi(t,r,n))||!(0!==u||!zi(e,t,r))||!(0!==s||!zi(e,n,r))}function zi(t,n,e){return n.x<=Math.max(t.x,e.x)&&n.x>=Math.min(t.x,e.x)&&n.y<=Math.max(t.y,e.y)&&n.y>=Math.min(t.y,e.y)}function Ci(t){return t>0?1:t<0?-1:0}function Di(t,n){return Ni(t.prev,t,t.next)<0?Ni(t,n,t.next)>=0&&Ni(t,t.prev,n)>=0:Ni(t,n,t.prev)<0||Ni(t,t.next,n)<0}function Bi(t,n){const e=Vi(t.i,t.x,t.y),r=Vi(n.i,n.x,n.y),i=t.next,o=n.prev;return t.next=n,n.prev=t,e.next=i,i.prev=e,r.next=e,e.prev=r,o.next=r,r.prev=o,r}function Li(t,n,e,r){const i=Vi(t,n,e);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function _i(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Vi(t,n,e){return{i:t,x:n,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}Cr.basisTo2D=function(t,r,i){if(!n(t))throw new e("projection is required.");if(!n(r))throw new e("matrix is required.");if(!n(i))throw new e("result is required.");const o=Y.getTranslation(r,Mi),u=t.ellipsoid;let s;if(m.equals(o,m.ZERO))s=m.clone(m.ZERO,bi);else{const n=u.cartesianToCartographic(o,yi);s=t.project(n,bi),m.fromElements(s.z,s.x,s.y,s)}const c=Cr.eastNorthUpToFixedFrame(o,u,xi),a=Y.inverseTransformation(c,Ei),f=Y.getMatrix3(r,Ai),h=Y.multiplyByMatrix3(a,f,i);return Y.multiply(pi,h,i),Y.setTranslation(i,s,i),i},Cr.ellipsoidTo2DModelMatrix=function(t,r,i){if(!n(t))throw new e("projection is required.");if(!n(r))throw new e("center is required.");if(!n(i))throw new e("result is required.");const o=t.ellipsoid,u=Cr.eastNorthUpToFixedFrame(r,o,xi),s=Y.inverseTransformation(u,Ei),c=o.cartesianToCartographic(r,yi),a=t.project(c,bi);m.fromElements(a.z,a.x,a.y,a);const f=Y.fromTranslation(a,xi);return Y.multiply(pi,s,i),Y.multiply(f,i,i),i};var Hi,Yi,Zi,Wi,Qi,Ji,Gi={},Xi=function(){if(Zi)return Yi;Zi=1,Yi=n;var t=(Hi||(Hi=1,Gi.read=function(t,n,e,r,i){var o,u,s=8*i-r-1,c=(1<<s)-1,a=c>>1,f=-7,h=e?i-1:0,l=e?-1:1,d=t[n+h];for(h+=l,o=d&(1<<-f)-1,d>>=-f,f+=s;f>0;o=256*o+t[n+h],h+=l,f-=8);for(u=o&(1<<-f)-1,o>>=-f,f+=r;f>0;u=256*u+t[n+h],h+=l,f-=8);if(0===o)o=1-a;else{if(o===c)return u?NaN:1/0*(d?-1:1);u+=Math.pow(2,r),o-=a}return(d?-1:1)*u*Math.pow(2,o-r)},Gi.write=function(t,n,e,r,i,o){var u,s,c,a=8*o-i-1,f=(1<<a)-1,h=f>>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,w=r?1:-1,m=n<0||0===n&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(s=isNaN(n)?1:0,u=f):(u=Math.floor(Math.log(n)/Math.LN2),n*(c=Math.pow(2,-u))<1&&(u--,c*=2),(n+=u+h>=1?l/c:l*Math.pow(2,1-h))*c>=2&&(u++,c/=2),u+h>=f?(s=0,u=f):u+h>=1?(s=(n*c-1)*Math.pow(2,i),u+=h):(s=n*Math.pow(2,h-1)*Math.pow(2,i),u=0));i>=8;t[e+d]=255&s,d+=w,s/=256,i-=8);for(u=u<<i|s,a+=i;a>0;t[e+d]=255&u,d+=w,u/=256,a-=8);t[e+d-w]|=128*m}),Gi);function n(t){this.buf=ArrayBuffer.isView&&ArrayBuffer.isView(t)?t:new Uint8Array(t||0),this.pos=0,this.type=0,this.length=this.buf.length}n.Varint=0,n.Fixed64=1,n.Bytes=2,n.Fixed32=5;var e=4294967296,r=1/e,i="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function o(t){return t.type===n.Bytes?t.readVarint()+t.pos:t.pos+1}function u(t,n,e){return e?4294967296*n+(t>>>0):4294967296*(n>>>0)+(t>>>0)}function s(t,n,e){var r=n<=16383?1:n<=2097151?2:n<=268435455?3:Math.floor(Math.log(n)/(7*Math.LN2));e.realloc(r);for(var i=e.pos-1;i>=t;i--)e.buf[i+r]=e.buf[i]}function c(t,n){for(var e=0;e<t.length;e++)n.writeVarint(t[e])}function a(t,n){for(var e=0;e<t.length;e++)n.writeSVarint(t[e])}function f(t,n){for(var e=0;e<t.length;e++)n.writeFloat(t[e])}function h(t,n){for(var e=0;e<t.length;e++)n.writeDouble(t[e])}function l(t,n){for(var e=0;e<t.length;e++)n.writeBoolean(t[e])}function d(t,n){for(var e=0;e<t.length;e++)n.writeFixed32(t[e])}function w(t,n){for(var e=0;e<t.length;e++)n.writeSFixed32(t[e])}function m(t,n){for(var e=0;e<t.length;e++)n.writeFixed64(t[e])}function g(t,n){for(var e=0;e<t.length;e++)n.writeSFixed64(t[e])}function v(t,n){return(t[n]|t[n+1]<<8|t[n+2]<<16)+16777216*t[n+3]}function p(t,n,e){t[e]=n,t[e+1]=n>>>8,t[e+2]=n>>>16,t[e+3]=n>>>24}function y(t,n){return(t[n]|t[n+1]<<8|t[n+2]<<16)+(t[n+3]<<24)}return n.prototype={destroy:function(){this.buf=null},readFields:function(t,n,e){for(e=e||this.length;this.pos<e;){var r=this.readVarint(),i=r>>3,o=this.pos;this.type=7&r,t(i,n,this),this.pos===o&&this.skip(r)}return n},readMessage:function(t,n){return this.readFields(t,n,this.readVarint()+this.pos)},readFixed32:function(){var t=v(this.buf,this.pos);return this.pos+=4,t},readSFixed32:function(){var t=y(this.buf,this.pos);return this.pos+=4,t},readFixed64:function(){var t=v(this.buf,this.pos)+v(this.buf,this.pos+4)*e;return this.pos+=8,t},readSFixed64:function(){var t=v(this.buf,this.pos)+y(this.buf,this.pos+4)*e;return this.pos+=8,t},readFloat:function(){var n=t.read(this.buf,this.pos,!0,23,4);return this.pos+=4,n},readDouble:function(){var n=t.read(this.buf,this.pos,!0,52,8);return this.pos+=8,n},readVarint:function(t){var n,e,r=this.buf;return n=127&(e=r[this.pos++]),e<128?n:(n|=(127&(e=r[this.pos++]))<<7,e<128?n:(n|=(127&(e=r[this.pos++]))<<14,e<128?n:(n|=(127&(e=r[this.pos++]))<<21,e<128?n:function(t,n,e){var r,i,o=e.buf;if(r=(112&(i=o[e.pos++]))>>4,i<128)return u(t,r,n);if(r|=(127&(i=o[e.pos++]))<<3,i<128)return u(t,r,n);if(r|=(127&(i=o[e.pos++]))<<10,i<128)return u(t,r,n);if(r|=(127&(i=o[e.pos++]))<<17,i<128)return u(t,r,n);if(r|=(127&(i=o[e.pos++]))<<24,i<128)return u(t,r,n);if(r|=(1&(i=o[e.pos++]))<<31,i<128)return u(t,r,n);throw new Error("Expected varint not more than 10 bytes")}(n|=(15&(e=r[this.pos]))<<28,t,this))))},readVarint64:function(){return this.readVarint(!0)},readSVarint:function(){var t=this.readVarint();return t%2==1?(t+1)/-2:t/2},readBoolean:function(){return Boolean(this.readVarint())},readString:function(){var t=this.readVarint()+this.pos,n=this.pos;return this.pos=t,t-n>=12&&i?function(t,n,e){return i.decode(t.subarray(n,e))}(this.buf,n,t):function(t,n,e){for(var r="",i=n;i<e;){var o,u,s,c=t[i],a=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f>e)break;1===f?c<128&&(a=c):2===f?128==(192&(o=t[i+1]))&&(a=(31&c)<<6|63&o)<=127&&(a=null):3===f?(o=t[i+1],u=t[i+2],128==(192&o)&&128==(192&u)&&((a=(15&c)<<12|(63&o)<<6|63&u)<=2047||a>=55296&&a<=57343)&&(a=null)):4===f&&(o=t[i+1],u=t[i+2],s=t[i+3],128==(192&o)&&128==(192&u)&&128==(192&s)&&((a=(15&c)<<18|(63&o)<<12|(63&u)<<6|63&s)<=65535||a>=1114112)&&(a=null)),null===a?(a=65533,f=1):a>65535&&(a-=65536,r+=String.fromCharCode(a>>>10&1023|55296),a=56320|1023&a),r+=String.fromCharCode(a),i+=f}return r}(this.buf,n,t)},readBytes:function(){var t=this.readVarint()+this.pos,n=this.buf.subarray(this.pos,t);return this.pos=t,n},readPackedVarint:function(t,e){if(this.type!==n.Bytes)return t.push(this.readVarint(e));var r=o(this);for(t=t||[];this.pos<r;)t.push(this.readVarint(e));return t},readPackedSVarint:function(t){if(this.type!==n.Bytes)return t.push(this.readSVarint());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readSVarint());return t},readPackedBoolean:function(t){if(this.type!==n.Bytes)return t.push(this.readBoolean());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readBoolean());return t},readPackedFloat:function(t){if(this.type!==n.Bytes)return t.push(this.readFloat());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readFloat());return t},readPackedDouble:function(t){if(this.type!==n.Bytes)return t.push(this.readDouble());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readDouble());return t},readPackedFixed32:function(t){if(this.type!==n.Bytes)return t.push(this.readFixed32());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readFixed32());return t},readPackedSFixed32:function(t){if(this.type!==n.Bytes)return t.push(this.readSFixed32());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed32());return t},readPackedFixed64:function(t){if(this.type!==n.Bytes)return t.push(this.readFixed64());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readFixed64());return t},readPackedSFixed64:function(t){if(this.type!==n.Bytes)return t.push(this.readSFixed64());var e=o(this);for(t=t||[];this.pos<e;)t.push(this.readSFixed64());return t},skip:function(t){var e=7&t;if(e===n.Varint)for(;this.buf[this.pos++]>127;);else if(e===n.Bytes)this.pos=this.readVarint()+this.pos;else if(e===n.Fixed32)this.pos+=4;else{if(e!==n.Fixed64)throw new Error("Unimplemented type: "+e);this.pos+=8}},writeTag:function(t,n){this.writeVarint(t<<3|n)},realloc:function(t){for(var n=this.length||16;n<this.pos+t;)n*=2;if(n!==this.length){var e=new Uint8Array(n);e.set(this.buf),this.buf=e,this.length=n}},finish:function(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)},writeFixed32:function(t){this.realloc(4),p(this.buf,t,this.pos),this.pos+=4},writeSFixed32:function(t){this.realloc(4),p(this.buf,t,this.pos),this.pos+=4},writeFixed64:function(t){this.realloc(8),p(this.buf,-1&t,this.pos),p(this.buf,Math.floor(t*r),this.pos+4),this.pos+=8},writeSFixed64:function(t){this.realloc(8),p(this.buf,-1&t,this.pos),p(this.buf,Math.floor(t*r),this.pos+4),this.pos+=8},writeVarint:function(t){(t=+t||0)>268435455||t<0?function(t,n){var e,r;if(t>=0?(e=t%4294967296|0,r=t/4294967296|0):(r=~(-t/4294967296),4294967295^(e=~(-t%4294967296))?e=e+1|0:(e=0,r=r+1|0)),t>=0x10000000000000000||t<-0x10000000000000000)throw new Error("Given varint doesn\'t fit into 10 bytes");n.realloc(10),function(t,n,e){e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos++]=127&t|128,t>>>=7,e.buf[e.pos]=127&t}(e,0,n),function(t,n){var e=(7&t)<<4;n.buf[n.pos++]|=e|((t>>>=3)?128:0),t&&(n.buf[n.pos++]=127&t|((t>>>=7)?128:0),t&&(n.buf[n.pos++]=127&t|((t>>>=7)?128:0),t&&(n.buf[n.pos++]=127&t|((t>>>=7)?128:0),t&&(n.buf[n.pos++]=127&t|((t>>>=7)?128:0),t&&(n.buf[n.pos++]=127&t)))))}(r,n)}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))))},writeSVarint:function(t){this.writeVarint(t<0?2*-t-1:2*t)},writeBoolean:function(t){this.writeVarint(Boolean(t))},writeString:function(t){t=String(t),this.realloc(4*t.length),this.pos++;var n=this.pos;this.pos=function(t,n,e){for(var r,i,o=0;o<n.length;o++){if((r=n.charCodeAt(o))>55295&&r<57344){if(!i){r>56319||o+1===n.length?(t[e++]=239,t[e++]=191,t[e++]=189):i=r;continue}if(r<56320){t[e++]=239,t[e++]=191,t[e++]=189,i=r;continue}r=i-55296<<10|r-56320|65536,i=null}else i&&(t[e++]=239,t[e++]=191,t[e++]=189,i=null);r<128?t[e++]=r:(r<2048?t[e++]=r>>6|192:(r<65536?t[e++]=r>>12|224:(t[e++]=r>>18|240,t[e++]=r>>12&63|128),t[e++]=r>>6&63|128),t[e++]=63&r|128)}return e}(this.buf,t,this.pos);var e=this.pos-n;e>=128&&s(n,e,this),this.pos=n-1,this.writeVarint(e),this.pos+=e},writeFloat:function(n){this.realloc(4),t.write(this.buf,n,this.pos,!0,23,4),this.pos+=4},writeDouble:function(n){this.realloc(8),t.write(this.buf,n,this.pos,!0,52,8),this.pos+=8},writeBytes:function(t){var n=t.length;this.writeVarint(n),this.realloc(n);for(var e=0;e<n;e++)this.buf[this.pos++]=t[e]},writeRawMessage:function(t,n){this.pos++;var e=this.pos;t(n,this);var r=this.pos-e;r>=128&&s(e,r,this),this.pos=e-1,this.writeVarint(r),this.pos+=r},writeMessage:function(t,e,r){this.writeTag(t,n.Bytes),this.writeRawMessage(e,r)},writePackedVarint:function(t,n){n.length&&this.writeMessage(t,c,n)},writePackedSVarint:function(t,n){n.length&&this.writeMessage(t,a,n)},writePackedBoolean:function(t,n){n.length&&this.writeMessage(t,l,n)},writePackedFloat:function(t,n){n.length&&this.writeMessage(t,f,n)},writePackedDouble:function(t,n){n.length&&this.writeMessage(t,h,n)},writePackedFixed32:function(t,n){n.length&&this.writeMessage(t,d,n)},writePackedSFixed32:function(t,n){n.length&&this.writeMessage(t,w,n)},writePackedFixed64:function(t,n){n.length&&this.writeMessage(t,m,n)},writePackedSFixed64:function(t,n){n.length&&this.writeMessage(t,g,n)},writeBytesField:function(t,e){this.writeTag(t,n.Bytes),this.writeBytes(e)},writeFixed32Field:function(t,e){this.writeTag(t,n.Fixed32),this.writeFixed32(e)},writeSFixed32Field:function(t,e){this.writeTag(t,n.Fixed32),this.writeSFixed32(e)},writeFixed64Field:function(t,e){this.writeTag(t,n.Fixed64),this.writeFixed64(e)},writeSFixed64Field:function(t,e){this.writeTag(t,n.Fixed64),this.writeSFixed64(e)},writeVarintField:function(t,e){this.writeTag(t,n.Varint),this.writeVarint(e)},writeSVarintField:function(t,e){this.writeTag(t,n.Varint),this.writeSVarint(e)},writeStringField:function(t,e){this.writeTag(t,n.Bytes),this.writeString(e)},writeFloatField:function(t,e){this.writeTag(t,n.Fixed32),this.writeFloat(e)},writeDoubleField:function(t,e){this.writeTag(t,n.Fixed64),this.writeDouble(e)},writeBooleanField:function(t,n){this.writeVarintField(t,Boolean(n))}},Yi}(),Ki=a(Xi),to={},no=function(){if(Wi)return to;Wi=1;var t=to.Ring={};t.read=function(n,e){return n.readFields(t.zt,{path:[]},e)},t.zt=function(t,n,e){1===t&&e.readPackedVarint(n.path,!0)},t.write=function(t,n){t.path&&n.writePackedVarint(1,t.path)};var n=to.Building={};n.read=function(t,e){return t.readFields(n.zt,{minzoom:0,maxzoom:0,path:[],height:0,indoorid:"",altitude:0},e)},n.zt=function(n,e,r){1===n?e.minzoom=r.readVarint():2===n?e.maxzoom=r.readVarint():3===n?e.path.push(t.read(r,r.readVarint()+r.pos)):4===n?e.height=r.readVarint():5===n?e.indoorid=r.readString():6===n&&(e.altitude=r.readVarint(!0))},n.write=function(n,e){if(n.minzoom&&e.writeVarintField(1,n.minzoom),n.maxzoom&&e.writeVarintField(2,n.maxzoom),n.path)for(var r=0;r<n.path.length;r++)e.writeMessage(3,t.write,n.path[r]);n.height&&e.writeVarintField(4,n.height),n.indoorid&&e.writeStringField(5,n.indoorid),n.altitude&&e.writeVarintField(6,n.altitude)};var e=to.BuildingSameStyle={};e.read=function(t,n){return t.readFields(e.zt,{mainkey:0,subkey:0,items:[],resolution:0},n)},e.zt=function(t,e,r){1===t?e.mainkey=r.readVarint():2===t?e.subkey=r.readVarint():3===t?e.items.push(n.read(r,r.readVarint()+r.pos)):4===t&&(e.resolution=r.readVarint())},e.write=function(t,e){if(t.mainkey&&e.writeVarintField(1,t.mainkey),t.subkey&&e.writeVarintField(2,t.subkey),t.items)for(var r=0;r<t.items.length;r++)e.writeMessage(3,n.write,t.items[r]);t.resolution&&e.writeVarintField(4,t.resolution)};var r=to.BuildingLayer={};return r.read=function(t,n){return t.readFields(r.zt,{building:[]},n)},r.zt=function(t,n,r){1===t&&n.building.push(e.read(r,r.readVarint()+r.pos))},r.write=function(t,n){if(t.building)for(var r=0;r<t.building.length;r++)n.writeMessage(1,e.write,t.building[r])},to}(),eo=function(){if(Ji)return Qi;Ji=1;const t=2147483648;function n(t,n){const i=function(t,n){const i=r(t,n);let o=e(180),u=e(90);const s=o/(1<<i),c=u/(1<<i);return o=s>0?Math.floor(s+.5):Math.floor(s-.5),u=c>0?Math.floor(c+.5):Math.floor(c-.5),[o,u]}(t,n);return[2*i[0],2*i[1]]}function e(n){return Math.floor(n*t/180+.5)}function r(t,n){return 33-n-t}function i(n){return 180*n/t}function o(t,e){const r=n(t.z,e),i=r[0],o=r[1],u=1<<t.z;return[-i/2+t.x*i/u,o/2-(t.y+1)*o/u]}function u(t,n,e){const u=o(t,n),s=r(t.z,n);for(var c=[],a=0;a<e.length;a+=2){const t=e[a]+u[0];let n=t<<s;const r=e[a+1]+u[1]<<s;t>0&&n<0&&(n=2147483647);const o=i(n),f=i(r);c.push([o,f])}return c}function s(t){for(var n=0,e=2,r=t.length;e<r;e+=2)n+=((t[e]-t[e-2])**2+(t[e+1]-t[e-1])**2)**.5;return n}function c(t,n){for(var e=0,r=0,i=t.length;r<i;r+=2){var o=s(t.slice(r,r+4));if(!(o+e<n)){var u=(n-e)/o;return[Math.round(t[r]+u*(t[r+2]-t[r])),Math.round(t[r+1]+u*(t[r+3]-t[r+1])),r]}e+=o}return null}function a(t,n){n=n/180*Math.PI;let e=0,r=0,i=0;for(var o=2,u=t.length;o<u;o+=2){var s=t[o]-t[o-2],c=t[o+1]-t[o-1],a=(s**2+c**2)**.5;if(2==o)e=s,r=c,i=a;else{if(Math.acos((s*e+c*r)/a/i)>n)return!1;e=s,r=c,i=a}}return!0}return Qi={getWorldSize:n,riseLevel:function(t,n,i,s){return function(t,n,i){var u=t.z;const s=o(t,n),c=r(u,n);for(var a=[],f=0;f<i.length;f+=1){var h=i[f][0],l=i[f][1];l<-90&&(l=-90),l>90&&(l=90),h<-180&&(h=-180),h>180&&(h=180);let t=e(h),n=e(l);const r=t/(1<<c),o=n/(1<<c);t=r>0?Math.floor(r+.5):Math.floor(r-.5),n=o>0?Math.floor(o+.5):Math.floor(o-.5),t-=s[0],n-=s[1],a.push(t,n)}return a}(s,i-1,u(n,i,t))},ptsLength:s,getSmoothSlice:function(t,n,e){for(var r=function(t,n){var e=[],r=[],i=s(t);if(i>=n){for(var o=Math.floor(i/n),u=1;u<=o;u+=1)e.push(c(t,n*u));var a=[],f=[],h=0,l=void 0;for(u=0;u<e.length;u+=1){l=e[u][2]+2;var d=t.slice(h,l);f=[e[u][0],e[u][1]];for(var w=a.concat(d).concat(f),m=2;m<w.length;m+=2)w[m]===w[m-2]&&w[m+1]===w[m-1]&&(w.splice(m,2),m-=2);r.push(w),a=f,h=l}return r}}(t,n)||[],i=0;i<r.length;i+=1)a(r[i],e)||(r.splice(i,1),i-=1);return r},tileInnerCoords2LngLat:u,tileInnerCoord2LngLat:function(t,n,e,u){const s=o(t,n),c=e+s[0],a=u+s[1],f=r(t.z,n);return e=c<<f,u=a<<f,c>0&&e<0&&(e=2147483647),[i(e),i(u)]}}}();self.onmessage=function(t){!async function(t){const{coord:n,url:e,center:r}=t;try{const t=await fetch(e),i=await t.arrayBuffer(),o=new Ki(i),u=no.BuildingLayer.read(o),s=n.split("-").map((t=>parseInt(t,10))),c={z:s[0],x:s[1],y:s[2]},a=m.fromDegrees(...r),f=Cr.eastNorthUpToFixedFrame(a),h=Y.inverse(f,new Y);let l=[],d=[],w=[],g=[],v=0;for(let t=0;t<u.building.length;t++){const n=u.building[t];n.items.forEach((t=>{const{altitude:e,height:r}=t,i=t.path[0].path,o=eo.tileInnerCoords2LngLat(c,n.resolution,i),u=ki(o.flat()),s=u.length/3,a=o.length,f=o.map((t=>{const n=Y.multiplyByPoint(h,m.fromDegrees(t[0],t[1],e+0),new m);return[n.x,n.y,n.z]})),p=o.map((t=>{const n=Y.multiplyByPoint(h,m.fromDegrees(t[0],t[1],e+r+0),new m);return[n.x,n.y,n.z]})),y=m.fromArray(f[0]),b=m.fromArray(p[0]),M=m.subtract(b,y,new m),A=m.normalize(M,new m),x=m.multiplyByScalar(A,-1,new m);for(let t=0;t<a;t++)w.push(x.x,x.y,x.z),g.push(0);for(let t=0;t<a;t++)w.push(A.x,A.y,A.z),g.push(0);l=l.concat(f.flat(99),p.flat(99));for(let t=0;t<s;t+=1)d.push(v+u[3*t+2]),d.push(v+u[3*t+1]),d.push(v+u[3*t]);for(let t=0;t<s;t+=1)d.push(v+a+u[3*t]),d.push(v+a+u[3*t+1]),d.push(v+a+u[3*t+2]);for(let t=0;t<a;t++){const n=p[t],e=f[t],r=f[(t+1)%a],i=p[(t+1)%a];l.push(...n),l.push(...e),l.push(...r),l.push(...i),g.push(1,1,1,1);const o=new m(n[0]-e[0],n[1]-e[1],n[2]-e[2]),u=new m(r[0]-e[0],r[1]-e[1],r[2]-e[2]),s=m.cross(u,o,new m),c=m.normalize(s,new m);w.push(c.x,c.y,c.z,c.x,c.y,c.z,c.x,c.y,c.z,c.x,c.y,c.z),d.push(v+2*a+4*t+0),d.push(v+2*a+4*t+1),d.push(v+2*a+4*t+2),d.push(v+2*a+4*t+0),d.push(v+2*a+4*t+2),d.push(v+2*a+4*t+3)}v+=6*a}))}const p={id:n,coord:[c.z,c.x,c.y],vertices:new Float32Array(l),normals:new Float32Array(w),indices:new Uint16Array(d),faces:new Float32Array(g),model:f};self.postMessage({coord:n,status:3,data:p})}catch(t){self.postMessage({coord:n,status:4})}}(t.data)}},"function"==typeof define&&define.amd?define(factory):factory();\n'],{type:"application/javascript"}),n=URL.createObjectURL(e);this.worker=new Worker(n),this.worker.addEventListener("message",this.onMessage)}rp=!1;onDrop=(t,e)=>{delete this.ep[t],this.rp=!0};async loadTileset(){try{const t=await fetch(this.tilesetUrl),e=await t.json();this.tileset=e}catch(t){}}getViewFrustum(){const t=this._scene.camera,e=this.tileset.metadata.enuCenterGCJ02,n=t.frustum.computeCullingVolume(t.positionWC,t.directionWC,t.upWC).planes,i=r.Cartesian3.fromDegrees(...e),s=r.Transforms.eastNorthUpToFixedFrame(i),o=r.Matrix4.inverse(s,new r.Matrix4),a=n.map((t=>{const e=new r.Cartesian3(t.x,t.y,t.z),n=t.w,i=r.Matrix4.multiplyByPointAsVector(o,e,new r.Cartesian3),s=r.Cartesian3.multiplyByScalar(e,-n,new r.Cartesian3),a=r.Matrix4.multiplyByPoint(o,s,new r.Cartesian3),u=-r.Cartesian3.dot(i,a);return new r.Cartesian4(i.x,i.y,i.z,u)}));return new r.CullingVolume(a)}getTileKey(t){return t.coord.join("-")}computeTilesToRender(){if(!this.tileset)return{};const t=this._scene.camera,{enuCenterGCJ02:e}=this.tileset.metadata,n=this.getViewFrustum(),i=this.tileset.root,s=Fc(t.position,e),o=t=>{const e=new r.Cartesian3(t[0],t[1],t[2]),n=new r.Cartesian3(t[0]-t[3],t[1]-t[7],t[2]-t[11]),i=new r.Cartesian3(t[0]+t[3],t[1]-t[7],t[2]-t[11]),o=new r.Cartesian3(t[0]-t[3],t[1]+t[7],t[2]-t[11]),a=new r.Cartesian3(t[0]+t[3],t[1]+t[7],t[2]-t[11]);return Math.min(r.Cartesian3.distance(s,e),r.Cartesian3.distance(s,n),r.Cartesian3.distance(s,i),r.Cartesian3.distance(s,o),r.Cartesian3.distance(s,a))},a={},u=i.boundingVolume.box,h=new r.Cartesian3(u[0]-u[3],u[1]-u[7],u[2]-u[11]),l=new r.Cartesian3(u[0]+u[3],u[1]+u[7],u[2]+u[11]),c=new r.AxisAlignedBoundingBox(h,l);if(n.computeVisibility(c)===r.Intersect.OUTSIDE)return a;let f=i.children.length;for(let t=0;t<f;t++){const e=i.children[t],s=e.boundingVolume.box,u=new r.Cartesian3(s[0]-s[3],s[1]-s[7],s[2]-s[11]),h=new r.Cartesian3(s[0]+s[3],s[1]+s[7],s[2]+s[11]),l=new r.AxisAlignedBoundingBox(u,h);if(n.computeVisibility(l)!==r.Intersect.OUTSIDE&&o(s)<2e3){const t=e.content.uri,n=t.startsWith("http")?t:this.np+"/"+t;a[this.getTileKey(e)]=n}}return a}get name(){return this.do}clock=null;get entities(){return this.fo}get isLoading(){return this.po}get changedEvent(){return this.vo}get errorEvent(){return this.mo}get loadingEvent(){return this.yo}get show(){return this._show}set show(t){this._show=t}get clustering(){return this.wo}set clustering(t){if(!r.defined(t))throw new r.DeveloperError("value must be defined.");this.wo=t}update(){const t=Date.now();if(t-this.Qd<1e3)return!0;if(this.Qd=t,!this.tileset&&2!==this.tp)return this.loadTileset(),!0;const e=this.computeTilesToRender(),n=this.tileChanged(this.ip,e);if(this.ip=e,!n&&!this.rp)return!0;this.rp=!1;const i=Object.keys(e);for(let t=0;t<i.length;t++){const n=i[t];this.Ve.ar(n)||2===this.ep[n]||this.worker.postMessage({coord:n,url:e[n],center:this.tileset.metadata.enuCenterGCJ02})}return this.changedEvent.raiseEvent(),!0}tileChanged(t,e){const n=Object.keys(t),i=Object.keys(e);if(n.length!==i.length)return!0;for(let t=0;t<n.length;t++)if(!e[n[t]])return!0;return!1}getData(){const t=this.ip,e=Object.keys(t);let n=[];for(let t=0;t<e.length;t++){const i=this.Ve.nr(e[t],!1);i&&n.push(i)}return n}onMessage=t=>{const{coord:e,status:n,data:i}=t.data;3===n?(this.Ve.rr(e,i),this.ep[e]=3,this.changedEvent.raiseEvent(e)):this.ep[e]=4}}class Iy{show=!0;command;attributeLocations={position:0,normal:1,face:2};data;layer;wallColor;roofColor;createCommand(t){const e=r.RenderState.fromCache({depthTest:{enabled:!0},depthMask:!0,blending:r.BlendingState.ALPHA_BLEND});var n=new r.ShaderSource({sources:["in vec3 position;in vec3 normal;in float face;out vec3 v_positionEC;out vec3 v_normalEC;out float v_face;void main(){v_positionEC=(czm_modelView*vec4(position,1.0)).xyz;v_normalEC=czm_normal*normal;v_face=face;gl_Position=czm_modelViewProjection*vec4(position,1.0);}"]}),i=new r.ShaderSource({sources:["in vec3 v_positionEC;in vec3 v_normalEC;in float v_face;uniform vec4 u_roofColor;uniform vec4 u_wallColor;void main(){float lambert=dot(czm_sunDirectionEC,v_normalEC);lambert=0.8+lambert*0.2;vec3 color=(1.0-v_face)*u_roofColor.xyz+v_face*u_wallColor.xyz;out_FragColor=vec4(color*lambert,1.0);}"]}),s={u_wallColor:()=>this.wallColor,u_roofColor:()=>this.roofColor},o=r.ShaderProgram.fromCache({context:t,vertexShaderSource:n,fragmentShaderSource:i,attributeLocations:this.attributeLocations});return new r.DrawCommand({vertexArray:this.createVertexArray(t),primitiveType:r.PrimitiveType.TRIANGLES,renderState:e,shaderProgram:o,uniformMap:s,owner:this,pass:r.Pass.OPAQUE,modelMatrix:this.data.model})}createVertexArray(t){var e=new r.Geometry({attributes:{position:new r.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:this.data.vertices}),normal:new r.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:3,values:this.data.normals}),face:new r.GeometryAttribute({componentDatatype:r.ComponentDatatype.FLOAT,componentsPerAttribute:1,values:this.data.faces})},indices:this.data.indices,primitiveType:r.PrimitiveType.TRIANGLES,boundingSphere:r.BoundingSphere.fromVertices(this.data.positions)});return r.VertexArray.fromGeometry({context:t,geometry:e,attributeLocations:this.attributeLocations,bufferUsage:r.BufferUsage.STATIC_DRAW})}constructor(t={}){this.data=t.data,this.layer=t.layer,this.wallColor=t.wallColor,this.roofColor=t.roofColor}update(t){this.show&&this.layer&&(r.defined(this.command)||(this.command=this.createCommand(t.context)),r.defined(this.command)&&t.commandList.push(this.command))}isDestroyed(){return!1}destroy(){return r.defined(this.command)&&(this.command.shaderProgram=this.command.shaderProgram&&this.command.shaderProgram.destroy()),r.destroyObject(this)}setWallColor(t){this.wallColor=t,this.command=null}setRoofColor(t){this.roofColor=t,this.command=null}}class Ty{show=!0;dataSource;Hn;_scene;me=!1;Sp=2e3;_dirty=!0;Mp={};Ep;set roofColor(t){this.Ep=t,Object.keys(this.Mp).forEach((e=>{this.Mp[e].setRoofColor(t)})),this.requestRender()}get roofColor(){return this.Ep}Cp;set wallColor(t){this.Cp=t,Object.keys(this.Mp).forEach((e=>{this.Mp[e].setWallColor(t)})),this.requestRender()}get wallColor(){return this.Cp}set minDistance(t){this.Sp=t,this.dataSource.minDistance=this.Sp}get minDistance(){return this.Sp}onData=()=>{this.me||(this._dirty=!0,this.requestRender())};requestRender=()=>{this.Hn.scene.requestRender()};isDestroyed(){return this.me}destroy(){this.dataSource.changedEvent.removeEventListener(this.onData),this.me=!0,this.Hn.dataSources.remove(this.dataSource),Object.keys(this.Mp).forEach((t=>{this._scene.primitives.remove(this.Mp[t])})),this.requestRender()}constructor(t){this.Cp=t.wallColor||new r.Color(.7,.7,.7,.7),this.Ep=t.roofColor||new r.Color(.92,.92,.92,1),this.Hn=t.viewer,this._scene=t.viewer.scene,this.Sp=t.minDistance||2e3,this.dataSource=new Oy({scene:this._scene,tileset:t.tileset,minDistance:this.minDistance}),this.onData=ky(this.onData,500,{maxWait:1e3}),this.dataSource.changedEvent.addEventListener(this.onData),this.Hn.dataSources.add(this.dataSource)}Ap(t,e){const n=e.reduce(((t,e)=>(t[e.id]=e,t)),{}),i=Object.keys(t),r=[],s=[];for(let t=0;t<i.length;t++)n[i[t]]||r.push(i[t]);for(let n=0;n<e.length;n++)t[e[n].id]||s.push(e[n]);return{add:s,remove:r}}update(t){const e=this.dataSource.getData(),{add:n,remove:i}=this.Ap(this.Mp,e);for(let t=0;t<i.length;t++){const e=i[t];this._scene.primitives.remove(this.Mp[e]),delete this.Mp[e]}for(let t=0;t<n.length;t++){const e=n[t].id,i=new Iy({data:n[t],layer:this,wallColor:this.wallColor,roofColor:this.roofColor});this.Mp[e]=i}Object.keys(this.Mp).forEach((e=>{this.Mp[e].update(t)}))}debugElements=[];visualizeTiles(){const t=this.dataSource.ip,n=t=>{const[e,n,i]=t,r=Math.pow(2,e),s=360/r,o=180/r;return{bl:[n*s-180,90-(i+1)*o,0],br:[(n+1)*s-180,90-(i+1)*o,0],tl:[n*s-180,90-i*o,0],tr:[(n+1)*s-180,90-i*o,0]}},i=Object.keys(t).map((t=>t.split("-").map((t=>parseInt(t,10)))));this.debugElements.forEach((t=>this.Hn.entities.remove(t))),this.debugElements=[];for(let t=0;t<i.length;t++){const s=i[t],{bl:o,br:a,tl:u,tr:h}=n(s),l=e.Cartesian3.fromDegreesArray([o[0],o[1],a[0],a[1],h[0],h[1],u[0],u[1]]),c=this.Hn.entities.add({name:s.join("-"),polyline:{positions:l,material:r.Color.BLUE.withAlpha(.9),width:8}});this.debugElements.push(c);const f=e.Cartesian3.fromDegrees((o[0]+h[0])/2,(o[1]+h[1])/2),d=this.Hn.entities.add({position:f,name:i.join("-"),label:{text:s.join("-"),fillColor:r.Color.WHITE,font:"20px sans-serif",disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.debugElements.push(d)}this.Hn.scene.requestRender()}}class zy{url;zoom;Op={};constructor(t){this.url=t?.url,this.zoom=t?.zoom||17}async sample(t,e){try{const n=function(t,e,n){const i=Math.pow(2,n),r=360/i,s=180/i;return[n,Math.floor(t/r)+i/2,i/2-Math.ceil(e/s)]}(t,e,this.zoom),i=n.join("_")+".bin",r=this.url.endsWith("/")?this.url+i:this.url+"/"+i;let s=this.Op[r];s||(s=this.Ip(r));const o=await s;if(!o)return void delete this.Op[r];const{width:a,height:u,transform:h,data:l}=o,c=Math.floor((t-h[2])/h[0])+Math.floor((e-h[5])/h[4])*a;if(c>=0&&c<a*u){const t=l[c];if(-9999===t)return;return t}return}catch(t){return}}Ip(t){const e=fetch(t).then((t=>{if(!t.ok)throw new Error(`HTTP status: ${t.status}`);return t.arrayBuffer()})).then((t=>{const e=new Uint32Array(t),n=e[0],i=e[1],r=new Float64Array(t,8);return{width:n,height:i,transform:[r[0],r[1],r[2],r[3],r[4],r[5]],data:new Int16Array(t,56)}})).catch((t=>null));return this.Op[t]=e,e}}class Ry{constructor(t){void 0===t&&(t=[0,0,0,0,0,0,0,0,0]),this.elements=t}identity(){const t=this.elements;t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=1,t[5]=0,t[6]=0,t[7]=0,t[8]=1}setZero(){const t=this.elements;t[0]=0,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=0,t[6]=0,t[7]=0,t[8]=0}setTrace(t){const e=this.elements;e[0]=t.x,e[4]=t.y,e[8]=t.z}getTrace(t){void 0===t&&(t=new Py);const e=this.elements;return t.x=e[0],t.y=e[4],t.z=e[8],t}vmult(t,e){void 0===e&&(e=new Py);const n=this.elements,i=t.x,r=t.y,s=t.z;return e.x=n[0]*i+n[1]*r+n[2]*s,e.y=n[3]*i+n[4]*r+n[5]*s,e.z=n[6]*i+n[7]*r+n[8]*s,e}smult(t){for(let e=0;e<this.elements.length;e++)this.elements[e]*=t}mmult(t,e){void 0===e&&(e=new Ry);const n=this.elements,i=t.elements,r=e.elements,s=n[0],o=n[1],a=n[2],u=n[3],h=n[4],l=n[5],c=n[6],f=n[7],d=n[8],p=i[0],v=i[1],m=i[2],y=i[3],w=i[4],g=i[5],b=i[6],_=i[7],x=i[8];return r[0]=s*p+o*y+a*b,r[1]=s*v+o*w+a*_,r[2]=s*m+o*g+a*x,r[3]=u*p+h*y+l*b,r[4]=u*v+h*w+l*_,r[5]=u*m+h*g+l*x,r[6]=c*p+f*y+d*b,r[7]=c*v+f*w+d*_,r[8]=c*m+f*g+d*x,e}scale(t,e){void 0===e&&(e=new Ry);const n=this.elements,i=e.elements;for(let e=0;3!==e;e++)i[3*e+0]=t.x*n[3*e+0],i[3*e+1]=t.y*n[3*e+1],i[3*e+2]=t.z*n[3*e+2];return e}solve(t,e){void 0===e&&(e=new Py);const n=[];let i,r;for(i=0;i<12;i++)n.push(0);for(i=0;i<3;i++)for(r=0;r<3;r++)n[i+4*r]=this.elements[i+3*r];n[3]=t.x,n[7]=t.y,n[11]=t.z;let s=3;const o=s;let a,u;do{if(i=o-s,0===n[i+4*i])for(r=i+1;r<o;r++)if(0!==n[i+4*r]){a=4;do{u=4-a,n[u+4*i]+=n[u+4*r]}while(--a);break}if(0!==n[i+4*i])for(r=i+1;r<o;r++){const t=n[i+4*r]/n[i+4*i];a=4;do{u=4-a,n[u+4*r]=u<=i?0:n[u+4*r]-n[u+4*i]*t}while(--a)}}while(--s);if(e.z=n[11]/n[10],e.y=(n[7]-n[6]*e.z)/n[5],e.x=(n[3]-n[2]*e.z-n[1]*e.y)/n[0],isNaN(e.x)||isNaN(e.y)||isNaN(e.z)||e.x===1/0||e.y===1/0||e.z===1/0)throw`Could not solve equation! Got x=[${e.toString()}], b=[${t.toString()}], A=[${this.toString()}]`;return e}e(t,e,n){if(void 0===n)return this.elements[e+3*t];this.elements[e+3*t]=n}copy(t){for(let e=0;e<t.elements.length;e++)this.elements[e]=t.elements[e];return this}toString(){let t="";for(let e=0;e<9;e++)t+=this.elements[e]+",";return t}reverse(t){void 0===t&&(t=new Ry);const e=Fy;let n,i;for(n=0;n<3;n++)for(i=0;i<3;i++)e[n+6*i]=this.elements[n+3*i];e[3]=1,e[9]=0,e[15]=0,e[4]=0,e[10]=1,e[16]=0,e[5]=0,e[11]=0,e[17]=1;let r=3;const s=r;let o,a;do{if(n=s-r,0===e[n+6*n])for(i=n+1;i<s;i++)if(0!==e[n+6*i]){o=6;do{a=6-o,e[a+6*n]+=e[a+6*i]}while(--o);break}if(0!==e[n+6*n])for(i=n+1;i<s;i++){const t=e[n+6*i]/e[n+6*n];o=6;do{a=6-o,e[a+6*i]=a<=n?0:e[a+6*i]-e[a+6*n]*t}while(--o)}}while(--r);n=2;do{i=n-1;do{const t=e[n+6*i]/e[n+6*n];o=6;do{a=6-o,e[a+6*i]=e[a+6*i]-e[a+6*n]*t}while(--o)}while(i--)}while(--n);n=2;do{const t=1/e[n+6*n];o=6;do{a=6-o,e[a+6*n]=e[a+6*n]*t}while(--o)}while(n--);n=2;do{i=2;do{if(a=e[3+i+6*n],isNaN(a)||a===1/0)throw`Could not reverse! A=[${this.toString()}]`;t.e(n,i,a)}while(i--)}while(n--);return t}setRotationFromQuaternion(t){const e=t.x,n=t.y,i=t.z,r=t.w,s=e+e,o=n+n,a=i+i,u=e*s,h=e*o,l=e*a,c=n*o,f=n*a,d=i*a,p=r*s,v=r*o,m=r*a,y=this.elements;return y[0]=1-(c+d),y[1]=h-m,y[2]=l+v,y[3]=h+m,y[4]=1-(u+d),y[5]=f-p,y[6]=l-v,y[7]=f+p,y[8]=1-(u+c),this}transpose(t){void 0===t&&(t=new Ry);const e=this.elements,n=t.elements;let i;return n[0]=e[0],n[4]=e[4],n[8]=e[8],i=e[1],n[1]=e[3],n[3]=i,i=e[2],n[2]=e[6],n[6]=i,i=e[5],n[5]=e[7],n[7]=i,t}}const Fy=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];class Py{constructor(t,e,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),this.x=t,this.y=e,this.z=n}cross(t,e){void 0===e&&(e=new Py);const n=t.x,i=t.y,r=t.z,s=this.x,o=this.y,a=this.z;return e.x=o*r-a*i,e.y=a*n-s*r,e.z=s*i-o*n,e}set(t,e,n){return this.x=t,this.y=e,this.z=n,this}setZero(){this.x=this.y=this.z=0}vadd(t,e){if(!e)return new Py(this.x+t.x,this.y+t.y,this.z+t.z);e.x=t.x+this.x,e.y=t.y+this.y,e.z=t.z+this.z}vsub(t,e){if(!e)return new Py(this.x-t.x,this.y-t.y,this.z-t.z);e.x=this.x-t.x,e.y=this.y-t.y,e.z=this.z-t.z}crossmat(){return new Ry([0,-this.z,this.y,this.z,0,-this.x,-this.y,this.x,0])}normalize(){const t=this.x,e=this.y,n=this.z,i=Math.sqrt(t*t+e*e+n*n);if(i>0){const t=1/i;this.x*=t,this.y*=t,this.z*=t}else this.x=0,this.y=0,this.z=0;return i}unit(t){void 0===t&&(t=new Py);const e=this.x,n=this.y,i=this.z;let r=Math.sqrt(e*e+n*n+i*i);return r>0?(r=1/r,t.x=e*r,t.y=n*r,t.z=i*r):(t.x=1,t.y=0,t.z=0),t}length(){const t=this.x,e=this.y,n=this.z;return Math.sqrt(t*t+e*e+n*n)}lengthSquared(){return this.dot(this)}distanceTo(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z;return Math.sqrt((r-e)*(r-e)+(s-n)*(s-n)+(o-i)*(o-i))}distanceSquared(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z;return(r-e)*(r-e)+(s-n)*(s-n)+(o-i)*(o-i)}scale(t,e){void 0===e&&(e=new Py);const n=this.x,i=this.y,r=this.z;return e.x=t*n,e.y=t*i,e.z=t*r,e}vmul(t,e){return void 0===e&&(e=new Py),e.x=t.x*this.x,e.y=t.y*this.y,e.z=t.z*this.z,e}addScaledVector(t,e,n){return void 0===n&&(n=new Py),n.x=this.x+t*e.x,n.y=this.y+t*e.y,n.z=this.z+t*e.z,n}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}isZero(){return 0===this.x&&0===this.y&&0===this.z}negate(t){return void 0===t&&(t=new Py),t.x=-this.x,t.y=-this.y,t.z=-this.z,t}tangents(t,e){const n=this.length();if(n>0){const i=Dy,r=1/n;i.set(this.x*r,this.y*r,this.z*r);const s=Ny;Math.abs(i.x)<.9?(s.set(1,0,0),i.cross(s,t)):(s.set(0,1,0),i.cross(s,t)),i.cross(t,e)}else t.set(1,0,0),e.set(0,1,0)}toString(){return`${this.x},${this.y},${this.z}`}toArray(){return[this.x,this.y,this.z]}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}lerp(t,e,n){const i=this.x,r=this.y,s=this.z;n.x=i+(t.x-i)*e,n.y=r+(t.y-r)*e,n.z=s+(t.z-s)*e}almostEquals(t,e){return void 0===e&&(e=1e-6),!(Math.abs(this.x-t.x)>e||Math.abs(this.y-t.y)>e||Math.abs(this.z-t.z)>e)}almostZero(t){return void 0===t&&(t=1e-6),!(Math.abs(this.x)>t||Math.abs(this.y)>t||Math.abs(this.z)>t)}isAntiparallelTo(t,e){return this.negate(Uy),Uy.almostEquals(t,e)}clone(){return new Py(this.x,this.y,this.z)}}Py.ZERO=new Py(0,0,0),Py.UNIT_X=new Py(1,0,0),Py.UNIT_Y=new Py(0,1,0),Py.UNIT_Z=new Py(0,0,1);const Dy=new Py,Ny=new Py,Uy=new Py;class qy{constructor(t){void 0===t&&(t={}),this.lowerBound=new Py,this.upperBound=new Py,t.lowerBound&&this.lowerBound.copy(t.lowerBound),t.upperBound&&this.upperBound.copy(t.upperBound)}setFromPoints(t,e,n,i){const r=this.lowerBound,s=this.upperBound,o=n;r.copy(t[0]),o&&o.vmult(r,r),s.copy(r);for(let e=1;e<t.length;e++){let n=t[e];o&&(o.vmult(n,jy),n=jy),n.x>s.x&&(s.x=n.x),n.x<r.x&&(r.x=n.x),n.y>s.y&&(s.y=n.y),n.y<r.y&&(r.y=n.y),n.z>s.z&&(s.z=n.z),n.z<r.z&&(r.z=n.z)}return e&&(e.vadd(r,r),e.vadd(s,s)),i&&(r.x-=i,r.y-=i,r.z-=i,s.x+=i,s.y+=i,s.z+=i),this}copy(t){return this.lowerBound.copy(t.lowerBound),this.upperBound.copy(t.upperBound),this}clone(){return(new qy).copy(this)}extend(t){this.lowerBound.x=Math.min(this.lowerBound.x,t.lowerBound.x),this.upperBound.x=Math.max(this.upperBound.x,t.upperBound.x),this.lowerBound.y=Math.min(this.lowerBound.y,t.lowerBound.y),this.upperBound.y=Math.max(this.upperBound.y,t.upperBound.y),this.lowerBound.z=Math.min(this.lowerBound.z,t.lowerBound.z),this.upperBound.z=Math.max(this.upperBound.z,t.upperBound.z)}overlaps(t){const e=this.lowerBound,n=this.upperBound,i=t.lowerBound,r=t.upperBound,s=i.x<=n.x&&n.x<=r.x||e.x<=r.x&&r.x<=n.x,o=i.y<=n.y&&n.y<=r.y||e.y<=r.y&&r.y<=n.y,a=i.z<=n.z&&n.z<=r.z||e.z<=r.z&&r.z<=n.z;return s&&o&&a}volume(){const t=this.lowerBound,e=this.upperBound;return(e.x-t.x)*(e.y-t.y)*(e.z-t.z)}contains(t){const e=this.lowerBound,n=this.upperBound,i=t.lowerBound,r=t.upperBound;return e.x<=i.x&&n.x>=r.x&&e.y<=i.y&&n.y>=r.y&&e.z<=i.z&&n.z>=r.z}getCorners(t,e,n,i,r,s,o,a){const u=this.lowerBound,h=this.upperBound;t.copy(u),e.set(h.x,u.y,u.z),n.set(h.x,h.y,u.z),i.set(u.x,h.y,h.z),r.set(h.x,u.y,h.z),s.set(u.x,h.y,u.z),o.set(u.x,u.y,h.z),a.copy(h)}toLocalFrame(t,e){const n=By,i=n[0],r=n[1],s=n[2],o=n[3],a=n[4],u=n[5],h=n[6],l=n[7];this.getCorners(i,r,s,o,a,u,h,l);for(let e=0;8!==e;e++){const i=n[e];t.pointToLocal(i,i)}return e.setFromPoints(n)}toWorldFrame(t,e){const n=By,i=n[0],r=n[1],s=n[2],o=n[3],a=n[4],u=n[5],h=n[6],l=n[7];this.getCorners(i,r,s,o,a,u,h,l);for(let e=0;8!==e;e++){const i=n[e];t.pointToWorld(i,i)}return e.setFromPoints(n)}overlapsRay(t){const{direction:e,from:n}=t,i=1/e.x,r=1/e.y,s=1/e.z,o=(this.lowerBound.x-n.x)*i,a=(this.upperBound.x-n.x)*i,u=(this.lowerBound.y-n.y)*r,h=(this.upperBound.y-n.y)*r,l=(this.lowerBound.z-n.z)*s,c=(this.upperBound.z-n.z)*s,f=Math.max(Math.max(Math.min(o,a),Math.min(u,h)),Math.min(l,c)),d=Math.min(Math.min(Math.max(o,a),Math.max(u,h)),Math.max(l,c));return!(d<0||f>d)}}const jy=new Py,By=[new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py];class Ly{constructor(){this.matrix=[]}get(t,e){let{index:n}=t,{index:i}=e;if(i>n){const t=i;i=n,n=t}return this.matrix[(n*(n+1)>>1)+i-1]}set(t,e,n){let{index:i}=t,{index:r}=e;if(r>i){const t=r;r=i,i=t}this.matrix[(i*(i+1)>>1)+r-1]=n?1:0}reset(){for(let t=0,e=this.matrix.length;t!==e;t++)this.matrix[t]=0}setNumObjects(t){this.matrix.length=t*(t-1)>>1}}class Hy{addEventListener(t,e){void 0===this.Tp&&(this.Tp={});const n=this.Tp;return void 0===n[t]&&(n[t]=[]),n[t].includes(e)||n[t].push(e),this}hasEventListener(t,e){if(void 0===this.Tp)return!1;const n=this.Tp;return!(void 0===n[t]||!n[t].includes(e))}hasAnyEventListener(t){return void 0!==this.Tp&&void 0!==this.Tp[t]}removeEventListener(t,e){if(void 0===this.Tp)return this;const n=this.Tp;if(void 0===n[t])return this;const i=n[t].indexOf(e);return-1!==i&&n[t].splice(i,1),this}dispatchEvent(t){if(void 0===this.Tp)return this;const e=this.Tp[t.type];if(void 0!==e){t.target=this;for(let n=0,i=e.length;n<i;n++)e[n].call(this,t)}return this}}class Wy{constructor(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=1),this.x=t,this.y=e,this.z=n,this.w=i}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}toString(){return`${this.x},${this.y},${this.z},${this.w}`}toArray(){return[this.x,this.y,this.z,this.w]}setFromAxisAngle(t,e){const n=Math.sin(.5*e);return this.x=t.x*n,this.y=t.y*n,this.z=t.z*n,this.w=Math.cos(.5*e),this}toAxisAngle(t){void 0===t&&(t=new Py),this.normalize();const e=2*Math.acos(this.w),n=Math.sqrt(1-this.w*this.w);return n<.001?(t.x=this.x,t.y=this.y,t.z=this.z):(t.x=this.x/n,t.y=this.y/n,t.z=this.z/n),[t,e]}setFromVectors(t,e){if(t.isAntiparallelTo(e)){const e=Vy,n=Gy;t.tangents(e,n),this.setFromAxisAngle(e,Math.PI)}else{const n=t.cross(e);this.x=n.x,this.y=n.y,this.z=n.z,this.w=Math.sqrt(t.length()**2*e.length()**2)+t.dot(e),this.normalize()}return this}mult(t,e){void 0===e&&(e=new Wy);const n=this.x,i=this.y,r=this.z,s=this.w,o=t.x,a=t.y,u=t.z,h=t.w;return e.x=n*h+s*o+i*u-r*a,e.y=i*h+s*a+r*o-n*u,e.z=r*h+s*u+n*a-i*o,e.w=s*h-n*o-i*a-r*u,e}inverse(t){void 0===t&&(t=new Wy);const e=this.x,n=this.y,i=this.z,r=this.w;this.conjugate(t);const s=1/(e*e+n*n+i*i+r*r);return t.x*=s,t.y*=s,t.z*=s,t.w*=s,t}conjugate(t){return void 0===t&&(t=new Wy),t.x=-this.x,t.y=-this.y,t.z=-this.z,t.w=this.w,t}normalize(){let t=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(t=1/t,this.x*=t,this.y*=t,this.z*=t,this.w*=t),this}normalizeFast(){const t=(3-(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w))/2;return 0===t?(this.x=0,this.y=0,this.z=0,this.w=0):(this.x*=t,this.y*=t,this.z*=t,this.w*=t),this}vmult(t,e){void 0===e&&(e=new Py);const n=t.x,i=t.y,r=t.z,s=this.x,o=this.y,a=this.z,u=this.w,h=u*n+o*r-a*i,l=u*i+a*n-s*r,c=u*r+s*i-o*n,f=-s*n-o*i-a*r;return e.x=h*u+f*-s+l*-a-c*-o,e.y=l*u+f*-o+c*-s-h*-a,e.z=c*u+f*-a+h*-o-l*-s,e}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this}toEuler(t,e){let n,i,r;void 0===e&&(e="YZX");const s=this.x,o=this.y,a=this.z,u=this.w;if("YZX"!==e)throw new Error(`Euler order ${e} not supported yet.`);{const t=s*o+a*u;if(t>.499&&(n=2*Math.atan2(s,u),i=Math.PI/2,r=0),t<-.499&&(n=-2*Math.atan2(s,u),i=-Math.PI/2,r=0),void 0===n){const e=s*s,h=o*o,l=a*a;n=Math.atan2(2*o*u-2*s*a,1-2*h-2*l),i=Math.asin(2*t),r=Math.atan2(2*s*u-2*o*a,1-2*e-2*l)}}t.y=n,t.z=i,t.x=r}setFromEuler(t,e,n,i){void 0===i&&(i="XYZ");const r=Math.cos(t/2),s=Math.cos(e/2),o=Math.cos(n/2),a=Math.sin(t/2),u=Math.sin(e/2),h=Math.sin(n/2);return"XYZ"===i?(this.x=a*s*o+r*u*h,this.y=r*u*o-a*s*h,this.z=r*s*h+a*u*o,this.w=r*s*o-a*u*h):"YXZ"===i?(this.x=a*s*o+r*u*h,this.y=r*u*o-a*s*h,this.z=r*s*h-a*u*o,this.w=r*s*o+a*u*h):"ZXY"===i?(this.x=a*s*o-r*u*h,this.y=r*u*o+a*s*h,this.z=r*s*h+a*u*o,this.w=r*s*o-a*u*h):"ZYX"===i?(this.x=a*s*o-r*u*h,this.y=r*u*o+a*s*h,this.z=r*s*h-a*u*o,this.w=r*s*o+a*u*h):"YZX"===i?(this.x=a*s*o+r*u*h,this.y=r*u*o+a*s*h,this.z=r*s*h-a*u*o,this.w=r*s*o-a*u*h):"XZY"===i&&(this.x=a*s*o-r*u*h,this.y=r*u*o-a*s*h,this.z=r*s*h+a*u*o,this.w=r*s*o+a*u*h),this}clone(){return new Wy(this.x,this.y,this.z,this.w)}slerp(t,e,n){void 0===n&&(n=new Wy);const i=this.x,r=this.y,s=this.z,o=this.w;let a,u,h,l,c,f=t.x,d=t.y,p=t.z,v=t.w;return u=i*f+r*d+s*p+o*v,u<0&&(u=-u,f=-f,d=-d,p=-p,v=-v),1-u>1e-6?(a=Math.acos(u),h=Math.sin(a),l=Math.sin((1-e)*a)/h,c=Math.sin(e*a)/h):(l=1-e,c=e),n.x=l*i+c*f,n.y=l*r+c*d,n.z=l*s+c*p,n.w=l*o+c*v,n}integrate(t,e,n,i){void 0===i&&(i=new Wy);const r=t.x*n.x,s=t.y*n.y,o=t.z*n.z,a=this.x,u=this.y,h=this.z,l=this.w,c=.5*e;return i.x+=c*(r*l+s*h-o*u),i.y+=c*(s*l+o*a-r*h),i.z+=c*(o*l+r*u-s*a),i.w+=c*(-r*a-s*u-o*h),i}}const Vy=new Py,Gy=new Py;class Yy{constructor(t){void 0===t&&(t={}),this.id=Yy.idCounter++,this.type=t.type||0,this.boundingSphereRadius=0,this.collisionResponse=!t.collisionResponse||t.collisionResponse,this.collisionFilterGroup=void 0!==t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask=void 0!==t.collisionFilterMask?t.collisionFilterMask:-1,this.material=t.material?t.material:null,this.body=null}updateBoundingSphereRadius(){throw`computeBoundingSphereRadius() not implemented for shape type ${this.type}`}volume(){throw`volume() not implemented for shape type ${this.type}`}calculateLocalInertia(t,e){throw`calculateLocalInertia() not implemented for shape type ${this.type}`}calculateWorldAABB(t,e,n,i){throw`calculateWorldAABB() not implemented for shape type ${this.type}`}}Yy.idCounter=0,Yy.types={SPHERE:1,PLANE:2,BOX:4,COMPOUND:8,CONVEXPOLYHEDRON:16,HEIGHTFIELD:32,PARTICLE:64,CYLINDER:128,TRIMESH:256};class Ky{constructor(t){void 0===t&&(t={}),this.position=new Py,this.quaternion=new Wy,t.position&&this.position.copy(t.position),t.quaternion&&this.quaternion.copy(t.quaternion)}pointToLocal(t,e){return Ky.pointToLocalFrame(this.position,this.quaternion,t,e)}pointToWorld(t,e){return Ky.pointToWorldFrame(this.position,this.quaternion,t,e)}vectorToWorldFrame(t,e){return void 0===e&&(e=new Py),this.quaternion.vmult(t,e),e}static pointToLocalFrame(t,e,n,i){return void 0===i&&(i=new Py),n.vsub(t,i),e.conjugate(Xy),Xy.vmult(i,i),i}static pointToWorldFrame(t,e,n,i){return void 0===i&&(i=new Py),e.vmult(n,i),i.vadd(t,i),i}static vectorToWorldFrame(t,e,n){return void 0===n&&(n=new Py),t.vmult(e,n),n}static vectorToLocalFrame(t,e,n,i){return void 0===i&&(i=new Py),e.w*=-1,e.vmult(n,i),e.w*=-1,i}}const Xy=new Wy;class Qy extends Yy{constructor(t){void 0===t&&(t={});const{vertices:e=[],faces:n=[],normals:i=[],axes:r,boundingSphereRadius:s}=t;super({type:Yy.types.CONVEXPOLYHEDRON}),this.vertices=e,this.faces=n,this.faceNormals=i,0===this.faceNormals.length&&this.computeNormals(),s?this.boundingSphereRadius=s:this.updateBoundingSphereRadius(),this.worldVertices=[],this.worldVerticesNeedsUpdate=!0,this.worldFaceNormals=[],this.worldFaceNormalsNeedsUpdate=!0,this.uniqueAxes=r?r.slice():null,this.uniqueEdges=[],this.computeEdges()}computeEdges(){const t=this.faces,e=this.vertices,n=this.uniqueEdges;n.length=0;const i=new Py;for(let r=0;r!==t.length;r++){const s=t[r],o=s.length;for(let t=0;t!==o;t++){const r=(t+1)%o;e[s[t]].vsub(e[s[r]],i),i.normalize();let a=!1;for(let t=0;t!==n.length;t++)if(n[t].almostEquals(i)||n[t].almostEquals(i)){a=!0;break}a||n.push(i.clone())}}}computeNormals(){this.faceNormals.length=this.faces.length;for(let t=0;t<this.faces.length;t++){for(let e=0;e<this.faces[t].length;e++)if(!this.vertices[this.faces[t][e]])throw new Error(`Vertex ${this.faces[t][e]} not found!`);const e=this.faceNormals[t]||new Py;this.getFaceNormal(t,e),e.negate(e),this.faceNormals[t]=e;const n=this.vertices[this.faces[t][0]];if(e.dot(n)<0)for(let e=0;e<this.faces[t].length;e++);}}getFaceNormal(t,e){const n=this.faces[t],i=this.vertices[n[0]],r=this.vertices[n[1]],s=this.vertices[n[2]];Qy.computeNormal(i,r,s,e)}static computeNormal(t,e,n,i){const r=new Py,s=new Py;e.vsub(t,s),n.vsub(e,r),r.cross(s,i),i.isZero()||i.normalize()}clipAgainstHull(t,e,n,i,r,s,o,a,u){const h=new Py;let l=-1,c=-Number.MAX_VALUE;for(let t=0;t<n.faces.length;t++){h.copy(n.faceNormals[t]),r.vmult(h,h);const e=h.dot(s);e>c&&(c=e,l=t)}const f=[];for(let t=0;t<n.faces[l].length;t++){const e=n.vertices[n.faces[l][t]],s=new Py;s.copy(e),r.vmult(s,s),i.vadd(s,s),f.push(s)}l>=0&&this.clipFaceAgainstHull(s,t,e,f,o,a,u)}findSeparatingAxis(t,e,n,i,r,s,o,a){const u=new Py,h=new Py,l=new Py,c=new Py,f=new Py,d=new Py;let p=Number.MAX_VALUE;const v=this;if(v.uniqueAxes)for(let o=0;o!==v.uniqueAxes.length;o++){n.vmult(v.uniqueAxes[o],u);const a=v.testSepAxis(u,t,e,n,i,r);if(!1===a)return!1;a<p&&(p=a,s.copy(u))}else{const a=o?o.length:v.faces.length;for(let h=0;h<a;h++){const a=o?o[h]:h;u.copy(v.faceNormals[a]),n.vmult(u,u);const l=v.testSepAxis(u,t,e,n,i,r);if(!1===l)return!1;l<p&&(p=l,s.copy(u))}}if(t.uniqueAxes)for(let o=0;o!==t.uniqueAxes.length;o++){r.vmult(t.uniqueAxes[o],h);const a=v.testSepAxis(h,t,e,n,i,r);if(!1===a)return!1;a<p&&(p=a,s.copy(h))}else{const o=a?a.length:t.faces.length;for(let u=0;u<o;u++){const o=a?a[u]:u;h.copy(t.faceNormals[o]),r.vmult(h,h);const l=v.testSepAxis(h,t,e,n,i,r);if(!1===l)return!1;l<p&&(p=l,s.copy(h))}}for(let o=0;o!==v.uniqueEdges.length;o++){n.vmult(v.uniqueEdges[o],c);for(let o=0;o!==t.uniqueEdges.length;o++)if(r.vmult(t.uniqueEdges[o],f),c.cross(f,d),!d.almostZero()){d.normalize();const o=v.testSepAxis(d,t,e,n,i,r);if(!1===o)return!1;o<p&&(p=o,s.copy(d))}}return i.vsub(e,l),l.dot(s)>0&&s.negate(s),!0}testSepAxis(t,e,n,i,r,s){Qy.project(this,t,n,i,Zy),Qy.project(e,t,r,s,Jy);const o=Zy[0],a=Zy[1],u=Jy[0],h=Jy[1];if(o<h||u<a)return!1;const l=o-h,c=u-a;return l<c?l:c}calculateLocalInertia(t,e){const n=new Py,i=new Py;this.computeLocalAABB(i,n);const r=n.x-i.x,s=n.y-i.y,o=n.z-i.z;e.x=1/12*t*(4*s*s+4*o*o),e.y=1/12*t*(4*r*r+4*o*o),e.z=1/12*t*(4*s*s+4*r*r)}getPlaneConstantOfFace(t){const e=this.faces[t],n=this.faceNormals[t],i=this.vertices[e[0]];return-n.dot(i)}clipFaceAgainstHull(t,e,n,i,r,s,o){const a=new Py,u=new Py,h=new Py,l=new Py,c=new Py,f=new Py,d=new Py,p=new Py,v=this,m=i,y=[];let w=-1,g=Number.MAX_VALUE;for(let e=0;e<v.faces.length;e++){a.copy(v.faceNormals[e]),n.vmult(a,a);const i=a.dot(t);i<g&&(g=i,w=e)}if(w<0)return;const b=v.faces[w];b.connectedFaces=[];for(let t=0;t<v.faces.length;t++)for(let e=0;e<v.faces[t].length;e++)-1!==b.indexOf(v.faces[t][e])&&t!==w&&-1===b.connectedFaces.indexOf(t)&&b.connectedFaces.push(t);const _=b.length;for(let t=0;t<_;t++){const i=v.vertices[b[t]],r=v.vertices[b[(t+1)%_]];i.vsub(r,u),h.copy(u),n.vmult(h,h),e.vadd(h,h),l.copy(this.faceNormals[w]),n.vmult(l,l),e.vadd(l,l),h.cross(l,c),c.negate(c),f.copy(i),n.vmult(f,f),e.vadd(f,f);const s=b.connectedFaces[t];d.copy(this.faceNormals[s]);const o=this.getPlaneConstantOfFace(s);p.copy(d),n.vmult(p,p);const a=o-p.dot(e);for(this.clipFaceAgainstPlane(m,y,p,a);m.length;)m.shift();for(;y.length;)m.push(y.shift())}d.copy(this.faceNormals[w]);const x=this.getPlaneConstantOfFace(w);p.copy(d),n.vmult(p,p);const k=x-p.dot(e);for(let t=0;t<m.length;t++){let e=p.dot(m[t])+k;if(e<=r&&(e=r),e<=s){const n=m[t];if(e<=1e-6){const t={point:n,normal:p,depth:e};o.push(t)}}}}clipFaceAgainstPlane(t,e,n,i){let r,s;const o=t.length;if(o<2)return e;let a=t[t.length-1],u=t[0];r=n.dot(a)+i;for(let h=0;h<o;h++){if(u=t[h],s=n.dot(u)+i,r<0)if(s<0){const t=new Py;t.copy(u),e.push(t)}else{const t=new Py;a.lerp(u,r/(r-s),t),e.push(t)}else if(s<0){const t=new Py;a.lerp(u,r/(r-s),t),e.push(t),e.push(u)}a=u,r=s}return e}computeWorldVertices(t,e){for(;this.worldVertices.length<this.vertices.length;)this.worldVertices.push(new Py);const n=this.vertices,i=this.worldVertices;for(let r=0;r!==this.vertices.length;r++)e.vmult(n[r],i[r]),t.vadd(i[r],i[r]);this.worldVerticesNeedsUpdate=!1}computeLocalAABB(t,e){const n=this.vertices;t.set(Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE),e.set(-Number.MAX_VALUE,-Number.MAX_VALUE,-Number.MAX_VALUE);for(let i=0;i<this.vertices.length;i++){const r=n[i];r.x<t.x?t.x=r.x:r.x>e.x&&(e.x=r.x),r.y<t.y?t.y=r.y:r.y>e.y&&(e.y=r.y),r.z<t.z?t.z=r.z:r.z>e.z&&(e.z=r.z)}}computeWorldFaceNormals(t){const e=this.faceNormals.length;for(;this.worldFaceNormals.length<e;)this.worldFaceNormals.push(new Py);const n=this.faceNormals,i=this.worldFaceNormals;for(let r=0;r!==e;r++)t.vmult(n[r],i[r]);this.worldFaceNormalsNeedsUpdate=!1}updateBoundingSphereRadius(){let t=0;const e=this.vertices;for(let n=0;n!==e.length;n++){const i=e[n].lengthSquared();i>t&&(t=i)}this.boundingSphereRadius=Math.sqrt(t)}calculateWorldAABB(t,e,n,i){const r=this.vertices;let s,o,a,u,h,l,c=new Py;for(let n=0;n<r.length;n++){c.copy(r[n]),e.vmult(c,c),t.vadd(c,c);const i=c;(void 0===s||i.x<s)&&(s=i.x),(void 0===u||i.x>u)&&(u=i.x),(void 0===o||i.y<o)&&(o=i.y),(void 0===h||i.y>h)&&(h=i.y),(void 0===a||i.z<a)&&(a=i.z),(void 0===l||i.z>l)&&(l=i.z)}n.set(s,o,a),i.set(u,h,l)}volume(){return 4*Math.PI*this.boundingSphereRadius/3}getAveragePointLocal(t){void 0===t&&(t=new Py);const e=this.vertices;for(let n=0;n<e.length;n++)t.vadd(e[n],t);return t.scale(1/e.length,t),t}transformAllPoints(t,e){const n=this.vertices.length,i=this.vertices;if(e){for(let t=0;t<n;t++){const n=i[t];e.vmult(n,n)}for(let t=0;t<this.faceNormals.length;t++){const n=this.faceNormals[t];e.vmult(n,n)}}if(t)for(let e=0;e<n;e++){const n=i[e];n.vadd(t,n)}}pointIsInside(t){const e=this.vertices,n=this.faces,i=this.faceNormals,r=new Py;this.getAveragePointLocal(r);for(let s=0;s<this.faces.length;s++){let o=i[s];const a=e[n[s][0]],u=new Py;t.vsub(a,u);const h=o.dot(u),l=new Py;r.vsub(a,l);const c=o.dot(l);if(h<0&&c>0||h>0&&c<0)return!1}return-1}static project(t,e,n,i,r){const s=t.vertices.length,o=tw;let a=0,u=0;const h=ew,l=t.vertices;h.setZero(),Ky.vectorToLocalFrame(n,i,e,o),Ky.pointToLocalFrame(n,i,h,h);const c=h.dot(o);u=a=l[0].dot(o);for(let t=1;t<s;t++){const e=l[t].dot(o);e>a&&(a=e),e<u&&(u=e)}if(u-=c,a-=c,u>a){const t=u;u=a,a=t}r[0]=a,r[1]=u}}const Zy=[],Jy=[];new Py;const tw=new Py,ew=new Py;class nw extends Yy{constructor(t){super({type:Yy.types.BOX}),this.halfExtents=t,this.convexPolyhedronRepresentation=null,this.updateConvexPolyhedronRepresentation(),this.updateBoundingSphereRadius()}updateConvexPolyhedronRepresentation(){const t=this.halfExtents.x,e=this.halfExtents.y,n=this.halfExtents.z,i=Py,r=[new i(-t,-e,-n),new i(t,-e,-n),new i(t,e,-n),new i(-t,e,-n),new i(-t,-e,n),new i(t,-e,n),new i(t,e,n),new i(-t,e,n)],s=[new i(0,0,1),new i(0,1,0),new i(1,0,0)],o=new Qy({vertices:r,faces:[[3,2,1,0],[4,5,6,7],[5,4,0,1],[2,3,7,6],[0,4,7,3],[1,2,6,5]],axes:s});this.convexPolyhedronRepresentation=o,o.material=this.material}calculateLocalInertia(t,e){return void 0===e&&(e=new Py),nw.calculateInertia(this.halfExtents,t,e),e}static calculateInertia(t,e,n){const i=t;n.x=1/12*e*(4*i.y*i.y+4*i.z*i.z),n.y=1/12*e*(4*i.x*i.x+4*i.z*i.z),n.z=1/12*e*(4*i.y*i.y+4*i.x*i.x)}getSideNormals(t,e){const n=t,i=this.halfExtents;if(n[0].set(i.x,0,0),n[1].set(0,i.y,0),n[2].set(0,0,i.z),n[3].set(-i.x,0,0),n[4].set(0,-i.y,0),n[5].set(0,0,-i.z),void 0!==e)for(let t=0;t!==n.length;t++)e.vmult(n[t],n[t]);return n}volume(){return 8*this.halfExtents.x*this.halfExtents.y*this.halfExtents.z}updateBoundingSphereRadius(){this.boundingSphereRadius=this.halfExtents.length()}forEachWorldCorner(t,e,n){const i=this.halfExtents,r=[[i.x,i.y,i.z],[-i.x,i.y,i.z],[-i.x,-i.y,i.z],[-i.x,-i.y,-i.z],[i.x,-i.y,-i.z],[i.x,i.y,-i.z],[-i.x,i.y,-i.z],[i.x,-i.y,i.z]];for(let i=0;i<r.length;i++)iw.set(r[i][0],r[i][1],r[i][2]),e.vmult(iw,iw),t.vadd(iw,iw),n(iw.x,iw.y,iw.z)}calculateWorldAABB(t,e,n,i){const r=this.halfExtents;rw[0].set(r.x,r.y,r.z),rw[1].set(-r.x,r.y,r.z),rw[2].set(-r.x,-r.y,r.z),rw[3].set(-r.x,-r.y,-r.z),rw[4].set(r.x,-r.y,-r.z),rw[5].set(r.x,r.y,-r.z),rw[6].set(-r.x,r.y,-r.z),rw[7].set(r.x,-r.y,r.z);const s=rw[0];e.vmult(s,s),t.vadd(s,s),i.copy(s),n.copy(s);for(let r=1;r<8;r++){const s=rw[r];e.vmult(s,s),t.vadd(s,s);const o=s.x,a=s.y,u=s.z;o>i.x&&(i.x=o),a>i.y&&(i.y=a),u>i.z&&(i.z=u),o<n.x&&(n.x=o),a<n.y&&(n.y=a),u<n.z&&(n.z=u)}}}const iw=new Py,rw=[new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py];class sw extends Hy{constructor(t){void 0===t&&(t={}),super(),this.id=sw.idCounter++,this.index=-1,this.world=null,this.vlambda=new Py,this.collisionFilterGroup="number"==typeof t.collisionFilterGroup?t.collisionFilterGroup:1,this.collisionFilterMask="number"==typeof t.collisionFilterMask?t.collisionFilterMask:-1,this.collisionResponse="boolean"!=typeof t.collisionResponse||t.collisionResponse,this.position=new Py,this.previousPosition=new Py,this.interpolatedPosition=new Py,this.initPosition=new Py,t.position&&(this.position.copy(t.position),this.previousPosition.copy(t.position),this.interpolatedPosition.copy(t.position),this.initPosition.copy(t.position)),this.velocity=new Py,t.velocity&&this.velocity.copy(t.velocity),this.initVelocity=new Py,this.force=new Py;const e="number"==typeof t.mass?t.mass:0;this.mass=e,this.invMass=e>0?1/e:0,this.material=t.material||null,this.linearDamping="number"==typeof t.linearDamping?t.linearDamping:.01,this.type=e<=0?sw.STATIC:sw.DYNAMIC,typeof t.type==typeof sw.STATIC&&(this.type=t.type),this.allowSleep=void 0===t.allowSleep||t.allowSleep,this.sleepState=sw.AWAKE,this.sleepSpeedLimit=void 0!==t.sleepSpeedLimit?t.sleepSpeedLimit:.1,this.sleepTimeLimit=void 0!==t.sleepTimeLimit?t.sleepTimeLimit:1,this.timeLastSleepy=0,this.wakeUpAfterNarrowphase=!1,this.torque=new Py,this.quaternion=new Wy,this.initQuaternion=new Wy,this.previousQuaternion=new Wy,this.interpolatedQuaternion=new Wy,t.quaternion&&(this.quaternion.copy(t.quaternion),this.initQuaternion.copy(t.quaternion),this.previousQuaternion.copy(t.quaternion),this.interpolatedQuaternion.copy(t.quaternion)),this.angularVelocity=new Py,t.angularVelocity&&this.angularVelocity.copy(t.angularVelocity),this.initAngularVelocity=new Py,this.shapes=[],this.shapeOffsets=[],this.shapeOrientations=[],this.inertia=new Py,this.invInertia=new Py,this.invInertiaWorld=new Ry,this.invMassSolve=0,this.invInertiaSolve=new Py,this.invInertiaWorldSolve=new Ry,this.fixedRotation=void 0!==t.fixedRotation&&t.fixedRotation,this.angularDamping=void 0!==t.angularDamping?t.angularDamping:.01,this.linearFactor=new Py(1,1,1),t.linearFactor&&this.linearFactor.copy(t.linearFactor),this.angularFactor=new Py(1,1,1),t.angularFactor&&this.angularFactor.copy(t.angularFactor),this.aabb=new qy,this.aabbNeedsUpdate=!0,this.boundingRadius=0,this.wlambda=new Py,this.isTrigger=Boolean(t.isTrigger),t.shape&&this.addShape(t.shape),this.updateMassProperties()}wakeUp(){const t=this.sleepState;this.sleepState=sw.AWAKE,this.wakeUpAfterNarrowphase=!1,t===sw.SLEEPING&&this.dispatchEvent(sw.wakeupEvent)}sleep(){this.sleepState=sw.SLEEPING,this.velocity.set(0,0,0),this.angularVelocity.set(0,0,0),this.wakeUpAfterNarrowphase=!1}sleepTick(t){if(this.allowSleep){const e=this.sleepState,n=this.velocity.lengthSquared()+this.angularVelocity.lengthSquared(),i=this.sleepSpeedLimit**2;e===sw.AWAKE&&n<i?(this.sleepState=sw.SLEEPY,this.timeLastSleepy=t,this.dispatchEvent(sw.sleepyEvent)):e===sw.SLEEPY&&n>i?this.wakeUp():e===sw.SLEEPY&&t-this.timeLastSleepy>this.sleepTimeLimit&&(this.sleep(),this.dispatchEvent(sw.sleepEvent))}}updateSolveMassProperties(){this.sleepState===sw.SLEEPING||this.type===sw.KINEMATIC?(this.invMassSolve=0,this.invInertiaSolve.setZero(),this.invInertiaWorldSolve.setZero()):(this.invMassSolve=this.invMass,this.invInertiaSolve.copy(this.invInertia),this.invInertiaWorldSolve.copy(this.invInertiaWorld))}pointToLocalFrame(t,e){return void 0===e&&(e=new Py),t.vsub(this.position,e),this.quaternion.conjugate().vmult(e,e),e}vectorToLocalFrame(t,e){return void 0===e&&(e=new Py),this.quaternion.conjugate().vmult(t,e),e}pointToWorldFrame(t,e){return void 0===e&&(e=new Py),this.quaternion.vmult(t,e),e.vadd(this.position,e),e}vectorToWorldFrame(t,e){return void 0===e&&(e=new Py),this.quaternion.vmult(t,e),e}addShape(t,e,n){const i=new Py,r=new Wy;return e&&i.copy(e),n&&r.copy(n),this.shapes.push(t),this.shapeOffsets.push(i),this.shapeOrientations.push(r),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=this,this}removeShape(t){const e=this.shapes.indexOf(t);return-1===e||(this.shapes.splice(e,1),this.shapeOffsets.splice(e,1),this.shapeOrientations.splice(e,1),this.updateMassProperties(),this.updateBoundingRadius(),this.aabbNeedsUpdate=!0,t.body=null),this}updateBoundingRadius(){const t=this.shapes,e=this.shapeOffsets,n=t.length;let i=0;for(let r=0;r!==n;r++){const n=t[r];n.updateBoundingSphereRadius();const s=e[r].length(),o=n.boundingSphereRadius;s+o>i&&(i=s+o)}this.boundingRadius=i}updateAABB(){const t=this.shapes,e=this.shapeOffsets,n=this.shapeOrientations,i=t.length,r=ow,s=aw,o=this.quaternion,a=this.aabb,u=uw;for(let h=0;h!==i;h++){const i=t[h];o.vmult(e[h],r),r.vadd(this.position,r),o.mult(n[h],s),i.calculateWorldAABB(r,s,u.lowerBound,u.upperBound),0===h?a.copy(u):a.extend(u)}this.aabbNeedsUpdate=!1}updateInertiaWorld(t){const e=this.invInertia;if(e.x!==e.y||e.y!==e.z||t){const t=hw,n=lw;t.setRotationFromQuaternion(this.quaternion),t.transpose(n),t.scale(e,t),t.mmult(n,this.invInertiaWorld)}}applyForce(t,e){if(void 0===e&&(e=new Py),this.type!==sw.DYNAMIC)return;this.sleepState===sw.SLEEPING&&this.wakeUp();const n=cw;e.cross(t,n),this.force.vadd(t,this.force),this.torque.vadd(n,this.torque)}applyLocalForce(t,e){if(void 0===e&&(e=new Py),this.type!==sw.DYNAMIC)return;const n=fw,i=dw;this.vectorToWorldFrame(t,n),this.vectorToWorldFrame(e,i),this.applyForce(n,i)}applyTorque(t){this.type===sw.DYNAMIC&&(this.sleepState===sw.SLEEPING&&this.wakeUp(),this.torque.vadd(t,this.torque))}applyImpulse(t,e){if(void 0===e&&(e=new Py),this.type!==sw.DYNAMIC)return;this.sleepState===sw.SLEEPING&&this.wakeUp();const n=e,i=pw;i.copy(t),i.scale(this.invMass,i),this.velocity.vadd(i,this.velocity);const r=vw;n.cross(t,r),this.invInertiaWorld.vmult(r,r),this.angularVelocity.vadd(r,this.angularVelocity)}applyLocalImpulse(t,e){if(void 0===e&&(e=new Py),this.type!==sw.DYNAMIC)return;const n=mw,i=yw;this.vectorToWorldFrame(t,n),this.vectorToWorldFrame(e,i),this.applyImpulse(n,i)}updateMassProperties(){const t=ww;this.invMass=this.mass>0?1/this.mass:0;const e=this.inertia,n=this.fixedRotation;this.updateAABB(),t.set((this.aabb.upperBound.x-this.aabb.lowerBound.x)/2,(this.aabb.upperBound.y-this.aabb.lowerBound.y)/2,(this.aabb.upperBound.z-this.aabb.lowerBound.z)/2),nw.calculateInertia(t,this.mass,e),this.invInertia.set(e.x>0&&!n?1/e.x:0,e.y>0&&!n?1/e.y:0,e.z>0&&!n?1/e.z:0),this.updateInertiaWorld(!0)}getVelocityAtWorldPoint(t,e){const n=new Py;return t.vsub(this.position,n),this.angularVelocity.cross(n,e),this.velocity.vadd(e,e),e}integrate(t,e,n){if(this.previousPosition.copy(this.position),this.previousQuaternion.copy(this.quaternion),this.type!==sw.DYNAMIC&&this.type!==sw.KINEMATIC||this.sleepState===sw.SLEEPING)return;const i=this.velocity,r=this.angularVelocity,s=this.position,o=this.force,a=this.torque,u=this.quaternion,h=this.invMass,l=this.invInertiaWorld,c=this.linearFactor,f=h*t;i.x+=o.x*f*c.x,i.y+=o.y*f*c.y,i.z+=o.z*f*c.z;const d=l.elements,p=this.angularFactor,v=a.x*p.x,m=a.y*p.y,y=a.z*p.z;r.x+=t*(d[0]*v+d[1]*m+d[2]*y),r.y+=t*(d[3]*v+d[4]*m+d[5]*y),r.z+=t*(d[6]*v+d[7]*m+d[8]*y),s.x+=i.x*t,s.y+=i.y*t,s.z+=i.z*t,u.integrate(this.angularVelocity,t,this.angularFactor,u),e&&(n?u.normalizeFast():u.normalize()),this.aabbNeedsUpdate=!0,this.updateInertiaWorld()}}sw.idCounter=0,sw.COLLIDE_EVENT_NAME="collide",sw.DYNAMIC=1,sw.STATIC=2,sw.KINEMATIC=4,sw.AWAKE=0,sw.SLEEPY=1,sw.SLEEPING=2,sw.wakeupEvent={type:"wakeup"},sw.sleepyEvent={type:"sleepy"},sw.sleepEvent={type:"sleep"};const ow=new Py,aw=new Wy,uw=new qy,hw=new Ry,lw=new Ry,cw=(new Ry,new Py),fw=new Py,dw=new Py,pw=new Py,vw=new Py,mw=new Py,yw=new Py,ww=new Py;class gw{constructor(){this.world=null,this.useBoundingBoxes=!1,this.dirty=!0}collisionPairs(t,e,n){throw new Error("collisionPairs not implemented for this BroadPhase class!")}needBroadphaseCollision(t,e){return!(!(t.collisionFilterGroup&e.collisionFilterMask&&e.collisionFilterGroup&t.collisionFilterMask)||(t.type&sw.STATIC||t.sleepState===sw.SLEEPING)&&(e.type&sw.STATIC||e.sleepState===sw.SLEEPING))}intersectionTest(t,e,n,i){this.useBoundingBoxes?this.doBoundingBoxBroadphase(t,e,n,i):this.doBoundingSphereBroadphase(t,e,n,i)}doBoundingSphereBroadphase(t,e,n,i){const r=bw;e.position.vsub(t.position,r);const s=(t.boundingRadius+e.boundingRadius)**2;r.lengthSquared()<s&&(n.push(t),i.push(e))}doBoundingBoxBroadphase(t,e,n,i){t.aabbNeedsUpdate&&t.updateAABB(),e.aabbNeedsUpdate&&e.updateAABB(),t.aabb.overlaps(e.aabb)&&(n.push(t),i.push(e))}makePairsUnique(t,e){const n=_w,i=xw,r=kw,s=t.length;for(let n=0;n!==s;n++)i[n]=t[n],r[n]=e[n];t.length=0,e.length=0;for(let t=0;t!==s;t++){const e=i[t].id,s=r[t].id,o=e<s?`${e},${s}`:`${s},${e}`;n[o]=t,n.keys.push(o)}for(let s=0;s!==n.keys.length;s++){const s=n.keys.pop(),o=n[s];t.push(i[o]),e.push(r[o]),delete n[s]}}setWorld(t){}static boundingSphereCheck(t,e){const n=new Py;t.position.vsub(e.position,n);const i=t.shapes[0],r=e.shapes[0];return Math.pow(i.boundingSphereRadius+r.boundingSphereRadius,2)>n.lengthSquared()}aabbQuery(t,e,n){return[]}}const bw=new Py;new Py,new Wy,new Py;const _w={keys:[]},xw=[],kw=[];new Py,new Py,new Py;class $w extends gw{constructor(){super()}collisionPairs(t,e,n){const i=t.bodies,r=i.length;let s,o;for(let t=0;t!==r;t++)for(let r=0;r!==t;r++)s=i[t],o=i[r],this.needBroadphaseCollision(s,o)&&this.intersectionTest(s,o,e,n)}aabbQuery(t,e,n){void 0===n&&(n=[]);for(let i=0;i<t.bodies.length;i++){const r=t.bodies[i];r.aabbNeedsUpdate&&r.updateAABB(),r.aabb.overlaps(e)&&n.push(r)}return n}}class Sw{constructor(){this.rayFromWorld=new Py,this.rayToWorld=new Py,this.hitNormalWorld=new Py,this.hitPointWorld=new Py,this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}reset(){this.rayFromWorld.setZero(),this.rayToWorld.setZero(),this.hitNormalWorld.setZero(),this.hitPointWorld.setZero(),this.hasHit=!1,this.shape=null,this.body=null,this.hitFaceIndex=-1,this.distance=-1,this.shouldStop=!1}abort(){this.shouldStop=!0}set(t,e,n,i,r,s,o){this.rayFromWorld.copy(t),this.rayToWorld.copy(e),this.hitNormalWorld.copy(n),this.hitPointWorld.copy(i),this.shape=r,this.body=s,this.distance=o}}let Mw,Ew,Cw,Aw,Ow,Iw,Tw;Mw=Yy.types.SPHERE,Ew=Yy.types.PLANE,Cw=Yy.types.BOX,Aw=Yy.types.CYLINDER,Ow=Yy.types.CONVEXPOLYHEDRON,Iw=Yy.types.HEIGHTFIELD,Tw=Yy.types.TRIMESH;class zw{get[Mw](){return this.zp}get[Ew](){return this.Rp}get[Cw](){return this.Fp}get[Aw](){return this.Pp}get[Ow](){return this.Pp}get[Iw](){return this.Dp}get[Tw](){return this.Np}constructor(t,e){void 0===t&&(t=new Py),void 0===e&&(e=new Py),this.from=t.clone(),this.to=e.clone(),this.direction=new Py,this.precision=1e-4,this.checkCollisionResponse=!0,this.skipBackfaces=!1,this.collisionFilterMask=-1,this.collisionFilterGroup=-1,this.mode=zw.ANY,this.result=new Sw,this.hasHit=!1,this.callback=t=>{}}intersectWorld(t,e){return this.mode=e.mode||zw.ANY,this.result=e.result||new Sw,this.skipBackfaces=!!e.skipBackfaces,this.collisionFilterMask=void 0!==e.collisionFilterMask?e.collisionFilterMask:-1,this.collisionFilterGroup=void 0!==e.collisionFilterGroup?e.collisionFilterGroup:-1,this.checkCollisionResponse=void 0===e.checkCollisionResponse||e.checkCollisionResponse,e.from&&this.from.copy(e.from),e.to&&this.to.copy(e.to),this.callback=e.callback||(()=>{}),this.hasHit=!1,this.result.reset(),this.updateDirection(),this.getAABB(Rw),Fw.length=0,t.broadphase.aabbQuery(t,Rw,Fw),this.intersectBodies(Fw),this.hasHit}intersectBody(t,e){e&&(this.result=e,this.updateDirection());const n=this.checkCollisionResponse;if(n&&!t.collisionResponse)return;if(!(this.collisionFilterGroup&t.collisionFilterMask&&t.collisionFilterGroup&this.collisionFilterMask))return;const i=Nw,r=Uw;for(let e=0,s=t.shapes.length;e<s;e++){const s=t.shapes[e];if((!n||s.collisionResponse)&&(t.quaternion.mult(t.shapeOrientations[e],r),t.quaternion.vmult(t.shapeOffsets[e],i),i.vadd(t.position,i),this.intersectShape(s,r,i,t),this.result.shouldStop))break}}intersectBodies(t,e){e&&(this.result=e,this.updateDirection());for(let e=0,n=t.length;!this.result.shouldStop&&e<n;e++)this.intersectBody(t[e])}updateDirection(){this.to.vsub(this.from,this.direction),this.direction.normalize()}intersectShape(t,e,n,i){const r=function(t,e,n){n.vsub(t,og);const i=og.dot(e);return e.scale(i,ag),ag.vadd(t,ag),n.distanceTo(ag)}(this.from,this.direction,n);if(r>t.boundingSphereRadius)return;const s=this[t.type];s&&s.call(this,t,e,n,i,t)}Fp(t,e,n,i,r){return this.Pp(t.convexPolyhedronRepresentation,e,n,i,r)}Rp(t,e,n,i,r){const s=this.from,o=this.to,a=this.direction,u=new Py(0,0,1);e.vmult(u,u);const h=new Py;s.vsub(n,h);const l=h.dot(u);if(o.vsub(n,h),l*h.dot(u)>0)return;if(s.distanceTo(o)<l)return;const c=u.dot(a);if(Math.abs(c)<this.precision)return;const f=new Py,d=new Py,p=new Py;s.vsub(n,f);const v=-u.dot(f)/c;a.scale(v,d),s.vadd(d,p),this.reportIntersection(u,p,r,i,-1)}getAABB(t){const{lowerBound:e,upperBound:n}=t,i=this.to,r=this.from;e.x=Math.min(i.x,r.x),e.y=Math.min(i.y,r.y),e.z=Math.min(i.z,r.z),n.x=Math.max(i.x,r.x),n.y=Math.max(i.y,r.y),n.z=Math.max(i.z,r.z)}Dp(t,e,n,i,r){t.data,t.elementSize;const s=Vw;s.from.copy(this.from),s.to.copy(this.to),Ky.pointToLocalFrame(n,e,s.from,s.from),Ky.pointToLocalFrame(n,e,s.to,s.to),s.updateDirection();const o=Gw;let a,u,h,l;a=u=0,h=l=t.data.length-1;const c=new qy;s.getAABB(c),t.getIndexOfPosition(c.lowerBound.x,c.lowerBound.y,o,!0),a=Math.max(a,o[0]),u=Math.max(u,o[1]),t.getIndexOfPosition(c.upperBound.x,c.upperBound.y,o,!0),h=Math.min(h,o[0]+1),l=Math.min(l,o[1]+1);for(let o=a;o<h;o++)for(let a=u;a<l;a++){if(this.result.shouldStop)return;if(t.getAabbAtIndex(o,a,c),c.overlapsRay(s)){if(t.getConvexTrianglePillar(o,a,!1),Ky.pointToWorldFrame(n,e,t.pillarOffset,Ww),this.Pp(t.pillarConvex,e,Ww,i,r,Hw),this.result.shouldStop)return;t.getConvexTrianglePillar(o,a,!0),Ky.pointToWorldFrame(n,e,t.pillarOffset,Ww),this.Pp(t.pillarConvex,e,Ww,i,r,Hw)}}}zp(t,e,n,i,r){const s=this.from,o=this.to,a=t.radius,u=(o.x-s.x)**2+(o.y-s.y)**2+(o.z-s.z)**2,h=2*((o.x-s.x)*(s.x-n.x)+(o.y-s.y)*(s.y-n.y)+(o.z-s.z)*(s.z-n.z)),l=h**2-4*u*((s.x-n.x)**2+(s.y-n.y)**2+(s.z-n.z)**2-a**2),c=Yw,f=Kw;if(!(l<0))if(0===l)s.lerp(o,l,c),c.vsub(n,f),f.normalize(),this.reportIntersection(f,c,r,i,-1);else{const t=(-h-Math.sqrt(l))/(2*u),e=(-h+Math.sqrt(l))/(2*u);if(t>=0&&t<=1&&(s.lerp(o,t,c),c.vsub(n,f),f.normalize(),this.reportIntersection(f,c,r,i,-1)),this.result.shouldStop)return;e>=0&&e<=1&&(s.lerp(o,e,c),c.vsub(n,f),f.normalize(),this.reportIntersection(f,c,r,i,-1))}}Pp(t,e,n,i,r,s){const o=Xw,a=Qw,u=s&&s.faceList||null,h=t.faces,l=t.vertices,c=t.faceNormals,f=this.direction,d=this.from,p=this.to,v=d.distanceTo(p),m=u?u.length:h.length,y=this.result;for(let t=0;!y.shouldStop&&t<m;t++){const s=u?u[t]:t,p=h[s],m=c[s],w=e,g=n;a.copy(l[p[0]]),w.vmult(a,a),a.vadd(g,a),a.vsub(d,a),w.vmult(m,o);const b=f.dot(o);if(Math.abs(b)<this.precision)continue;const _=o.dot(a)/b;if(!(_<0)){f.scale(_,qw),qw.vadd(d,qw),jw.copy(l[p[0]]),w.vmult(jw,jw),g.vadd(jw,jw);for(let t=1;!y.shouldStop&&t<p.length-1;t++){Bw.copy(l[p[t]]),Lw.copy(l[p[t+1]]),w.vmult(Bw,Bw),w.vmult(Lw,Lw),g.vadd(Bw,Bw),g.vadd(Lw,Lw);const e=qw.distanceTo(d);!zw.pointInTriangle(qw,jw,Bw,Lw)&&!zw.pointInTriangle(qw,Bw,jw,Lw)||e>v||this.reportIntersection(o,qw,r,i,s)}}}}Np(t,e,n,i,r,s){const o=Zw,a=rg,u=sg,h=Qw,l=Jw,c=tg,f=eg,d=ig,p=ng,v=t.indices;t.vertices;const m=this.from,y=this.to,w=this.direction;u.position.copy(n),u.quaternion.copy(e),Ky.vectorToLocalFrame(n,e,w,l),Ky.pointToLocalFrame(n,e,m,c),Ky.pointToLocalFrame(n,e,y,f),f.x*=t.scale.x,f.y*=t.scale.y,f.z*=t.scale.z,c.x*=t.scale.x,c.y*=t.scale.y,c.z*=t.scale.z,f.vsub(c,l),l.normalize();const g=c.distanceSquared(f);t.tree.rayQuery(this,u,a);for(let s=0,u=a.length;!this.result.shouldStop&&s!==u;s++){const u=a[s];t.getNormal(u,o),t.getVertex(v[3*u],jw),jw.vsub(c,h);const f=l.dot(o),m=o.dot(h)/f;if(m<0)continue;l.scale(m,qw),qw.vadd(c,qw),t.getVertex(v[3*u+1],Bw),t.getVertex(v[3*u+2],Lw);const y=qw.distanceSquared(c);!zw.pointInTriangle(qw,Bw,jw,Lw)&&!zw.pointInTriangle(qw,jw,Bw,Lw)||y>g||(Ky.vectorToWorldFrame(e,o,p),Ky.pointToWorldFrame(n,e,qw,d),this.reportIntersection(p,d,r,i,u))}a.length=0}reportIntersection(t,e,n,i,r){const s=this.from,o=this.to,a=s.distanceTo(e),u=this.result;if(!(this.skipBackfaces&&t.dot(this.direction)>0))switch(u.hitFaceIndex=void 0!==r?r:-1,this.mode){case zw.ALL:this.hasHit=!0,u.set(s,o,t,e,n,i,a),u.hasHit=!0,this.callback(u);break;case zw.CLOSEST:(a<u.distance||!u.hasHit)&&(this.hasHit=!0,u.hasHit=!0,u.set(s,o,t,e,n,i,a));break;case zw.ANY:this.hasHit=!0,u.hasHit=!0,u.set(s,o,t,e,n,i,a),u.shouldStop=!0}}static pointInTriangle(t,e,n,i){i.vsub(e,og),n.vsub(e,Pw),t.vsub(e,Dw);const r=og.dot(og),s=og.dot(Pw),o=og.dot(Dw),a=Pw.dot(Pw),u=Pw.dot(Dw);let h,l;return(h=a*o-s*u)>=0&&(l=r*u-s*o)>=0&&h+l<r*a-s*s}}zw.CLOSEST=1,zw.ANY=2,zw.ALL=4;const Rw=new qy,Fw=[],Pw=new Py,Dw=new Py,Nw=new Py,Uw=new Wy,qw=new Py,jw=new Py,Bw=new Py,Lw=new Py;new Py,new Sw;const Hw={faceList:[0]},Ww=new Py,Vw=new zw,Gw=[],Yw=new Py,Kw=new Py,Xw=new Py;new Py,new Py;const Qw=new Py,Zw=new Py,Jw=new Py,tg=new Py,eg=new Py,ng=new Py,ig=new Py;new qy;const rg=[],sg=new Ky,og=new Py,ag=new Py;class ug{static defaults(t,e){void 0===t&&(t={});for(let n in e)n in t||(t[n]=e[n]);return t}}class hg{constructor(){this.spatial=new Py,this.rotational=new Py}multiplyElement(t){return t.spatial.dot(this.spatial)+t.rotational.dot(this.rotational)}multiplyVectors(t,e){return t.dot(this.spatial)+e.dot(this.rotational)}}class lg{constructor(t,e,n,i){void 0===n&&(n=-1e6),void 0===i&&(i=1e6),this.id=lg.idCounter++,this.minForce=n,this.maxForce=i,this.bi=t,this.bj=e,this.a=0,this.b=0,this.eps=0,this.jacobianElementA=new hg,this.jacobianElementB=new hg,this.enabled=!0,this.multiplier=0,this.setSpookParams(1e7,4,1/60)}setSpookParams(t,e,n){const i=e,r=t,s=n;this.a=4/(s*(1+4*i)),this.b=4*i/(1+4*i),this.eps=4/(s*s*r*(1+4*i))}computeB(t,e,n){const i=this.computeGW();return-this.computeGq()*t-i*e-this.computeGiMf()*n}computeGq(){const t=this.jacobianElementA,e=this.jacobianElementB,n=this.bi,i=this.bj,r=n.position,s=i.position;return t.spatial.dot(r)+e.spatial.dot(s)}computeGW(){const t=this.jacobianElementA,e=this.jacobianElementB,n=this.bi,i=this.bj,r=n.velocity,s=i.velocity,o=n.angularVelocity,a=i.angularVelocity;return t.multiplyVectors(r,o)+e.multiplyVectors(s,a)}computeGWlambda(){const t=this.jacobianElementA,e=this.jacobianElementB,n=this.bi,i=this.bj,r=n.vlambda,s=i.vlambda,o=n.wlambda,a=i.wlambda;return t.multiplyVectors(r,o)+e.multiplyVectors(s,a)}computeGiMf(){const t=this.jacobianElementA,e=this.jacobianElementB,n=this.bi,i=this.bj,r=n.force,s=n.torque,o=i.force,a=i.torque,u=n.invMassSolve,h=i.invMassSolve;return r.scale(u,cg),o.scale(h,fg),n.invInertiaWorldSolve.vmult(s,dg),i.invInertiaWorldSolve.vmult(a,pg),t.multiplyVectors(cg,dg)+e.multiplyVectors(fg,pg)}computeGiMGt(){const t=this.jacobianElementA,e=this.jacobianElementB,n=this.bi,i=this.bj,r=n.invMassSolve,s=i.invMassSolve,o=n.invInertiaWorldSolve,a=i.invInertiaWorldSolve;let u=r+s;return o.vmult(t.rotational,vg),u+=vg.dot(t.rotational),a.vmult(e.rotational,vg),u+=vg.dot(e.rotational),u}addToWlambda(t){const e=this.jacobianElementA,n=this.jacobianElementB,i=this.bi,r=this.bj,s=mg;i.vlambda.addScaledVector(i.invMassSolve*t,e.spatial,i.vlambda),r.vlambda.addScaledVector(r.invMassSolve*t,n.spatial,r.vlambda),i.invInertiaWorldSolve.vmult(e.rotational,s),i.wlambda.addScaledVector(t,s,i.wlambda),r.invInertiaWorldSolve.vmult(n.rotational,s),r.wlambda.addScaledVector(t,s,r.wlambda)}computeC(){return this.computeGiMGt()+this.eps}}lg.idCounter=0;const cg=new Py,fg=new Py,dg=new Py,pg=new Py,vg=new Py,mg=new Py;class yg extends lg{constructor(t,e,n){void 0===n&&(n=1e6),super(t,e,0,n),this.restitution=0,this.ri=new Py,this.rj=new Py,this.ni=new Py}computeB(t){const e=this.a,n=this.b,i=this.bi,r=this.bj,s=this.ri,o=this.rj,a=wg,u=gg,h=i.velocity,l=i.angularVelocity;i.force,i.torque;const c=r.velocity,f=r.angularVelocity;r.force,r.torque;const d=bg,p=this.jacobianElementA,v=this.jacobianElementB,m=this.ni;s.cross(m,a),o.cross(m,u),m.negate(p.spatial),a.negate(p.rotational),v.spatial.copy(m),v.rotational.copy(u),d.copy(r.position),d.vadd(o,d),d.vsub(i.position,d),d.vsub(s,d);const y=m.dot(d),w=this.restitution+1;return-y*e-(w*c.dot(m)-w*h.dot(m)+f.dot(u)-l.dot(a))*n-t*this.computeGiMf()}getImpactVelocityAlongNormal(){const t=_g,e=xg,n=kg,i=$g,r=Sg;return this.bi.position.vadd(this.ri,n),this.bj.position.vadd(this.rj,i),this.bi.getVelocityAtWorldPoint(n,t),this.bj.getVelocityAtWorldPoint(i,e),t.vsub(e,r),this.ni.dot(r)}}const wg=new Py,gg=new Py,bg=new Py,_g=new Py,xg=new Py,kg=new Py,$g=new Py,Sg=new Py;new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py;class Mg extends lg{constructor(t,e,n){super(t,e,-n,n),this.ri=new Py,this.rj=new Py,this.t=new Py}computeB(t){this.a;const e=this.b;this.bi,this.bj;const n=this.ri,i=this.rj,r=Eg,s=Cg,o=this.t;n.cross(o,r),i.cross(o,s);const a=this.jacobianElementA,u=this.jacobianElementB;return o.negate(a.spatial),r.negate(a.rotational),u.spatial.copy(o),u.rotational.copy(s),-this.computeGW()*e-t*this.computeGiMf()}}const Eg=new Py,Cg=new Py;class Ag{constructor(t,e,n){n=ug.defaults(n,{friction:.3,restitution:.3,contactEquationStiffness:1e7,contactEquationRelaxation:3,frictionEquationStiffness:1e7,frictionEquationRelaxation:3}),this.id=Ag.idCounter++,this.materials=[t,e],this.friction=n.friction,this.restitution=n.restitution,this.contactEquationStiffness=n.contactEquationStiffness,this.contactEquationRelaxation=n.contactEquationRelaxation,this.frictionEquationStiffness=n.frictionEquationStiffness,this.frictionEquationRelaxation=n.frictionEquationRelaxation}}Ag.idCounter=0;class Og{constructor(t){void 0===t&&(t={});let e="";"string"==typeof t&&(e=t,t={}),this.name=e,this.id=Og.idCounter++,this.friction=void 0!==t.friction?t.friction:-1,this.restitution=void 0!==t.restitution?t.restitution:-1}}Og.idCounter=0,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new zw,new Py,new Py,new Py,new Py(1,0,0),new Py(0,1,0),new Py(0,0,1),new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py,new Py;class Ig{constructor(t){void 0===t&&(t={}),this.root=t.root||null,this.aabb=t.aabb?t.aabb.clone():new qy,this.data=[],this.children=[]}reset(){this.children.length=this.data.length=0}insert(t,e,n){void 0===n&&(n=0);const i=this.data;if(!this.aabb.contains(t))return!1;const r=this.children;if(n<(this.maxDepth||this.root.maxDepth)){let i=!1;r.length||(this.subdivide(),i=!0);for(let i=0;8!==i;i++)if(r[i].insert(t,e,n+1))return!0;i&&(r.length=0)}return i.push(e),!0}subdivide(){const t=this.aabb,e=t.lowerBound,n=t.upperBound,i=this.children;i.push(new Ig({aabb:new qy({lowerBound:new Py(0,0,0)})}),new Ig({aabb:new qy({lowerBound:new Py(1,0,0)})}),new Ig({aabb:new qy({lowerBound:new Py(1,1,0)})}),new Ig({aabb:new qy({lowerBound:new Py(1,1,1)})}),new Ig({aabb:new qy({lowerBound:new Py(0,1,1)})}),new Ig({aabb:new qy({lowerBound:new Py(0,0,1)})}),new Ig({aabb:new qy({lowerBound:new Py(1,0,1)})}),new Ig({aabb:new qy({lowerBound:new Py(0,1,0)})})),n.vsub(e,zg),zg.scale(.5,zg);const r=this.root||this;for(let t=0;8!==t;t++){const n=i[t];n.root=r;const s=n.aabb.lowerBound;s.x*=zg.x,s.y*=zg.y,s.z*=zg.z,s.vadd(e,s),s.vadd(zg,n.aabb.upperBound)}}aabbQuery(t,e){this.data,this.children;const n=[this];for(;n.length;){const i=n.pop();i.aabb.overlaps(t)&&[].push.apply(e,i.data),[].push.apply(n,i.children)}return e}rayQuery(t,e,n){return t.getAABB(Rg),Rg.toLocalFrame(e,Rg),this.aabbQuery(Rg,n),n}removeEmptyNodes(){for(let t=this.children.length-1;t>=0;t--)this.children[t].removeEmptyNodes(),this.children[t].children.length||this.children[t].data.length||this.children.splice(t,1)}}class Tg extends Ig{constructor(t,e){void 0===e&&(e={}),super({root:null,aabb:t}),this.maxDepth=void 0!==e.maxDepth?e.maxDepth:8}}const zg=new Py,Rg=new qy;class Fg extends Yy{constructor(t,e){super({type:Yy.types.TRIMESH}),this.vertices=new Float32Array(t),this.indices=new Int16Array(e),this.normals=new Float32Array(e.length),this.aabb=new qy,this.edges=null,this.scale=new Py(1,1,1),this.tree=new Tg,this.updateEdges(),this.updateNormals(),this.updateAABB(),this.updateBoundingSphereRadius(),this.updateTree()}updateTree(){const t=this.tree;t.reset(),t.aabb.copy(this.aabb);const e=this.scale;t.aabb.lowerBound.x*=1/e.x,t.aabb.lowerBound.y*=1/e.y,t.aabb.lowerBound.z*=1/e.z,t.aabb.upperBound.x*=1/e.x,t.aabb.upperBound.y*=1/e.y,t.aabb.upperBound.z*=1/e.z;const n=new qy,i=new Py,r=new Py,s=new Py,o=[i,r,s];for(let e=0;e<this.indices.length/3;e++){const a=3*e;this.Up(this.indices[a],i),this.Up(this.indices[a+1],r),this.Up(this.indices[a+2],s),n.setFromPoints(o),t.insert(n,e)}t.removeEmptyNodes()}getTrianglesInAABB(t,e){Dg.copy(t);const n=this.scale,i=n.x,r=n.y,s=n.z,o=Dg.lowerBound,a=Dg.upperBound;return o.x/=i,o.y/=r,o.z/=s,a.x/=i,a.y/=r,a.z/=s,this.tree.aabbQuery(Dg,e)}setScale(t){const e=this.scale.x===this.scale.y&&this.scale.y===this.scale.z,n=t.x===t.y&&t.y===t.z;e&&n||this.updateNormals(),this.scale.copy(t),this.updateAABB(),this.updateBoundingSphereRadius()}updateNormals(){const t=Pg,e=this.normals;for(let n=0;n<this.indices.length/3;n++){const i=3*n,r=this.indices[i],s=this.indices[i+1],o=this.indices[i+2];this.getVertex(r,Bg),this.getVertex(s,Lg),this.getVertex(o,Hg),Fg.computeNormal(Lg,Bg,Hg,t),e[i]=t.x,e[i+1]=t.y,e[i+2]=t.z}}updateEdges(){const t={},e=(e,n)=>{t[e<n?`${e}_${n}`:`${n}_${e}`]=!0};for(let t=0;t<this.indices.length/3;t++){const n=3*t,i=this.indices[n],r=this.indices[n+1],s=this.indices[n+2];e(i,r),e(r,s),e(s,i)}const n=Object.keys(t);this.edges=new Int16Array(2*n.length);for(let t=0;t<n.length;t++){const e=n[t].split("_");this.edges[2*t]=parseInt(e[0],10),this.edges[2*t+1]=parseInt(e[1],10)}}getEdgeVertex(t,e,n){const i=this.edges[2*t+(e?1:0)];this.getVertex(i,n)}getEdgeVector(t,e){const n=Ng,i=Ug;this.getEdgeVertex(t,0,n),this.getEdgeVertex(t,1,i),i.vsub(n,e)}static computeNormal(t,e,n,i){e.vsub(t,jg),n.vsub(e,qg),qg.cross(jg,i),i.isZero()||i.normalize()}getVertex(t,e){const n=this.scale;return this.Up(t,e),e.x*=n.x,e.y*=n.y,e.z*=n.z,e}Up(t,e){const n=3*t,i=this.vertices;return e.set(i[n],i[n+1],i[n+2])}getWorldVertex(t,e,n,i){return this.getVertex(t,i),Ky.pointToWorldFrame(e,n,i,i),i}getTriangleVertices(t,e,n,i){const r=3*t;this.getVertex(this.indices[r],e),this.getVertex(this.indices[r+1],n),this.getVertex(this.indices[r+2],i)}getNormal(t,e){const n=3*t;return e.set(this.normals[n],this.normals[n+1],this.normals[n+2])}calculateLocalInertia(t,e){this.computeLocalAABB(Wg);const n=Wg.upperBound.x-Wg.lowerBound.x,i=Wg.upperBound.y-Wg.lowerBound.y,r=Wg.upperBound.z-Wg.lowerBound.z;return e.set(1/12*t*(4*i*i+4*r*r),1/12*t*(4*n*n+4*r*r),1/12*t*(4*i*i+4*n*n))}computeLocalAABB(t){const e=t.lowerBound,n=t.upperBound,i=this.vertices.length;this.vertices;const r=Vg;this.getVertex(0,r),e.copy(r),n.copy(r);for(let t=0;t!==i;t++)this.getVertex(t,r),r.x<e.x?e.x=r.x:r.x>n.x&&(n.x=r.x),r.y<e.y?e.y=r.y:r.y>n.y&&(n.y=r.y),r.z<e.z?e.z=r.z:r.z>n.z&&(n.z=r.z)}updateAABB(){this.computeLocalAABB(this.aabb)}updateBoundingSphereRadius(){let t=0;const e=this.vertices,n=new Py;for(let i=0,r=e.length/3;i!==r;i++){this.getVertex(i,n);const e=n.lengthSquared();e>t&&(t=e)}this.boundingSphereRadius=Math.sqrt(t)}calculateWorldAABB(t,e,n,i){const r=Gg,s=Yg;r.position=t,r.quaternion=e,this.aabb.toWorldFrame(r,s),n.copy(s.lowerBound),i.copy(s.upperBound)}volume(){return 4*Math.PI*this.boundingSphereRadius/3}static createTorus(t,e,n,i,r){void 0===t&&(t=1),void 0===e&&(e=.5),void 0===n&&(n=8),void 0===i&&(i=6),void 0===r&&(r=2*Math.PI);const s=[],o=[];for(let o=0;o<=n;o++)for(let a=0;a<=i;a++){const u=a/i*r,h=o/n*Math.PI*2,l=(t+e*Math.cos(h))*Math.cos(u),c=(t+e*Math.cos(h))*Math.sin(u),f=e*Math.sin(h);s.push(l,c,f)}for(let t=1;t<=n;t++)for(let e=1;e<=i;e++){const n=(i+1)*t+e-1,r=(i+1)*(t-1)+e-1,s=(i+1)*(t-1)+e,a=(i+1)*t+e;o.push(n,r,a),o.push(r,s,a)}return new Fg(s,o)}}const Pg=new Py,Dg=new qy,Ng=new Py,Ug=new Py,qg=new Py,jg=new Py,Bg=new Py,Lg=new Py,Hg=new Py,Wg=new qy,Vg=new Py,Gg=new Ky,Yg=new qy;class Kg{constructor(){this.equations=[]}solve(t,e){return 0}addEquation(t){!t.enabled||t.bi.isTrigger||t.bj.isTrigger||this.equations.push(t)}removeEquation(t){const e=this.equations,n=e.indexOf(t);-1!==n&&e.splice(n,1)}removeAllEquations(){this.equations.length=0}}class Xg extends Kg{constructor(){super(),this.iterations=10,this.tolerance=1e-7}solve(t,e){let n=0;const i=this.iterations,r=this.tolerance*this.tolerance,s=this.equations,o=s.length,a=e.bodies,u=a.length,h=t;let l,c,f,d,p,v;if(0!==o)for(let t=0;t!==u;t++)a[t].updateSolveMassProperties();const m=Zg,y=Jg,w=Qg;m.length=o,y.length=o,w.length=o;for(let t=0;t!==o;t++){const e=s[t];w[t]=0,y[t]=e.computeB(h),m[t]=1/e.computeC()}if(0!==o){for(let t=0;t!==u;t++){const e=a[t],n=e.vlambda,i=e.wlambda;n.set(0,0,0),i.set(0,0,0)}for(n=0;n!==i;n++){d=0;for(let t=0;t!==o;t++){const e=s[t];l=y[t],c=m[t],v=w[t],p=e.computeGWlambda(),f=c*(l-p-e.eps*v),v+f<e.minForce?f=e.minForce-v:v+f>e.maxForce&&(f=e.maxForce-v),w[t]+=f,d+=f>0?f:-f,e.addToWlambda(f)}if(d*d<r)break}for(let t=0;t!==u;t++){const e=a[t],n=e.velocity,i=e.angularVelocity;e.vlambda.vmul(e.linearFactor,e.vlambda),n.vadd(e.vlambda,n),e.wlambda.vmul(e.angularFactor,e.wlambda),i.vadd(e.wlambda,i)}let t=s.length;const e=1/h;for(;t--;)s[t].multiplier=w[t]*e}return n}}const Qg=[],Zg=[],Jg=[];sw.STATIC;class tb{constructor(){this.objects=[],this.type=Object}release(){const t=arguments.length;for(let e=0;e!==t;e++)this.objects.push(e<0||arguments.length<=e?void 0:arguments[e]);return this}get(){return 0===this.objects.length?this.constructObject():this.objects.pop()}constructObject(){throw new Error("constructObject() not implemented in this Pool subclass yet!")}resize(t){const e=this.objects;for(;e.length>t;)e.pop();for(;e.length<t;)e.push(this.constructObject());return this}}class eb extends tb{constructor(){super(...arguments),this.type=Py}constructObject(){return new Py}}const nb=Yy.types.SPHERE,ib=Yy.types.SPHERE|Yy.types.PLANE,rb=Yy.types.BOX|Yy.types.BOX,sb=Yy.types.SPHERE|Yy.types.BOX,ob=Yy.types.PLANE|Yy.types.BOX,ab=Yy.types.CONVEXPOLYHEDRON,ub=Yy.types.SPHERE|Yy.types.CONVEXPOLYHEDRON,hb=Yy.types.PLANE|Yy.types.CONVEXPOLYHEDRON,lb=Yy.types.BOX|Yy.types.CONVEXPOLYHEDRON,cb=Yy.types.SPHERE|Yy.types.HEIGHTFIELD,fb=Yy.types.BOX|Yy.types.HEIGHTFIELD,db=Yy.types.CONVEXPOLYHEDRON|Yy.types.HEIGHTFIELD,pb=Yy.types.PARTICLE|Yy.types.SPHERE,vb=Yy.types.PLANE|Yy.types.PARTICLE,mb=Yy.types.BOX|Yy.types.PARTICLE,yb=Yy.types.PARTICLE|Yy.types.CONVEXPOLYHEDRON,wb=Yy.types.CYLINDER,gb=Yy.types.SPHERE|Yy.types.CYLINDER,bb=Yy.types.PLANE|Yy.types.CYLINDER,_b=Yy.types.BOX|Yy.types.CYLINDER,xb=Yy.types.CONVEXPOLYHEDRON|Yy.types.CYLINDER,kb=Yy.types.HEIGHTFIELD|Yy.types.CYLINDER,$b=Yy.types.PARTICLE|Yy.types.CYLINDER,Sb=Yy.types.SPHERE|Yy.types.TRIMESH,Mb=Yy.types.PLANE|Yy.types.TRIMESH;class Eb{get[nb](){return this.sphereSphere}get[ib](){return this.spherePlane}get[rb](){return this.boxBox}get[sb](){return this.sphereBox}get[ob](){return this.planeBox}get[ab](){return this.convexConvex}get[ub](){return this.sphereConvex}get[hb](){return this.planeConvex}get[lb](){return this.boxConvex}get[cb](){return this.sphereHeightfield}get[fb](){return this.boxHeightfield}get[db](){return this.convexHeightfield}get[pb](){return this.sphereParticle}get[vb](){return this.planeParticle}get[mb](){return this.boxParticle}get[yb](){return this.convexParticle}get[wb](){return this.convexConvex}get[gb](){return this.sphereConvex}get[bb](){return this.planeConvex}get[_b](){return this.boxConvex}get[xb](){return this.convexConvex}get[kb](){return this.heightfieldCylinder}get[$b](){return this.particleCylinder}get[Sb](){return this.sphereTrimesh}get[Mb](){return this.planeTrimesh}constructor(t){this.contactPointPool=[],this.frictionEquationPool=[],this.result=[],this.frictionResult=[],this.v3pool=new eb,this.world=t,this.currentContactMaterial=t.defaultContactMaterial,this.enableFrictionReduction=!1}createContactEquation(t,e,n,i,r,s){let o;this.contactPointPool.length?(o=this.contactPointPool.pop(),o.bi=t,o.bj=e):o=new yg(t,e),o.enabled=t.collisionResponse&&e.collisionResponse&&n.collisionResponse&&i.collisionResponse;const a=this.currentContactMaterial;o.restitution=a.restitution,o.setSpookParams(a.contactEquationStiffness,a.contactEquationRelaxation,this.world.dt);const u=n.material||t.material,h=i.material||e.material;return u&&h&&u.restitution>=0&&h.restitution>=0&&(o.restitution=u.restitution*h.restitution),o.si=r||n,o.sj=s||i,o}createFrictionEquationsFromContact(t,e){const n=t.bi,i=t.bj,r=t.si,s=t.sj,o=this.world,a=this.currentContactMaterial;let u=a.friction;const h=r.material||n.material,l=s.material||i.material;if(h&&l&&h.friction>=0&&l.friction>=0&&(u=h.friction*l.friction),u>0){const r=u*(o.frictionGravity||o.gravity).length();let s=n.invMass+i.invMass;s>0&&(s=1/s);const h=this.frictionEquationPool,l=h.length?h.pop():new Mg(n,i,r*s),c=h.length?h.pop():new Mg(n,i,r*s);return l.bi=c.bi=n,l.bj=c.bj=i,l.minForce=c.minForce=-r*s,l.maxForce=c.maxForce=r*s,l.ri.copy(t.ri),l.rj.copy(t.rj),c.ri.copy(t.ri),c.rj.copy(t.rj),t.ni.tangents(l.t,c.t),l.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,o.dt),c.setSpookParams(a.frictionEquationStiffness,a.frictionEquationRelaxation,o.dt),l.enabled=c.enabled=t.enabled,e.push(l,c),!0}return!1}createFrictionFromAverage(t){let e=this.result[this.result.length-1];if(!this.createFrictionEquationsFromContact(e,this.frictionResult)||1===t)return;const n=this.frictionResult[this.frictionResult.length-2],i=this.frictionResult[this.frictionResult.length-1];Cb.setZero(),Ab.setZero(),Ob.setZero();const r=e.bi;e.bj;for(let n=0;n!==t;n++)e=this.result[this.result.length-1-n],e.bi!==r?(Cb.vadd(e.ni,Cb),Ab.vadd(e.ri,Ab),Ob.vadd(e.rj,Ob)):(Cb.vsub(e.ni,Cb),Ab.vadd(e.rj,Ab),Ob.vadd(e.ri,Ob));const s=1/t;Ab.scale(s,n.ri),Ob.scale(s,n.rj),i.ri.copy(n.ri),i.rj.copy(n.rj),Cb.normalize(),Cb.tangents(n.t,i.t)}getContacts(t,e,n,i,r,s,o){this.contactPointPool=r,this.frictionEquationPool=o,this.result=i,this.frictionResult=s;const a=zb,u=Rb,h=Ib,l=Tb;for(let i=0,r=t.length;i!==r;i++){const r=t[i],s=e[i];let o=null;r.material&&s.material&&(o=n.getContactMaterial(r.material,s.material)||null);const c=r.type&sw.KINEMATIC&&s.type&sw.STATIC||r.type&sw.STATIC&&s.type&sw.KINEMATIC||r.type&sw.KINEMATIC&&s.type&sw.KINEMATIC;for(let t=0;t<r.shapes.length;t++){r.quaternion.mult(r.shapeOrientations[t],a),r.quaternion.vmult(r.shapeOffsets[t],h),h.vadd(r.position,h);const e=r.shapes[t];for(let t=0;t<s.shapes.length;t++){s.quaternion.mult(s.shapeOrientations[t],u),s.quaternion.vmult(s.shapeOffsets[t],l),l.vadd(s.position,l);const i=s.shapes[t];if(!(e.collisionFilterMask&i.collisionFilterGroup&&i.collisionFilterMask&e.collisionFilterGroup))continue;if(h.distanceTo(l)>e.boundingSphereRadius+i.boundingSphereRadius)continue;let f=null;e.material&&i.material&&(f=n.getContactMaterial(e.material,i.material)||null),this.currentContactMaterial=f||o||n.defaultContactMaterial;const d=this[e.type|i.type];if(d){let t=!1;t=e.type<i.type?d.call(this,e,i,h,l,a,u,r,s,e,i,c):d.call(this,i,e,l,h,u,a,s,r,e,i,c),t&&c&&(n.shapeOverlapKeeper.set(e.id,i.id),n.bodyOverlapKeeper.set(r.id,s.id))}}}}}sphereSphere(t,e,n,i,r,s,o,a,u,h,l){if(l)return n.distanceSquared(i)<(t.radius+e.radius)**2;const c=this.createContactEquation(o,a,t,e,u,h);i.vsub(n,c.ni),c.ni.normalize(),c.ri.copy(c.ni),c.rj.copy(c.ni),c.ri.scale(t.radius,c.ri),c.rj.scale(-e.radius,c.rj),c.ri.vadd(n,c.ri),c.ri.vsub(o.position,c.ri),c.rj.vadd(i,c.rj),c.rj.vsub(a.position,c.rj),this.result.push(c),this.createFrictionEquationsFromContact(c,this.frictionResult)}spherePlane(t,e,n,i,r,s,o,a,u,h,l){const c=this.createContactEquation(o,a,t,e,u,h);if(c.ni.set(0,0,1),s.vmult(c.ni,c.ni),c.ni.negate(c.ni),c.ni.normalize(),c.ni.scale(t.radius,c.ri),n.vsub(i,Jb),c.ni.scale(c.ni.dot(Jb),t_),Jb.vsub(t_,c.rj),-Jb.dot(c.ni)<=t.radius){if(l)return!0;const t=c.ri,e=c.rj;t.vadd(n,t),t.vsub(o.position,t),e.vadd(i,e),e.vsub(a.position,e),this.result.push(c),this.createFrictionEquationsFromContact(c,this.frictionResult)}}boxBox(t,e,n,i,r,s,o,a,u,h,l){return t.convexPolyhedronRepresentation.material=t.material,e.convexPolyhedronRepresentation.material=e.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e.convexPolyhedronRepresentation,n,i,r,s,o,a,t,e,l)}sphereBox(t,e,n,i,r,s,o,a,u,h,l){const c=this.v3pool,f=h_;n.vsub(i,s_),e.getSideNormals(f,s);const d=t.radius;let p=!1;const v=c_,m=f_,y=d_;let w=null,g=0,b=0,_=0,x=null;for(let t=0,e=f.length;t!==e&&!1===p;t++){const e=o_;e.copy(f[t]);const n=e.length();e.normalize();const i=s_.dot(e);if(i<n+d&&i>0){const r=a_,s=u_;r.copy(f[(t+1)%3]),s.copy(f[(t+2)%3]);const o=r.length(),a=s.length();r.normalize(),s.normalize();const u=s_.dot(r),h=s_.dot(s);if(u<o&&u>-o&&h<a&&h>-a){const t=Math.abs(i-n-d);if((null===x||t<x)&&(x=t,b=u,_=h,w=n,v.copy(e),m.copy(r),y.copy(s),g++,l))return!0}}}if(g){p=!0;const r=this.createContactEquation(o,a,t,e,u,h);v.scale(-d,r.ri),r.ni.copy(v),r.ni.negate(r.ni),v.scale(w,v),m.scale(b,m),v.vadd(m,v),y.scale(_,y),v.vadd(y,r.rj),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.vadd(i,r.rj),r.rj.vsub(a.position,r.rj),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}let k=c.get();const $=l_;for(let r=0;2!==r&&!p;r++)for(let s=0;2!==s&&!p;s++)for(let c=0;2!==c&&!p;c++)if(k.set(0,0,0),r?k.vadd(f[0],k):k.vsub(f[0],k),s?k.vadd(f[1],k):k.vsub(f[1],k),c?k.vadd(f[2],k):k.vsub(f[2],k),i.vadd(k,$),$.vsub(n,$),$.lengthSquared()<d*d){if(l)return!0;p=!0;const r=this.createContactEquation(o,a,t,e,u,h);r.ri.copy($),r.ri.normalize(),r.ni.copy(r.ri),r.ri.scale(d,r.ri),r.rj.copy(k),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.vadd(i,r.rj),r.rj.vsub(a.position,r.rj),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}c.release(k),k=null;const S=c.get(),M=c.get(),E=c.get(),C=c.get(),A=c.get(),O=f.length;for(let r=0;r!==O&&!p;r++)for(let s=0;s!==O&&!p;s++)if(r%3!=s%3){f[s].cross(f[r],S),S.normalize(),f[r].vadd(f[s],M),E.copy(n),E.vsub(M,E),E.vsub(i,E);const c=E.dot(S);S.scale(c,C);let v=0;for(;v===r%3||v===s%3;)v++;A.copy(n),A.vsub(C,A),A.vsub(M,A),A.vsub(i,A);const m=Math.abs(c),y=A.length();if(m<f[v].length()&&y<d){if(l)return!0;p=!0;const r=this.createContactEquation(o,a,t,e,u,h);M.vadd(C,r.rj),r.rj.copy(r.rj),A.negate(r.ni),r.ni.normalize(),r.ri.copy(r.rj),r.ri.vadd(i,r.ri),r.ri.vsub(n,r.ri),r.ri.normalize(),r.ri.scale(d,r.ri),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.vadd(i,r.rj),r.rj.vsub(a.position,r.rj),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}}c.release(S,M,E,C,A)}planeBox(t,e,n,i,r,s,o,a,u,h,l){return e.convexPolyhedronRepresentation.material=e.material,e.convexPolyhedronRepresentation.collisionResponse=e.collisionResponse,e.convexPolyhedronRepresentation.id=e.id,this.planeConvex(t,e.convexPolyhedronRepresentation,n,i,r,s,o,a,t,e,l)}convexConvex(t,e,n,i,r,s,o,a,u,h,l,c,f){const d=C_;if(!(n.distanceTo(i)>t.boundingSphereRadius+e.boundingSphereRadius)&&t.findSeparatingAxis(e,n,r,i,s,d,c,f)){const c=[],f=A_;t.clipAgainstHull(n,r,e,i,s,d,-100,100,c);let p=0;for(let r=0;r!==c.length;r++){if(l)return!0;const s=this.createContactEquation(o,a,t,e,u,h),v=s.ri,m=s.rj;d.negate(s.ni),c[r].normal.negate(f),f.scale(c[r].depth,f),c[r].point.vadd(f,v),m.copy(c[r].point),v.vsub(n,v),m.vsub(i,m),v.vadd(n,v),v.vsub(o.position,v),m.vadd(i,m),m.vsub(a.position,m),this.result.push(s),p++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(s,this.frictionResult)}this.enableFrictionReduction&&p&&this.createFrictionFromAverage(p)}}sphereConvex(t,e,n,i,r,s,o,a,u,h,l){const c=this.v3pool;n.vsub(i,p_);const f=e.faceNormals,d=e.faces,p=e.vertices,v=t.radius;let m=!1;for(let r=0;r!==p.length;r++){const c=p[r],f=w_;s.vmult(c,f),i.vadd(f,f);const d=y_;if(f.vsub(n,d),d.lengthSquared()<v*v){if(l)return!0;m=!0;const r=this.createContactEquation(o,a,t,e,u,h);return r.ri.copy(d),r.ri.normalize(),r.ni.copy(r.ri),r.ri.scale(v,r.ri),f.vsub(i,r.rj),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.vadd(i,r.rj),r.rj.vsub(a.position,r.rj),this.result.push(r),void this.createFrictionEquationsFromContact(r,this.frictionResult)}}for(let r=0,y=d.length;r!==y&&!1===m;r++){const y=f[r],w=d[r],g=g_;s.vmult(y,g);const b=b_;s.vmult(p[w[0]],b),b.vadd(i,b);const _=__;g.scale(-v,_),n.vadd(_,_);const x=x_;_.vsub(b,x);const k=x.dot(g),$=k_;if(n.vsub(b,$),k<0&&$.dot(g)>0){const r=[];for(let t=0,e=w.length;t!==e;t++){const e=c.get();s.vmult(p[w[t]],e),i.vadd(e,e),r.push(e)}if(r_(r,g,n)){if(l)return!0;m=!0;const s=this.createContactEquation(o,a,t,e,u,h);g.scale(-v,s.ri),g.negate(s.ni);const f=c.get();g.scale(-k,f);const d=c.get();g.scale(-v,d),n.vsub(i,s.rj),s.rj.vadd(d,s.rj),s.rj.vadd(f,s.rj),s.rj.vadd(i,s.rj),s.rj.vsub(a.position,s.rj),s.ri.vadd(n,s.ri),s.ri.vsub(o.position,s.ri),c.release(f),c.release(d),this.result.push(s),this.createFrictionEquationsFromContact(s,this.frictionResult);for(let t=0,e=r.length;t!==e;t++)c.release(r[t]);return}for(let f=0;f!==w.length;f++){const d=c.get(),m=c.get();s.vmult(p[w[(f+1)%w.length]],d),s.vmult(p[w[(f+2)%w.length]],m),i.vadd(d,d),i.vadd(m,m);const y=v_;m.vsub(d,y);const g=m_;y.unit(g);const b=c.get(),_=c.get();n.vsub(d,_);const x=_.dot(g);g.scale(x,b),b.vadd(d,b);const k=c.get();if(b.vsub(n,k),x>0&&x*x<y.lengthSquared()&&k.lengthSquared()<v*v){if(l)return!0;const s=this.createContactEquation(o,a,t,e,u,h);b.vsub(i,s.rj),b.vsub(n,s.ni),s.ni.normalize(),s.ni.scale(v,s.ri),s.rj.vadd(i,s.rj),s.rj.vsub(a.position,s.rj),s.ri.vadd(n,s.ri),s.ri.vsub(o.position,s.ri),this.result.push(s),this.createFrictionEquationsFromContact(s,this.frictionResult);for(let t=0,e=r.length;t!==e;t++)c.release(r[t]);return c.release(d),c.release(m),c.release(b),c.release(k),void c.release(_)}c.release(d),c.release(m),c.release(b),c.release(k),c.release(_)}for(let t=0,e=r.length;t!==e;t++)c.release(r[t])}}}planeConvex(t,e,n,i,r,s,o,a,u,h,l){const c=$_,f=S_;f.set(0,0,1),r.vmult(f,f);let d=0;const p=M_;for(let r=0;r!==e.vertices.length;r++)if(c.copy(e.vertices[r]),s.vmult(c,c),i.vadd(c,c),c.vsub(n,p),f.dot(p)<=0){if(l)return!0;const r=this.createContactEquation(o,a,t,e,u,h),s=E_;f.scale(f.dot(p),s),c.vsub(s,s),s.vsub(n,r.ri),r.ni.copy(f),c.vsub(i,r.rj),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.vadd(i,r.rj),r.rj.vsub(a.position,r.rj),this.result.push(r),d++,this.enableFrictionReduction||this.createFrictionEquationsFromContact(r,this.frictionResult)}this.enableFrictionReduction&&d&&this.createFrictionFromAverage(d)}boxConvex(t,e,n,i,r,s,o,a,u,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexConvex(t.convexPolyhedronRepresentation,e,n,i,r,s,o,a,t,e,l)}sphereHeightfield(t,e,n,i,r,s,o,a,u,h,l){const c=e.data,f=t.radius,d=e.elementSize,p=L_,v=B_;Ky.pointToLocalFrame(i,s,n,v);let m=Math.floor((v.x-f)/d)-1,y=Math.ceil((v.x+f)/d)+1,w=Math.floor((v.y-f)/d)-1,g=Math.ceil((v.y+f)/d)+1;if(y<0||g<0||m>c.length||w>c[0].length)return;m<0&&(m=0),y<0&&(y=0),w<0&&(w=0),g<0&&(g=0),m>=c.length&&(m=c.length-1),y>=c.length&&(y=c.length-1),g>=c[0].length&&(g=c[0].length-1),w>=c[0].length&&(w=c[0].length-1);const b=[];e.getRectMinMax(m,w,y,g,b);const _=b[0],x=b[1];if(v.z-f>x||v.z+f<_)return;const k=this.result;for(let u=m;u<y;u++)for(let h=w;h<g;h++){const c=k.length;let f=!1;if(e.getConvexTrianglePillar(u,h,!1),Ky.pointToWorldFrame(i,s,e.pillarOffset,p),n.distanceTo(p)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(f=this.sphereConvex(t,e.pillarConvex,n,p,r,s,o,a,t,e,l)),l&&f)return!0;if(e.getConvexTrianglePillar(u,h,!0),Ky.pointToWorldFrame(i,s,e.pillarOffset,p),n.distanceTo(p)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(f=this.sphereConvex(t,e.pillarConvex,n,p,r,s,o,a,t,e,l)),l&&f)return!0;if(k.length-c>2)return}}boxHeightfield(t,e,n,i,r,s,o,a,u,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexHeightfield(t.convexPolyhedronRepresentation,e,n,i,r,s,o,a,t,e,l)}convexHeightfield(t,e,n,i,r,s,o,a,u,h,l){const c=e.data,f=e.elementSize,d=t.boundingSphereRadius,p=q_,v=j_,m=U_;Ky.pointToLocalFrame(i,s,n,m);let y=Math.floor((m.x-d)/f)-1,w=Math.ceil((m.x+d)/f)+1,g=Math.floor((m.y-d)/f)-1,b=Math.ceil((m.y+d)/f)+1;if(w<0||b<0||y>c.length||g>c[0].length)return;y<0&&(y=0),w<0&&(w=0),g<0&&(g=0),b<0&&(b=0),y>=c.length&&(y=c.length-1),w>=c.length&&(w=c.length-1),b>=c[0].length&&(b=c[0].length-1),g>=c[0].length&&(g=c[0].length-1);const _=[];e.getRectMinMax(y,g,w,b,_);const x=_[0],k=_[1];if(!(m.z-d>k||m.z+d<x))for(let u=y;u<w;u++)for(let h=g;h<b;h++){let c=!1;if(e.getConvexTrianglePillar(u,h,!1),Ky.pointToWorldFrame(i,s,e.pillarOffset,p),n.distanceTo(p)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(c=this.convexConvex(t,e.pillarConvex,n,p,r,s,o,a,null,null,l,v,null)),l&&c)return!0;if(e.getConvexTrianglePillar(u,h,!0),Ky.pointToWorldFrame(i,s,e.pillarOffset,p),n.distanceTo(p)<e.pillarConvex.boundingSphereRadius+t.boundingSphereRadius&&(c=this.convexConvex(t,e.pillarConvex,n,p,r,s,o,a,null,null,l,v,null)),l&&c)return!0}}sphereParticle(t,e,n,i,r,s,o,a,u,h,l){const c=z_;if(c.set(0,0,1),i.vsub(n,c),c.lengthSquared()<=t.radius*t.radius){if(l)return!0;const n=this.createContactEquation(a,o,e,t,u,h);c.normalize(),n.rj.copy(c),n.rj.scale(t.radius,n.rj),n.ni.copy(c),n.ni.negate(n.ni),n.ri.set(0,0,0),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}planeParticle(t,e,n,i,r,s,o,a,u,h,l){const c=O_;c.set(0,0,1),o.quaternion.vmult(c,c);const f=I_;if(i.vsub(o.position,f),c.dot(f)<=0){if(l)return!0;const n=this.createContactEquation(a,o,e,t,u,h);n.ni.copy(c),n.ni.negate(n.ni),n.ri.set(0,0,0);const r=T_;c.scale(c.dot(i),r),i.vsub(r,r),n.rj.copy(r),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}boxParticle(t,e,n,i,r,s,o,a,u,h,l){return t.convexPolyhedronRepresentation.material=t.material,t.convexPolyhedronRepresentation.collisionResponse=t.collisionResponse,this.convexParticle(t.convexPolyhedronRepresentation,e,n,i,r,s,o,a,t,e,l)}convexParticle(t,e,n,i,r,s,o,a,u,h,l){let c=-1;const f=P_,d=N_;let p=null;const v=F_;if(v.copy(i),v.vsub(n,v),r.conjugate(R_),R_.vmult(v,v),t.pointIsInside(v)){t.worldVerticesNeedsUpdate&&t.computeWorldVertices(n,r),t.worldFaceNormalsNeedsUpdate&&t.computeWorldFaceNormals(r);for(let e=0,n=t.faces.length;e!==n;e++){const n=[t.worldVertices[t.faces[e][0]]],r=t.worldFaceNormals[e];i.vsub(n[0],D_);const s=-r.dot(D_);if(null===p||Math.abs(s)<Math.abs(p)){if(l)return!0;p=s,c=e,f.copy(r)}}if(-1!==c){const r=this.createContactEquation(a,o,e,t,u,h);f.scale(p,d),d.vadd(i,d),d.vsub(n,d),r.rj.copy(d),f.negate(r.ni),r.ri.set(0,0,0);const s=r.ri,l=r.rj;s.vadd(i,s),s.vsub(a.position,s),l.vadd(n,l),l.vsub(o.position,l),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}}}heightfieldCylinder(t,e,n,i,r,s,o,a,u,h,l){return this.convexHeightfield(e,t,i,n,s,r,a,o,u,h,l)}particleCylinder(t,e,n,i,r,s,o,a,u,h,l){return this.convexParticle(e,t,i,n,s,r,a,o,u,h,l)}sphereTrimesh(t,e,n,i,r,s,o,a,u,h,l){const c=Bb,f=Lb,d=Hb,p=Wb,v=Vb,m=Gb,y=Qb,w=jb,g=Ub,b=Zb;Ky.pointToLocalFrame(i,s,n,v);const _=t.radius;y.lowerBound.set(v.x-_,v.y-_,v.z-_),y.upperBound.set(v.x+_,v.y+_,v.z+_),e.getTrianglesInAABB(y,b);const x=qb,k=t.radius*t.radius;for(let r=0;r<b.length;r++)for(let c=0;c<3;c++)if(e.getVertex(e.indices[3*b[r]+c],x),x.vsub(v,g),g.lengthSquared()<=k){if(w.copy(x),Ky.pointToWorldFrame(i,s,w,x),x.vsub(n,g),l)return!0;let r=this.createContactEquation(o,a,t,e,u,h);r.ni.copy(g),r.ni.normalize(),r.ri.copy(r.ni),r.ri.scale(t.radius,r.ri),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),r.rj.copy(x),r.rj.vsub(a.position,r.rj),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}for(let r=0;r<b.length;r++)for(let y=0;y<3;y++){e.getVertex(e.indices[3*b[r]+y],c),e.getVertex(e.indices[3*b[r]+(y+1)%3],f),f.vsub(c,d),v.vsub(f,m);const w=m.dot(d);v.vsub(c,m);let g=m.dot(d);if(g>0&&w<0&&(v.vsub(c,m),p.copy(d),p.normalize(),g=m.dot(p),p.scale(g,m),m.vadd(c,m),m.distanceTo(v)<t.radius)){if(l)return!0;const r=this.createContactEquation(o,a,t,e,u,h);m.vsub(v,r.ni),r.ni.normalize(),r.ni.scale(t.radius,r.ri),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),Ky.pointToWorldFrame(i,s,m,m),m.vsub(a.position,r.rj),Ky.vectorToWorldFrame(s,r.ni,r.ni),Ky.vectorToWorldFrame(s,r.ri,r.ri),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}}const $=Yb,S=Kb,M=Xb,E=Nb;for(let r=0,c=b.length;r!==c;r++){e.getTriangleVertices(b[r],$,S,M),e.getNormal(b[r],E),v.vsub($,m);let c=m.dot(E);if(E.scale(c,m),v.vsub(m,m),c=m.distanceTo(v),zw.pointInTriangle(m,$,S,M)&&c<t.radius){if(l)return!0;let r=this.createContactEquation(o,a,t,e,u,h);m.vsub(v,r.ni),r.ni.normalize(),r.ni.scale(t.radius,r.ri),r.ri.vadd(n,r.ri),r.ri.vsub(o.position,r.ri),Ky.pointToWorldFrame(i,s,m,m),m.vsub(a.position,r.rj),Ky.vectorToWorldFrame(s,r.ni,r.ni),Ky.vectorToWorldFrame(s,r.ri,r.ri),this.result.push(r),this.createFrictionEquationsFromContact(r,this.frictionResult)}}b.length=0}planeTrimesh(t,e,n,i,r,s,o,a,u,h,l){const c=new Py,f=Fb;f.set(0,0,1),r.vmult(f,f);for(let r=0;r<e.vertices.length/3;r++){e.getVertex(r,c);const d=new Py;d.copy(c),Ky.pointToWorldFrame(i,s,d,c);const p=Pb;if(c.vsub(n,p),f.dot(p)<=0){if(l)return!0;const n=this.createContactEquation(o,a,t,e,u,h);n.ni.copy(f);const i=Db;f.scale(p.dot(f),i),c.vsub(i,i),n.ri.copy(i),n.ri.vsub(o.position,n.ri),n.rj.copy(c),n.rj.vsub(a.position,n.rj),this.result.push(n),this.createFrictionEquationsFromContact(n,this.frictionResult)}}}}const Cb=new Py,Ab=new Py,Ob=new Py,Ib=new Py,Tb=new Py,zb=new Wy,Rb=new Wy,Fb=new Py,Pb=new Py,Db=new Py,Nb=new Py,Ub=new Py;new Py;const qb=new Py,jb=new Py,Bb=new Py,Lb=new Py,Hb=new Py,Wb=new Py,Vb=new Py,Gb=new Py,Yb=new Py,Kb=new Py,Xb=new Py,Qb=new qy,Zb=[],Jb=new Py,t_=new Py,e_=new Py,n_=new Py,i_=new Py;function r_(t,e,n){let i=null;const r=t.length;for(let s=0;s!==r;s++){const o=t[s],a=e_;t[(s+1)%r].vsub(o,a);const u=n_;a.cross(e,u);const h=i_;n.vsub(o,h);const l=u.dot(h);if(!(null===i||l>0&&!0===i||l<=0&&!1===i))return!1;null===i&&(i=l>0)}return!0}const s_=new Py,o_=new Py,a_=new Py,u_=new Py,h_=[new Py,new Py,new Py,new Py,new Py,new Py],l_=new Py,c_=new Py,f_=new Py,d_=new Py,p_=new Py,v_=new Py,m_=new Py,y_=new Py,w_=new Py,g_=new Py,b_=new Py,__=new Py,x_=new Py,k_=new Py;new Py,new Py;const $_=new Py,S_=new Py,M_=new Py,E_=new Py,C_=new Py,A_=new Py,O_=new Py,I_=new Py,T_=new Py,z_=new Py,R_=new Wy,F_=new Py;new Py;const P_=new Py,D_=new Py,N_=new Py,U_=new Py,q_=new Py,j_=[0],B_=new Py,L_=new Py;class H_{constructor(){this.current=[],this.previous=[]}getKey(t,e){if(e<t){const n=e;e=t,t=n}return t<<16|e}set(t,e){const n=this.getKey(t,e),i=this.current;let r=0;for(;n>i[r];)r++;if(n!==i[r]){for(let t=i.length-1;t>=r;t--)i[t+1]=i[t];i[r]=n}}tick(){const t=this.current;this.current=this.previous,this.previous=t,this.current.length=0}getDiff(t,e){const n=this.current,i=this.previous,r=n.length,s=i.length;let o=0;for(let e=0;e<r;e++){let r=!1;const s=n[e];for(;s>i[o];)o++;r=s===i[o],r||W_(t,s)}o=0;for(let t=0;t<s;t++){let r=!1;const s=i[t];for(;s>n[o];)o++;r=n[o]===s,r||W_(e,s)}}}function W_(t,e){t.push((4294901760&e)>>16,65535&e)}const V_=(t,e)=>t<e?`${t}-${e}`:`${e}-${t}`;class G_{constructor(){this.data={keys:[]}}get(t,e){const n=V_(t,e);return this.data[n]}set(t,e,n){const i=V_(t,e);this.get(t,e)||this.data.keys.push(i),this.data[i]=n}delete(t,e){const n=V_(t,e),i=this.data.keys.indexOf(n);-1!==i&&this.data.keys.splice(i,1),delete this.data[n]}reset(){const t=this.data,e=t.keys;for(;e.length>0;)delete t[e.pop()]}}class Y_ extends Hy{constructor(t){void 0===t&&(t={}),super(),this.dt=-1,this.allowSleep=!!t.allowSleep,this.contacts=[],this.frictionEquations=[],this.quatNormalizeSkip=void 0!==t.quatNormalizeSkip?t.quatNormalizeSkip:0,this.quatNormalizeFast=void 0!==t.quatNormalizeFast&&t.quatNormalizeFast,this.time=0,this.stepnumber=0,this.default_dt=1/60,this.nextId=0,this.gravity=new Py,t.gravity&&this.gravity.copy(t.gravity),t.frictionGravity&&(this.frictionGravity=new Py,this.frictionGravity.copy(t.frictionGravity)),this.broadphase=void 0!==t.broadphase?t.broadphase:new $w,this.bodies=[],this.hasActiveBodies=!1,this.solver=void 0!==t.solver?t.solver:new Xg,this.constraints=[],this.narrowphase=new Eb(this),this.collisionMatrix=new Ly,this.collisionMatrixPrevious=new Ly,this.bodyOverlapKeeper=new H_,this.shapeOverlapKeeper=new H_,this.contactmaterials=[],this.contactMaterialTable=new G_,this.defaultMaterial=new Og("default"),this.defaultContactMaterial=new Ag(this.defaultMaterial,this.defaultMaterial,{friction:.3,restitution:0}),this.doProfiling=!1,this.profile={solve:0,makeContactConstraints:0,broadphase:0,integrate:0,narrowphase:0},this.accumulator=0,this.subsystems=[],this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.idToBodyMap={},this.broadphase.setWorld(this)}getContactMaterial(t,e){return this.contactMaterialTable.get(t.id,e.id)}collisionMatrixTick(){const t=this.collisionMatrixPrevious;this.collisionMatrixPrevious=this.collisionMatrix,this.collisionMatrix=t,this.collisionMatrix.reset(),this.bodyOverlapKeeper.tick(),this.shapeOverlapKeeper.tick()}addConstraint(t){this.constraints.push(t)}removeConstraint(t){const e=this.constraints.indexOf(t);-1!==e&&this.constraints.splice(e,1)}rayTest(t,e,n){n instanceof Sw?this.raycastClosest(t,e,{skipBackfaces:!0},n):this.raycastAll(t,e,{skipBackfaces:!0},n)}raycastAll(t,e,n,i){return void 0===n&&(n={}),n.mode=zw.ALL,n.from=t,n.to=e,n.callback=i,K_.intersectWorld(this,n)}raycastAny(t,e,n,i){return void 0===n&&(n={}),n.mode=zw.ANY,n.from=t,n.to=e,n.result=i,K_.intersectWorld(this,n)}raycastClosest(t,e,n,i){return void 0===n&&(n={}),n.mode=zw.CLOSEST,n.from=t,n.to=e,n.result=i,K_.intersectWorld(this,n)}addBody(t){this.bodies.includes(t)||(t.index=this.bodies.length,this.bodies.push(t),t.world=this,t.initPosition.copy(t.position),t.initVelocity.copy(t.velocity),t.timeLastSleepy=this.time,t instanceof sw&&(t.initAngularVelocity.copy(t.angularVelocity),t.initQuaternion.copy(t.quaternion)),this.collisionMatrix.setNumObjects(this.bodies.length),this.addBodyEvent.body=t,this.idToBodyMap[t.id]=t,this.dispatchEvent(this.addBodyEvent))}removeBody(t){t.world=null;const e=this.bodies.length-1,n=this.bodies,i=n.indexOf(t);if(-1!==i){n.splice(i,1);for(let t=0;t!==n.length;t++)n[t].index=t;this.collisionMatrix.setNumObjects(e),this.removeBodyEvent.body=t,delete this.idToBodyMap[t.id],this.dispatchEvent(this.removeBodyEvent)}}getBodyById(t){return this.idToBodyMap[t]}getShapeById(t){const e=this.bodies;for(let n=0;n<e.length;n++){const i=e[n].shapes;for(let e=0;e<i.length;e++){const n=i[e];if(n.id===t)return n}}return null}addContactMaterial(t){this.contactmaterials.push(t),this.contactMaterialTable.set(t.materials[0].id,t.materials[1].id,t)}removeContactMaterial(t){const e=this.contactmaterials.indexOf(t);-1!==e&&(this.contactmaterials.splice(e,1),this.contactMaterialTable.delete(t.materials[0].id,t.materials[1].id))}fixedStep(t,e){void 0===t&&(t=1/60),void 0===e&&(e=10);const n=X_.now()/1e3;if(this.lastCallTime){const i=n-this.lastCallTime;this.step(t,i,e)}else this.step(t,void 0,e);this.lastCallTime=n}step(t,e,n){if(void 0===n&&(n=10),void 0===e)this.internalStep(t),this.time+=t;else{this.accumulator+=e;const i=X_.now();let r=0;for(;this.accumulator>=t&&r<n&&(this.internalStep(t),this.accumulator-=t,r++,!(X_.now()-i>1e3*t)););this.accumulator=this.accumulator%t;const s=this.accumulator/t;for(let t=0;t!==this.bodies.length;t++){const e=this.bodies[t];e.previousPosition.lerp(e.position,s,e.interpolatedPosition),e.previousQuaternion.slerp(e.quaternion,s,e.interpolatedQuaternion),e.previousQuaternion.normalize()}this.time+=e}}internalStep(t){this.dt=t;const e=this.contacts,n=nx,i=ix,r=this.bodies.length,s=this.bodies,o=this.solver,a=this.gravity,u=this.doProfiling,h=this.profile,l=sw.DYNAMIC;let c=-1/0;const f=this.constraints,d=ex;a.length();const p=a.x,v=a.y,m=a.z;let y=0;for(u&&(c=X_.now()),y=0;y!==r;y++){const t=s[y];if(t.type===l){const e=t.force,n=t.mass;e.x+=n*p,e.y+=n*v,e.z+=n*m}}for(let t=0,e=this.subsystems.length;t!==e;t++)this.subsystems[t].update();u&&(c=X_.now()),n.length=0,i.length=0,this.broadphase.collisionPairs(this,n,i),u&&(h.broadphase=X_.now()-c);let w=f.length;for(y=0;y!==w;y++){const t=f[y];if(!t.collideConnected)for(let e=n.length-1;e>=0;e-=1)(t.bodyA===n[e]&&t.bodyB===i[e]||t.bodyB===n[e]&&t.bodyA===i[e])&&(n.splice(e,1),i.splice(e,1))}this.collisionMatrixTick(),u&&(c=X_.now());const g=tx,b=e.length;for(y=0;y!==b;y++)g.push(e[y]);e.length=0;const _=this.frictionEquations.length;for(y=0;y!==_;y++)d.push(this.frictionEquations[y]);for(this.frictionEquations.length=0,this.narrowphase.getContacts(n,i,this,e,g,this.frictionEquations,d),u&&(h.narrowphase=X_.now()-c),u&&(c=X_.now()),y=0;y<this.frictionEquations.length;y++)o.addEquation(this.frictionEquations[y]);const x=e.length;for(let t=0;t!==x;t++){const n=e[t],i=n.bi,r=n.bj,s=n.si,a=n.sj;let u;u=i.material&&r.material&&this.getContactMaterial(i.material,r.material)||this.defaultContactMaterial,u.friction,i.material&&r.material&&(i.material.friction>=0&&r.material.friction>=0&&(i.material.friction,r.material.friction),i.material.restitution>=0&&r.material.restitution>=0&&(n.restitution=i.material.restitution*r.material.restitution)),o.addEquation(n),i.allowSleep&&i.type===sw.DYNAMIC&&i.sleepState===sw.SLEEPING&&r.sleepState===sw.AWAKE&&r.type!==sw.STATIC&&r.velocity.lengthSquared()+r.angularVelocity.lengthSquared()>=2*r.sleepSpeedLimit**2&&(i.wakeUpAfterNarrowphase=!0),r.allowSleep&&r.type===sw.DYNAMIC&&r.sleepState===sw.SLEEPING&&i.sleepState===sw.AWAKE&&i.type!==sw.STATIC&&i.velocity.lengthSquared()+i.angularVelocity.lengthSquared()>=2*i.sleepSpeedLimit**2&&(r.wakeUpAfterNarrowphase=!0),this.collisionMatrix.set(i,r,!0),this.collisionMatrixPrevious.get(i,r)||(J_.body=r,J_.contact=n,i.dispatchEvent(J_),J_.body=i,r.dispatchEvent(J_)),this.bodyOverlapKeeper.set(i.id,r.id),this.shapeOverlapKeeper.set(s.id,a.id)}for(this.emitContactEvents(),u&&(h.makeContactConstraints=X_.now()-c,c=X_.now()),y=0;y!==r;y++){const t=s[y];t.wakeUpAfterNarrowphase&&(t.wakeUp(),t.wakeUpAfterNarrowphase=!1)}for(w=f.length,y=0;y!==w;y++){const t=f[y];t.update();for(let e=0,n=t.equations.length;e!==n;e++){const n=t.equations[e];o.addEquation(n)}}o.solve(t,this),u&&(h.solve=X_.now()-c),o.removeAllEquations();const k=Math.pow;for(y=0;y!==r;y++){const e=s[y];if(e.type&l){const n=k(1-e.linearDamping,t),i=e.velocity;i.scale(n,i);const r=e.angularVelocity;if(r){const n=k(1-e.angularDamping,t);r.scale(n,r)}}}this.dispatchEvent(Z_),u&&(c=X_.now());const $=this.stepnumber%(this.quatNormalizeSkip+1)==0,S=this.quatNormalizeFast;for(y=0;y!==r;y++)s[y].integrate(t,$,S);this.clearForces(),this.broadphase.dirty=!0,u&&(h.integrate=X_.now()-c),this.stepnumber+=1,this.dispatchEvent(Q_);let M=!0;if(this.allowSleep)for(M=!1,y=0;y!==r;y++){const t=s[y];t.sleepTick(this.time),t.sleepState!==sw.SLEEPING&&(M=!0)}this.hasActiveBodies=M}emitContactEvents(){const t=this.hasAnyEventListener("beginContact"),e=this.hasAnyEventListener("endContact");if((t||e)&&this.bodyOverlapKeeper.getDiff(rx,sx),t){for(let t=0,e=rx.length;t<e;t+=2)ox.bodyA=this.getBodyById(rx[t]),ox.bodyB=this.getBodyById(rx[t+1]),this.dispatchEvent(ox);ox.bodyA=ox.bodyB=null}if(e){for(let t=0,e=sx.length;t<e;t+=2)ax.bodyA=this.getBodyById(sx[t]),ax.bodyB=this.getBodyById(sx[t+1]),this.dispatchEvent(ax);ax.bodyA=ax.bodyB=null}rx.length=sx.length=0;const n=this.hasAnyEventListener("beginShapeContact"),i=this.hasAnyEventListener("endShapeContact");if((n||i)&&this.shapeOverlapKeeper.getDiff(rx,sx),n){for(let t=0,e=rx.length;t<e;t+=2){const e=this.getShapeById(rx[t]),n=this.getShapeById(rx[t+1]);ux.shapeA=e,ux.shapeB=n,e&&(ux.bodyA=e.body),n&&(ux.bodyB=n.body),this.dispatchEvent(ux)}ux.bodyA=ux.bodyB=ux.shapeA=ux.shapeB=null}if(i){for(let t=0,e=sx.length;t<e;t+=2){const e=this.getShapeById(sx[t]),n=this.getShapeById(sx[t+1]);hx.shapeA=e,hx.shapeB=n,e&&(hx.bodyA=e.body),n&&(hx.bodyB=n.body),this.dispatchEvent(hx)}hx.bodyA=hx.bodyB=hx.shapeA=hx.shapeB=null}}clearForces(){const t=this.bodies,e=t.length;for(let n=0;n!==e;n++){const e=t[n];e.force,e.torque,e.force.set(0,0,0),e.torque.set(0,0,0)}}}new qy;const K_=new zw,X_=globalThis.performance||{};if(!X_.now){let t=Date.now();X_.timing&&X_.timing.navigationStart&&(t=X_.timing.navigationStart),X_.now=()=>Date.now()-t}new Py;const Q_={type:"postStep"},Z_={type:"preStep"},J_={type:sw.COLLIDE_EVENT_NAME,body:null,contact:null},tx=[],ex=[],nx=[],ix=[],rx=[],sx=[],ox={type:"beginContact",bodyA:null,bodyB:null},ax={type:"endContact",bodyA:null,bodyB:null},ux={type:"beginShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null},hx={type:"endShapeContact",bodyA:null,bodyB:null,shapeA:null,shapeB:null};function lx(t,e,n,i,r){let s;if(r===function(t,e,n,i){let r=0;for(let s=e,o=n-i;s<n;s+=i)r+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return r}(t,e,n,i)>0)for(let r=e;r<n;r+=i)s=Tx(r/i|0,t[r],t[r+1],s);else for(let r=n-i;r>=e;r-=i)s=Tx(r/i|0,t[r],t[r+1],s);return s&&Mx(s,s.next)&&(zx(s),s=s.next),s}function cx(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Mx(i,i.next)&&0!==Sx(i.prev,i,i.next))i=i.next;else{if(zx(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function fx(t,e,n,i,r,s,o){if(!t)return;!o&&s&&function(t,e,n,i){let r=t;do{0===r.z&&(r.z=bx(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,n=1;do{let i,r=t;t=null;let s=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<n&&(a++,o=o.nextZ,o);t++);let u=n;for(;a>0||u>0&&o;)0!==a&&(0===u||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,u--),s?s.nextZ=i:t=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(e>1)}(r)}(t,i,r,s);let a=t;for(;t.prev!==t.next;){const u=t.prev,h=t.next;if(s?px(t,i,r,s):dx(t))e.push(u.i,t.i,h.i),zx(t),t=h.next,a=h.next;else if((t=h)===a){o?1===o?fx(t=vx(cx(t),e),e,n,i,r,s,2):2===o&&mx(t,e,n,i,r,s):fx(cx(t),e,n,i,r,s,1);break}}}function dx(t){const e=t.prev,n=t,i=t.next;if(Sx(e,n,i)>=0)return!1;const r=e.x,s=n.x,o=i.x,a=e.y,u=n.y,h=i.y,l=Math.min(r,s,o),c=Math.min(a,u,h),f=Math.max(r,s,o),d=Math.max(a,u,h);let p=i.next;for(;p!==e;){if(p.x>=l&&p.x<=f&&p.y>=c&&p.y<=d&&kx(r,a,s,u,o,h,p.x,p.y)&&Sx(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function px(t,e,n,i){const r=t.prev,s=t,o=t.next;if(Sx(r,s,o)>=0)return!1;const a=r.x,u=s.x,h=o.x,l=r.y,c=s.y,f=o.y,d=Math.min(a,u,h),p=Math.min(l,c,f),v=Math.max(a,u,h),m=Math.max(l,c,f),y=bx(d,p,e,n,i),w=bx(v,m,e,n,i);let g=t.prevZ,b=t.nextZ;for(;g&&g.z>=y&&b&&b.z<=w;){if(g.x>=d&&g.x<=v&&g.y>=p&&g.y<=m&&g!==r&&g!==o&&kx(a,l,u,c,h,f,g.x,g.y)&&Sx(g.prev,g,g.next)>=0)return!1;if(g=g.prevZ,b.x>=d&&b.x<=v&&b.y>=p&&b.y<=m&&b!==r&&b!==o&&kx(a,l,u,c,h,f,b.x,b.y)&&Sx(b.prev,b,b.next)>=0)return!1;b=b.nextZ}for(;g&&g.z>=y;){if(g.x>=d&&g.x<=v&&g.y>=p&&g.y<=m&&g!==r&&g!==o&&kx(a,l,u,c,h,f,g.x,g.y)&&Sx(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;b&&b.z<=w;){if(b.x>=d&&b.x<=v&&b.y>=p&&b.y<=m&&b!==r&&b!==o&&kx(a,l,u,c,h,f,b.x,b.y)&&Sx(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function vx(t,e){let n=t;do{const i=n.prev,r=n.next.next;!Mx(i,r)&&Ex(i,n,n.next,r)&&Ox(i,r)&&Ox(r,i)&&(e.push(i.i,n.i,r.i),zx(n),zx(n.next),n=t=r),n=n.next}while(n!==t);return cx(n)}function mx(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&$x(o,t)){let a=Ix(o,t);return o=cx(o,o.next),a=cx(a,a.next),fx(o,e,n,i,r,s,0),void fx(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function yx(t,e){let n=t.x-e.x;return 0===n&&(n=t.y-e.y,0===n)&&(n=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)),n}function wx(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(Mx(t,n))return n;do{if(Mx(t,n.next))return n.next;if(r<=n.y&&r>=n.next.y&&n.next.y!==n.y){const t=n.x+(r-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(t<=i&&t>o&&(o=t,s=n.x<n.next.x?n:n.next,t===i))return s}n=n.next}while(n!==e);if(!s)return null;const a=s,u=s.x,h=s.y;let l=1/0;n=s;do{if(i>=n.x&&n.x>=u&&i!==n.x&&xx(r<h?i:o,r,u,h,r<h?o:i,r,n.x,n.y)){const e=Math.abs(r-n.y)/(i-n.x);Ox(n,t)&&(e<l||e===l&&(n.x>s.x||n.x===s.x&&gx(s,n)))&&(s=n,l=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Ix(n,t);return cx(i,i.next),cx(n,n.next)}function gx(t,e){return Sx(t.prev,t,e.prev)<0&&Sx(e.next,t,t.next)<0}function bx(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function _x(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function xx(t,e,n,i,r,s,o,a){return(r-o)*(e-a)>=(t-o)*(s-a)&&(t-o)*(i-a)>=(n-o)*(e-a)&&(n-o)*(s-a)>=(r-o)*(i-a)}function kx(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&xx(t,e,n,i,r,s,o,a)}function $x(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Ex(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Ox(t,e)&&Ox(e,t)&&function(t,e){let n=t,i=!1;const r=(t.x+e.x)/2,s=(t.y+e.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&r<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(Sx(t.prev,t,e.prev)||Sx(t,e.prev,e))||Mx(t,e)&&Sx(t.prev,t,t.next)>0&&Sx(e.prev,e,e.next)>0)}function Sx(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Mx(t,e){return t.x===e.x&&t.y===e.y}function Ex(t,e,n,i){const r=Ax(Sx(t,e,n)),s=Ax(Sx(t,e,i)),o=Ax(Sx(n,i,t)),a=Ax(Sx(n,i,e));return r!==s&&o!==a||!(0!==r||!Cx(t,n,e))||!(0!==s||!Cx(t,i,e))||!(0!==o||!Cx(n,t,i))||!(0!==a||!Cx(n,e,i))}function Cx(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function Ax(t){return t>0?1:t<0?-1:0}function Ox(t,e){return Sx(t.prev,t,t.next)<0?Sx(t,e,t.next)>=0&&Sx(t,t.prev,e)>=0:Sx(t,e,t.prev)<0||Sx(t,t.next,e)<0}function Ix(t,e){const n=Rx(t.i,t.x,t.y),i=Rx(e.i,e.x,e.y),r=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,s.next=i,i.prev=s,i}function Tx(t,e,n,i){const r=Rx(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function zx(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Rx(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}const Fx=function(t,e){var n,i,r=t[0],s=t[1],o=e[0],a=e[1],u=o[0],h=o[1],l=a[0],c=a[1],f=l-u,d=c-h,p=0===f&&0===d?0:(f*(r-u)+d*(s-h))/(f*f+d*d||0);return p<=0?(n=u,i=h):p>=1?(n=l,i=c):(n=u+p*f,i=h+p*d),[n,i]},Px=function(t,e){return((t[0]-e[0])**2+(t[1]-e[1])**2)**.5},Dx=function(t,e){let n=1/0;for(let i=0,r=1,s=e.length;r<s;i=r,r+=1){const s=Fx(t,[e[i],e[r]]);n=Math.min(n,Px(s,t))}return n},Nx=function(t,e){var n=1/0;let i;for(let r=0,s=1,o=e.length;s<o;r=s,s+=1){let o=Fx(t,[e[r],e[s]]);const a=Px(o,t);a<n&&(n=a,i=o)}return i},Ux=function(t,e){var n=1/0;let i;for(let r=0;r<e.length;r+=1){const s=e[r];for(let e=0,r=1,o=s.length;r<o;e=r,r+=1){let o=Fx(t,[s[e],s[r]]);const a=Px(o,t);a<n&&(n=a,i=o)}}return i},qx=t=>{const e=[0,0],n=[0,0];let i=0;const r=t[0],s=t.length;for(let o=2;o<s;o++){const s=t[o-1],a=t[o];e[0]=r[0]-a[0],e[1]=r[1]-a[1],n[0]=r[0]-s[0],n[1]=r[1]-s[1],i+=e[0]*n[1]-e[1]*n[0]}return i/2},jx=function(t,e){var n=1/0;let i;for(let r=0;r<e.length;r+=1){const s=e[r];let o=Ux(t,s);const a=Px(o,t);a<n&&(n=a,i=o)}return i},Bx=(t,e,n=!1)=>{const i=t[0],r=t[1];let s,o,a,u,h=!1;const l=e.length;for(let t=0,c=l-1;t<l;c=t,t+=1){let l=!1;if(s=e[t][0],o=e[t][1],a=e[c][0],u=e[c][1],s===i&&o===r||a===i&&u===r)return!!n;if(o<r==u>=r){const t=(a-s)*(r-o)/(u-o)+s;if(i===t)return!!n;l=i<t}l&&(h=!h)}return h},Lx=(t,e,n=!1)=>!!Bx(t,e[0],n)&&!e.slice(1).find((e=>Bx(t,e,!n))),Hx=(t,e,n=!1)=>!!e.find((e=>Lx(t,e,n))),Wx=(t,e)=>{let n=0;if(t[0]===e[0])n=t[1]>e[1]?Math.PI:0;else if(t[1]===e[1])n=t[0]>e[0]?Math.PI/2:-Math.PI/2;else{const i=t[0]-e[0],r=t[1]-e[1];n=Math.atan(i/r),i>0&&r>0?n=Math.PI-n:i<0&&r<0||i>0&&r<0?n=-n:i<0&&r>0&&(n=Math.PI-n)}return n},Vx=(t,e,n=0)=>{if(!e)return[];n%=e;const i=[0],r=t.length;for(let e=1;e<r;e+=1){const n=t[e][0]-t[e-1][0],r=t[e][1]-t[e-1][1];i[e]=i[e-1]+(n**2+r**2)**.5}const s=[];let o=0;for(let a=1;a<r;a+=1)if(i[a]-n-o*e>=e-1e-8){let r=i[a]-n-e*o;const u=Math.floor((r+1e-8)/e);o+=u,r=i[a]-n-e*o;const h=Wx(t[a-1],t[a]);for(let n=0;n<u;n+=1){const o=(r+e*(u-1-n))/(i[a]-i[a-1]),l=[t[a][0]-o*(t[a][0]-t[a-1][0]),t[a][1]-o*(t[a][1]-t[a-1][1]),void 0!==t[a][2]?t[a][2]-o*(t[a][2]-t[a-1][2]):0,h];s.push(l)}}return s},Gx=t=>{const e=t.length;let n=0;const i=t[e-1];let r,s,o,a=i[0],u=i[1];for(let i=0;i<e;i+=1)o=t[i],r=o[0],s=o[1],n+=(r-a)*(s+u),a=r,u=s;return n>0};function Yx(t,n,i,r){const s=e.Cartesian3.subtract(i,n,new e.Cartesian3),o=e.Cartesian3.subtract(r,n,new e.Cartesian3),a=e.Cartesian3.subtract(t,n,new e.Cartesian3),u=e.Cartesian3.dot(s,a),h=e.Cartesian3.dot(o,a);if(u<=0&&h<=0)return e.Cartesian3.clone(n);const l=e.Cartesian3.subtract(t,i,new e.Cartesian3),c=e.Cartesian3.dot(s,l),f=e.Cartesian3.dot(o,l);if(c>=0&&f<=c)return e.Cartesian3.clone(i);const d=u*f-c*h;if(d<=0&&u>=0&&c<=0){const t=u/(u-c);return e.Cartesian3.add(n,e.Cartesian3.multiplyByScalar(s,t,new e.Cartesian3),new e.Cartesian3)}const p=e.Cartesian3.subtract(t,r,new e.Cartesian3),v=e.Cartesian3.dot(s,p),m=e.Cartesian3.dot(o,p);if(m>=0&&v<=m)return e.Cartesian3.clone(r);const y=v*h-u*m;if(y<=0&&h>=0&&m<=0){const t=h/(h-m);return e.Cartesian3.add(n,e.Cartesian3.multiplyByScalar(o,t,new e.Cartesian3),new e.Cartesian3)}const w=c*m-v*f;if(w<=0&&f-c>=0&&v-m>=0){const t=(f-c)/(f-c+(v-m));return e.Cartesian3.add(i,e.Cartesian3.multiplyByScalar(e.Cartesian3.subtract(r,i,new e.Cartesian3),t,new e.Cartesian3),new e.Cartesian3)}const g=1/(w+y+d),b=y*g,_=d*g;return e.Cartesian3.add(n,e.Cartesian3.add(e.Cartesian3.multiplyByScalar(s,b,new e.Cartesian3),e.Cartesian3.multiplyByScalar(o,_,new e.Cartesian3),new e.Cartesian3),new e.Cartesian3)}function Kx(t,n,i){let r=null,s=1/0;const o=new e.Cartesian3,a=new e.Cartesian3,u=new e.Cartesian3;for(let h=0;h<i.length;h+=3){o.x=n[3*i[h]],o.y=n[3*i[h]+1],o.z=n[3*i[h]+2],a.x=n[3*i[h+1]],a.y=n[3*i[h+1]+1],a.z=n[3*i[h+1]+2],u.x=n[3*i[h+2]],u.y=n[3*i[h+2]+1],u.z=n[3*i[h+2]+2];const l=Yx(t,o,a,u),c=e.Cartesian3.distance(t,l);c<s&&(s=c,r=l)}return{point:r,distance:s}}var Xx={distance:Px,distanceToLineString:Dx,closestOnSegment:Fx,closestOnLineString:Nx,closestOnMultiLineString:Ux,closestOnMultiPolygon:jx,buff:(t,e)=>{const n=9e-6,i=t.map((t=>{const e=t.map((t=>[t[0]*n,t[1]*n])),i=e.length;return e[0][0]===e[i-1][0]&&e[0][1]===e[i-1][1]||e.push(e[0]),e})),r=dp(function(t,e,n={}){for(const e of t){if(e.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(e[e.length-1].length!==e[0].length)throw new Error("First and last Position are not equivalent.");for(let t=0;t<e[e.length-1].length;t++)if(e[e.length-1][t]!==e[0][t])throw new Error("First and last Position are not equivalent.")}return hf({type:"Polygon",coordinates:t},e,n)}(i),e/1e3,{units:"kilometers",steps:1});if(r)return"MultiPolygon"==r.geometry.type?r.geometry.coordinates.map(((t,e)=>t.map((t=>t.map((t=>[t[0]/n,t[1]/n])))))):[r.geometry.coordinates.map((t=>t.map((t=>[t[0]/n,t[1]/n]))))]},inMultiPolygon:Hx,inPolygon:Lx,contain:Bx,dividePathByUnit:Vx,isClockwise:Gx,closestPointOnMesh:Kx,ringArea2D:qx};const Qx={distance:Px,distanceToLineString:Dx,closestOnSegment:Fx,closestOnLineString:Nx,closestOnMultiLineString:Ux,closestOnMultiPolygon:jx,pointInMultiPolygon:Hx,pointInPolygon:Lx,pointInRing:Bx,dividePathByUnit:Vx,isClockwise:Gx,closestPointOnMesh:Kx,ringArea2D:qx};var Zx=2*Math.PI;class Jx{Gn;qp;jp;Bp;Lp;Hp;Wp;Vp;Gp;Yp;Kp;Xp=0;fe;Qp;Zp;Jp;tv;ev;nv;iv;rv;Vn;sv;ov=0;constructor(t,e,n){this.sv=n;var i=void 0===(e=e||{}).title?"joystick":e.title,r=void 0===e.width?0:e.width,s=void 0===e.height?0:e.height;this.Qp=void 0===e.internalFillColor?"rgba(255,255,255,0.4)":e.internalFillColor,this.Zp=void 0===e.internalLineWidth?2:e.internalLineWidth,this.Jp=void 0===e.internalStrokeColor?"rgba(255,255,255,0.6)":e.internalStrokeColor,this.tv=void 0===e.externalLineWidth?2:e.externalLineWidth,this.ev=void 0===e.externalStrokeColor?"rgba(255,255,255,0.3)":e.externalStrokeColor,this.nv=void 0===e.autoReturnToCenter||e.autoReturnToCenter;var o=t;o.style.touchAction="none";var a=document.createElement("canvas");this.Gn=a,a.style.width="100%",a.id=i,0===r&&(r=o.clientWidth),0===s&&(s=o.clientHeight),a.width=r,a.height=s,o.appendChild(a),this.Vn=t,this.fe=a.getContext("2d"),this.iv=a.width/4-12,this.Hp=this.iv+20,this.rv=this.iv+30,this.Bp=a.width/2,this.Lp=a.height/2,this.Gp=a.width/10,this.Yp=-1*this.Gp,this.Wp=a.height/10,this.Vp=-1*this.Wp,this.qp=this.Bp,this.jp=this.Lp,this.Vn.style.display="none",this.av(),this.uv(),this.Kp=null,this.hv=this.hv.bind(this),this.lv=this.lv.bind(this),this.cv=this.cv.bind(this),this.fv=this.fv.bind(this),this.dv=this.dv.bind(this),this.pv=this.pv.bind(this)}av=()=>{this.fe.beginPath(),this.fe.arc(this.Bp,this.Lp,this.rv,0,Zx,!1),this.fe.shadowBlur=5,this.fe.shadowColor="white",this.fe.lineWidth=this.tv,this.fe.strokeStyle=this.ev,this.fe.stroke()};uv=()=>{this.fe.beginPath();const t=this.qp-this.Bp,e=this.jp-this.Lp,n=(t**2+e**2)**.5;if(n>this.Hp){const i=this.Hp/n;this.qp=i*t+this.Bp,this.jp=i*e+this.Lp}this.fe.arc(this.qp,this.jp,this.iv,0,Zx,!1);var i=this.fe.createRadialGradient(this.Bp,this.Lp,5,this.Bp,this.Lp,200);i.addColorStop(0,this.Qp),i.addColorStop(1,this.Jp),this.fe.shadowBlur=5,this.fe.shadowColor="white",this.fe.fillStyle=i,this.fe.fill(),this.fe.lineWidth=this.Zp,this.fe.strokeStyle=this.Jp,this.fe.stroke()};fv(t){0==this.Xp&&1==t.touches.length&&(this.Xp=1)}dv(t){1===this.Xp&&1==t.touches.length&&(this.qp=t.touches[0].pageX,this.jp=t.touches[0].pageY,"BODY"===this.Gn.offsetParent.tagName.toUpperCase()?(this.qp-=this.Gn.offsetLeft,this.jp-=this.Gn.offsetTop):(this.qp-=this.Gn.offsetParent.offsetLeft,this.jp-=this.Gn.offsetParent.offsetTop),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.av(),this.uv())}pv(t){t.touches[0]||(this.Xp=0,this.nv&&(this.qp=this.Bp,this.jp=this.Lp),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.av(),this.uv())}hv(t){t.stopPropagation(),this.Xp=1}lv(t){1===this.Xp&&(t.stopPropagation(),this.qp=t.pageX,this.jp=t.pageY,"BODY"===this.Gn.offsetParent.tagName.toUpperCase()?(this.qp-=this.Gn.offsetLeft,this.jp-=this.Gn.offsetTop):(this.qp-=this.Gn.offsetParent.offsetLeft,this.jp-=this.Gn.offsetParent.offsetTop),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.av(),this.uv())}cv(t){this.Xp=0,this.nv&&(this.qp=this.Bp,this.jp=this.Lp),this.fe.clearRect(0,0,this.Gn.width,this.Gn.height),this.av(),this.uv()}open(){"ontouchstart"in document.documentElement?(this.Gn.addEventListener("touchstart",this.fv,!0),document.addEventListener("touchmove",this.dv,!0),document.addEventListener("touchend",this.pv,!0)):(this.Gn.addEventListener("mousedown",this.hv,!0),document.addEventListener("mousemove",this.lv,!0),document.addEventListener("mouseup",this.cv,!0)),this.Vn.style.display="block",this.ov=window.setInterval((()=>{this.sv({x:this.GetX(),y:this.GetY()})}),50)}close(){"ontouchstart"in document.documentElement?(this.Gn.removeEventListener("touchstart",this.fv),document.removeEventListener("touchmove",this.dv),document.removeEventListener("touchend",this.pv)):(this.Gn.removeEventListener("mousedown",this.hv),document.removeEventListener("mousemove",this.lv),document.removeEventListener("mouseup",this.cv)),this.Vn.style.display="none",clearInterval(this.ov),this.ov=0}getCardinalDirection(){let t="",e=this.qp-this.Bp,n=this.jp-this.Lp;return n>=this.Vp&&n<=this.Wp&&(t="C"),n<this.Vp&&(t="N"),n>this.Wp&&(t="S"),e<this.Yp&&("C"===t?t="W":t+="W"),e>this.Gp&&("C"===t?t="E":t+="E"),t}GetWidth(){return this.Gn.width}GetHeight(){return this.Gn.height}GetPosX(){return this.qp}GetPosY(){return this.jp}GetX(){return parseFloat(((this.qp-this.Bp)/this.Hp*100).toFixed())}GetY(){return parseFloat(((this.jp-this.Lp)/this.Hp*100*-1).toFixed())}GetDir(){return this.getCardinalDirection()}}class tk{Os="closed";bo;xf;dd;vv=new e.Cartesian2;mv=new e.Cartesian2;Ud;Ef;yv;wv;Kc;gv;bv=!1;_v={};Lf=[];xv=0;Wf=0;kv=1;Jn=!1;$v;Sv;Cf=0;Mv=0;Ev=-10;Cv;Av;Ov;Iv;Tv;constructor(t){t.isIndoor?this.Kc=new zp(1,1,.1):this.Kc=new zp(1,1,.01),t.buffer=t.buffer||.2,t.speed=t.speed||1,t.steeringSpeed=t.steeringSpeed||10,t.lookingMode=t.lookingMode||"scene",t.fixSpeedByHeight=null==t.fixSpeedByHeight||t.fixSpeedByHeight,t.isIndoor&&(t.fixSpeedByHeight=!1),this.bo=t,this.bv="fixedLine"===t.lookingMode,this.kv=t.fixedLineMoveSpeed||1,this.bv&&t.cameraInfos&&(this._v=t.cameraInfos,this.Lf=t.cameraInfos.map((t=>t.position)),this.xv=1e3*Bp({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:this.Lf}},{units:"kilometers"}));const e=t.viewer.canvas;e.setAttribute("tabindex","0"),e.onclick=function(){e.focus()},this.Ef=[],this.Ud=new r.ScreenSpaceEventHandler(e),this.Of=this.Of.bind(this),this.Af=this.Af.bind(this),this.If=this.If.bind(this),this.zv();const n=document.createElement("div");n.style.cssText="width:150px;height:150px;position:absolute;bottom:50px;left:0;border-radius:100%",this.gv=n,this.wv=new Jx(n,{width:150,height:150,externalLineWidth:1,internalLineWidth:1},this.Rv.bind(this));const i=this.bo.yunjingLayer.gc.Is();i?(this.Ov=i,this.Fv(i)):this.bo.yunjingLayer.on("configloaded",(t=>{this.Ov=t,this.Fv(t)}))}set isIndoor(t){this.bo.isIndoor=t}get isIndoor(){return this.bo.isIndoor||!1}Fv(t){const e=t.limitBounds;if(e){const t=[];var n=new Y_;n.broadphase=new $w,e?.forEach((e=>{const i=e.extrudedHeight;let r=[],s=[],o=[];if(e.perPositionHeight)s=e.path.map(((t,n)=>(Xx.isClockwise(t)&&(t=t.reverse()),n&&o.push((o[o.length-1]||0)+e.path[n-1].length),t.map((t=>[t[0],t[1]])).flat()))),r=e.path.map((t=>t.map((t=>t[2]))));else{const t=e.height;s=e.path.map(((t,n)=>(Xx.isClockwise(t)&&(t=t.reverse()),n&&o.push((o[o.length-1]||0)+e.path[n-1].length),t.map((t=>[t[0],t[1]])).flat()))),r=e.path.map((e=>e.map((e=>t))))}const a=s.flat();r=r.flat();const u=function(t,e,n=2){const i=e.length,r=i?e[0]*n:t.length;let s=lx(t,0,r,n,!0);const o=[];if(!s||s.next===s.prev)return o;let a,u,h;if(i&&(s=function(t,e,n,i){const r=[];for(let n=0,s=e.length;n<s;n++){const o=lx(t,e[n]*i,n<s-1?e[n+1]*i:t.length,i,!1);o===o.next&&(o.steiner=!0),r.push(_x(o))}r.sort(yx);for(let t=0;t<r.length;t++)n=wx(r[t],n);return n}(t,e,s,n)),t.length>80*n){a=1/0,u=1/0;let e=-1/0,i=-1/0;for(let s=n;s<r;s+=n){const n=t[s],r=t[s+1];n<a&&(a=n),r<u&&(u=r),n>e&&(e=n),r>i&&(i=r)}h=Math.max(e-a,i-u),h=0!==h?32767/h:0}return fx(s,o,n,a,u,h,0),o}(a,o),h=r.length,l=[],c=[];for(let t=0;t<a.length;t+=2)l.push(a[t],a[t+1],r[t/2]);for(let t=0;t<a.length;t+=2)l.push(a[t],a[t+1],r[t/2]+i);for(let t=0;t<u.length;t+=3)c.push(u[t],u[t+1],u[t+2]),c.push(u[t+2]+h,u[t+1]+h,u[t]+h);for(let t=0;t<h-1;t+=1)-1==o.indexOf(t+1)&&(null==o[0]||t<o[0]?c.push(t,t+h,t+1+h,t,t+1+h,t+1):c.push(t,t+1+h,t+h,t,t+1,t+1+h));const f=new Fg(l,c);t.push({mesh:f,groundTriangles:u.length/3,extrudedHeight:i,maxz:Math.min(...r)+i,minz:Math.max(...r)});var d=new sw({mass:1,position:new Py(0,0,0)});d.addShape(f),d.angularVelocity.set(0,0,.1),n.addBody(d)})),this.Iv={world:n,infos:t}}}Rv(t){if(this.yv,t.x||t.y){const e=r.Cartographic.fromCartesian(this.bo.viewer.camera.positionWC,void 0,this.Pv);let n=.05*this.bo.speed;this.bo.fixSpeedByHeight&&(n*=Math.max(1.8,e.height-this.bo.yunjingLayer.getBaseHeight())/2),"fixedLine"===this.bo.lookingMode?(n*=t.y,this.moveByLine(t.y>0?"forward":"backward",t.y)):this.move([t.x,t.y,0],n,!0)}}zv(){}Dv(){const t=this.bo.yunjingLayer.Ii().map((t=>t.Gt));if(0===t.length)return;const e=new Set,n={},i=this.bo.boxesSize||.5;for(var r=0;r<t.length;r++){const o=t[r],a=o.byteLength/4/3;if(a<=0)continue;const u=new Float32Array(o);for(var s=0;s<a;s+=1){const t=3*s,r=u[t],o=u[t+1],a=u[t+2],h=`${Math.floor(r/i)}_${Math.floor(o/i)}_${Math.floor(a/i)}`;e.has(h)?n[h]+=1:(e.add(h),n[h]=1)}}if(!(e.size<=0)){for(let t in n)n[t]<20&&e.delete(t);this.yv={isCode:!0,dis:i,codes:e}}}Nv(t){let e=this.Ov.enuCenter;const n={},i=[];t.forEach((t=>{const s=[(t[0]+t[3])/2,(t[1]+t[4])/2,(t[2]+t[5])/2],o=[Math.abs(t[0]-t[3])/1,Math.abs(t[1]-t[4])/1,Math.abs(t[2]-t[5])/1];let a=Dc(new r.Cartesian3(...s),e),u=Nc(a);const h=`${Math.round(t[0]/5)}_${Math.round(t[1]/5)}`,l={bbox:t,center:u,alt:t[5],ecef:a,size:o,radius:Math.sqrt(o[0]*o[0]+o[1]*o[1]+o[2]*o[2])/2};n[h]?n[h].push(l):n[h]=[l],i.push(l)}));const s=[],o=i.length;for(let t=0;t<o;t++){const{center:e,size:n,alt:o}=i[t],a=new r.Cartesian3(...n),u=r.Matrix4.multiplyByTranslation(r.Transforms.eastNorthUpToFixedFrame(r.Cartesian3.fromDegrees(e.lng,e.lat,e.height)),new r.Cartesian3(0,0,0),new r.Matrix4),h=new r.GeometryInstance({geometry:r.BoxGeometry.fromDimensions({vertexFormat:r.VertexFormat.POSITION_AND_NORMAL,dimensions:a}),modelMatrix:u,attributes:{color:r.ColorGeometryInstanceAttribute.fromColor(new r.Color(1,(150-Math.min(150,o))/150,(150-Math.min(150,o))/150,.6))}});s.push(h)}this.bo.viewer.scene.primitives.add(new r.Primitive({geometryInstances:s,appearance:new r.PerInstanceColorAppearance({translucent:!0,closed:!0,renderState:{depthTest:{enabled:!0}}})}))}static Sf=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","KeyA","KeyS","KeyD","KeyW","KeyQ","KeyE"];open(){if("openning"==this.Os)return;this.Os="openning";const t=this.bo.viewer,n=t.scene;n.screenSpaceCameraController.enableRotate=!1,n.screenSpaceCameraController.enableTranslate=!1,n.screenSpaceCameraController.enableZoom=!1,n.screenSpaceCameraController.enableLook=!1,n.screenSpaceCameraController.Uv/=3,this.vv.x=this.vv.y=0,this.mv.x=this.mv.y=0,this.dd={inertiaing:!1,looking:!1,moveForward:!1,moveBackward:!1,moveUp:!1,moveDown:!1,moveLeft:!1,moveRight:!1,dragging:!1,noObstacleAvoidance:!1};const i=this.Ud,s=-1!==navigator.userAgent.toLowerCase().indexOf("mobile"),o=t=>{this.dd.inertiaing=!1,this.dd.looking=!0,this.dd.dragging=!1,this.mv.x=this.vv.x=t.position.x,this.mv.y=this.vv.y=t.position.y},a=()=>{this.dd.inertiaing=!1,this.dd.looking=!1,this.dd.dragging=!1,this.xf=void 0},u=t=>{this.dd.inertiaing=!1,this.dd.dragging=!0,this.dd.looking=!1,this.mv.x=this.vv.x=t.position.x,this.mv.y=this.vv.y=t.position.y;const n=this.bo.viewer.camera;let i;if(this.bo.isIndoor)i=new e.Cartesian3(0,0,-1.5);else{const t=r.Cartographic.fromCartesian(n.positionWC,void 0,this.Pv);i=new e.Cartesian3(0,0,-(t.height-this.bo.yunjingLayer.getBaseHeight()))}this.Kc.Nc(new e.Cartesian3,i),this.$v=this.if(this.mv),this.Mv=(new Date).getTime(),this.Sv=void 0},h=()=>{if(this.dd.dragging=!1,!this.bo.isIndoor&&this.Sv&&(new Date).getTime()-this.Mv<10){this.dd.inertiaing=!0;const t=this.bo.viewer.camera,n=r.Cartographic.fromCartesian(t.positionWC,void 0,this.Pv);let i=this.Ev;this.bo.fixSpeedByHeight&&(i*=Math.max(1.8,n.height-this.bo.yunjingLayer.getBaseHeight())/2);const s=this.Sv,o=e.Cartesian2.magnitude(this.Sv);let a=o/Math.abs(i);a=Math.min(1,a),i=-o/a;const u=(s.x<0?-1:1)*Math.abs(s.x/o)*i,h=(s.y<0?-1:1)*Math.abs(s.y/o)*i;this.Cv=u,this.Av=h}else this.Sv=void 0;this.xf=void 0},l=t=>{(this.dd.looking||this.dd.dragging)&&(this.mv=r.Cartesian2.clone(t.endPosition,this.mv)),(this.dd.dragging||this.dd?.inertiaing)&&this.qv()},c=this.bo.viewer.camera,f=t=>{if(this.dd.inertiaing=!1,t.distance){if(t.distance.startPosition.y===t.distance.endPosition.y)return;t=5*(t.distance.endPosition.y-t.distance.startPosition.y)}const n=r.Cartographic.fromCartesian(c.positionWC,void 0,this.Pv),i=this.Ov.enuCenter;if(!i)return;let s=(this.bo.isIndoor?1.5:Math.max(1.8,n.height-this.bo.yunjingLayer.getBaseHeight()))*t/1e3;const o=new r.Cartesian3,a=r.Cartesian3.multiplyByScalar(c.directionWC,s,o);r.Cartesian3.add(c.positionWC,a,o);const u=Fc(o,i,this.jv);if(!this.Bv(u,o)){const t=this.Lv(Fc(c.positionWC,i),a,u);if(!t)return;{const n=Pc(t,i);e.Cartesian3.fromRadians(n[0],n[1],n[2],void 0,o)}}c.setView({destination:o,orientation:{heading:c.heading,pitch:c.pitch,roll:0}})};i.setInputAction(f,r.ScreenSpaceEventType.WHEEL),i.setInputAction(f,r.ScreenSpaceEventType.PINCH_MOVE),i.setInputAction(f,r.ScreenSpaceEventType.WHEEL,r.KeyboardEventModifier.SHIFT),document.addEventListener("keydown",this.Af,!1),document.addEventListener("keyup",this.If,!1),this.Cf=requestAnimationFrame(this.Of),s?(t._element.appendChild(this.gv),this.wv.open(),i.setInputAction(o,r.ScreenSpaceEventType.LEFT_DOWN),i.setInputAction(a,r.ScreenSpaceEventType.LEFT_UP),i.setInputAction(l,r.ScreenSpaceEventType.MOUSE_MOVE)):(i.setInputAction(o,r.ScreenSpaceEventType.RIGHT_DOWN),i.setInputAction(o,r.ScreenSpaceEventType.RIGHT_DOWN,r.KeyboardEventModifier.SHIFT),i.setInputAction(a,r.ScreenSpaceEventType.RIGHT_UP),i.setInputAction(a,r.ScreenSpaceEventType.RIGHT_UP,r.KeyboardEventModifier.SHIFT),i.setInputAction(u,r.ScreenSpaceEventType.LEFT_DOWN),i.setInputAction(u,r.ScreenSpaceEventType.LEFT_DOWN,r.KeyboardEventModifier.SHIFT),i.setInputAction(h,r.ScreenSpaceEventType.LEFT_UP),i.setInputAction(h,r.ScreenSpaceEventType.LEFT_UP,r.KeyboardEventModifier.SHIFT),i.setInputAction(l,r.ScreenSpaceEventType.MOUSE_MOVE),i.setInputAction(l,r.ScreenSpaceEventType.MOUSE_MOVE,r.KeyboardEventModifier.SHIFT),i.setInputAction((()=>{this.dd.inertiaing=!1}),r.ScreenSpaceEventType.MIDDLE_DOWN));const d=new e.Quaternion,p=new e.Matrix3,v=new e.Cartesian3;return c.rotate=(t,n)=>{if(n){const i=this.Ov.enuCenter,s=n,o=e.Quaternion.fromAxisAngle(t,-s,d),a=e.Matrix3.fromQuaternion(o,p);e.Matrix3.multiplyByVector(a,c.position,v);const u=c._actualTransform;r.Matrix4.multiplyByPoint(u,v,v);const h=Fc(v,i,this.jv);if(!this.Bv(h,v))return}r.Camera.prototype.rotate.call(c,t,n)},this}close(){const t=-1!==navigator.userAgent.toLowerCase().indexOf("mobile");document.removeEventListener("keydown",this.Af),document.removeEventListener("keyup",this.If),this.Cf&&cancelAnimationFrame(this.Cf),this.Ef=[],this.xf=void 0;const e=this.bo.viewer,n=e.scene;n.screenSpaceCameraController.enableRotate=!0,n.screenSpaceCameraController.enableTranslate=!0,n.screenSpaceCameraController.enableZoom=!0,n.screenSpaceCameraController.enableTilt=!0,n.screenSpaceCameraController.enableLook=!0,n.screenSpaceCameraController.Uv*=3;const i=this.Ud;t?(e._element.removeChild(this.gv),this.wv.close(),i.removeInputAction(r.ScreenSpaceEventType.LEFT_DOWN),i.removeInputAction(r.ScreenSpaceEventType.LEFT_UP),i.removeInputAction(r.ScreenSpaceEventType.MOUSE_MOVE)):(i.removeInputAction(r.ScreenSpaceEventType.RIGHT_DOWN),i.removeInputAction(r.ScreenSpaceEventType.RIGHT_DOWN,r.KeyboardEventModifier.SHIFT),i.removeInputAction(r.ScreenSpaceEventType.RIGHT_UP),i.removeInputAction(r.ScreenSpaceEventType.RIGHT_UP,r.KeyboardEventModifier.SHIFT),i.removeInputAction(r.ScreenSpaceEventType.LEFT_DOWN),i.removeInputAction(r.ScreenSpaceEventType.LEFT_DOWN,r.KeyboardEventModifier.SHIFT),i.removeInputAction(r.ScreenSpaceEventType.LEFT_UP),i.removeInputAction(r.ScreenSpaceEventType.LEFT_UP,r.KeyboardEventModifier.SHIFT),i.removeInputAction(r.ScreenSpaceEventType.MOUSE_MOVE),i.removeInputAction(r.ScreenSpaceEventType.MOUSE_MOVE,r.KeyboardEventModifier.SHIFT),i.removeInputAction(r.ScreenSpaceEventType.MIDDLE_DOWN)),i.removeInputAction(r.ScreenSpaceEventType.WHEEL),i.removeInputAction(r.ScreenSpaceEventType.PINCH_MOVE),i.removeInputAction(r.ScreenSpaceEventType.WHEEL,r.KeyboardEventModifier.SHIFT),this.bo.viewer.camera.rotate=r.Camera.prototype.rotate}set speed(t){this.bo.speed=t||.5}Af(t){if(this.dd.inertiaing=!1,"Shift"==t.key)return void(this.dd.noObstacleAvoidance=!0);const e={ArrowDown:"ArrowUp",ArrowUp:"ArrowDown",ArrowLeft:"ArrowRight",ArrowRight:"ArrowLeft",KeyA:"KeyD",KeyD:"KeyA",KeyS:"KeyW",KeyW:"KeyS"};if(-1!==tk.Sf.indexOf(t.code)&&-1==this.Ef.indexOf(t.code)){if(e[t.code]){const n=this.Ef.indexOf(e[t.code]);-1!==n&&this.Ef.splice(n,1)}this.Ef.push(t.code)}}If(t){if("Shift"==t.key)return void(this.dd.noObstacleAvoidance=!1);const e=-1!==tk.Sf.indexOf(t.code),n=this.Ef.indexOf(t.code);e&&-1!==n&&this.Ef.splice(n,1),this.xf=void 0}Hv=new r.Ray;if(t){const n=this.bo.viewer.camera,i=r.Cartographic.fromCartesian(n.positionWC,void 0,this.Pv),s=[180*i.longitude/Math.PI,180*i.latitude/Math.PI,i.height],o=n.getPickRay(t,this.Hv),a=e.Cartesian3.add(o.origin,o.direction,o.origin),u=new e.Cartesian3;let h;return e.Cartesian3.normalize(Fc(a,s,a),u),h=this.bo.isIndoor?new e.Cartesian3(0,0,-1.5):new e.Cartesian3(0,0,-(i.height-this.bo.yunjingLayer.getBaseHeight())),this.Kc.Nc(new e.Cartesian3,h),this.Kc.Uc(u,!0)}Pv=new r.Cartographic;qv(){const t=(new Date).getTime(),n=this.Ov.enuCenter;if(!this.Ef.length&&!this.dd?.looking&&this.dd?.dragging&&n){const i=this.bo.viewer.camera,s=r.Cartographic.fromCartesian(i.positionWC,void 0,this.Pv);this.vv.x=this.mv.x,this.vv.y=this.mv.y;const o=this.if(this.mv);if(this.$v){const a=e.Cartesian3.subtract(o,this.$v,this.jv);if(a.x||a.y){this.Sv=e.Cartesian2.multiplyByScalar(a,1e3/(t-this.Mv),this.Sv||new e.Cartesian2);const o=r.Math.toDegrees(s.longitude),u=r.Math.toDegrees(s.latitude),h=r.Cartesian3.fromElements(-a.x,-a.y,0,this.jv);let l=new e.Cartesian3;l=Dc(h,[o,u,s.height],void 0,l);let c=Nc(l);const f=Ic([c.lng,c.lat,s.height],n);if(this.Bv(f,l))i.setView({destination:e.Cartesian3.fromDegrees(c.lng,c.lat,s.height,void 0,l),orientation:{heading:i.heading,pitch:i.pitch,roll:0}});else{const t=this.Lv(Fc(i.positionWC,n),h,f);if(t){const r=Pc(t,n);i.setView({destination:e.Cartesian3.fromRadians(r[0],r[1],s.height,void 0,l),orientation:{heading:i.heading,pitch:i.pitch,roll:0}})}}}else this.Sv=void 0}this.$v=o,this.Mv=t}}Of(){this.Cf=0;const t=this.Ov?.enuCenter;if(t){const n=this.bo.viewer.camera,i=r.Cartographic.fromCartesian(n.positionWC,void 0,this.Pv);if(this.Ef.length||this.dd?.looking){let s=0,o=0,a=0;if(this.Ef.length){const t=(new Date).getTime();if(this.xf&&t-this.xf){let e=(t-this.xf)/1e3*this.bo.speed;this.bo.fixSpeedByHeight&&(e*=Math.max(1.8,i.height-this.bo.yunjingLayer.getBaseHeight())/2);let r=0;switch(this.Ef.sort().join(",")){case"ArrowUp":case"KeyW":r=0;break;case"ArrowDown":case"KeyS":r=180;break;case"ArrowLeft":case"KeyA":r=-90;break;case"ArrowRight":case"KeyD":r=90;break;case"ArrowDown,ArrowLeft":case"KeyA,KeyS":r=-135;break;case"ArrowDown,ArrowRight":case"KeyD,KeyS":r=135;break;case"ArrowLeft,ArrowUp":case"KeyA,KeyW":r=-45;break;case"ArrowRight,ArrowUp":case"KeyD,KeyW":r=45;break;case"KeyQ":r=0,a=1;break;case"KeyE":r=0,a=-1}r=n.heading+r*Math.PI/180,s=Math.sin(r)*e,o=Math.cos(r)*e,a&&(a*=e,s=o=0)}this.xf=t}else this.xf=void 0;let u=0,h=0;const l=this.bo.viewer.canvas,c=l.clientWidth,f=l.clientHeight,d=(this.mv.x-this.vv.x)/c,p=-(this.mv.y-this.vv.y)/f,v=30;u=d*v*Math.PI/180*2,h=p*v*Math.PI/180,"scene"==this.bo.lookingMode&&(u=-u,h=-h),this.vv.x=this.mv.x,this.vv.y=this.mv.y;const m=r.Math.toDegrees(i.longitude),y=r.Math.toDegrees(i.latitude),w=new r.Cartesian3(s,o,a);let g=Dc(w,[m,y,i.height]);const b=Fc(g,t);if(!this.Bv(b,g)){const i=this.Lv(Fc(n.positionWC,t),w,b);if(i){const n=Pc(i,t);e.Cartesian3.fromRadians(n[0],n[1],n[2],void 0,g)}else g.x=n.positionWC.x,g.y=n.positionWC.y,g.z=n.positionWC.z}n.setView({destination:g,orientation:{heading:n.heading+u,pitch:Math.max(-90,Math.min(this.bo.yunjingLayer.getMaxPitch(),n.pitch+h)),roll:0}})}else if(this.dd?.inertiaing&&this.Sv){const s=(new Date).getTime(),o=this.Sv,a=this.Cv,u=this.Av;let h;h=Math.abs(a)>Math.abs(u)?Math.abs(o.x)/Math.abs(a):Math.abs(o.y)/Math.abs(u);let l,c,f=(s-this.Mv)/1e3;if(f>=h&&(f=h),l=o.x*f+.5*a*f*f,c=o.y*f+.5*u*f*f,this.Sv.x=o.x+a*f,this.Sv.y=o.y+u*f,l||c){const s=r.Math.toDegrees(i.longitude),o=r.Math.toDegrees(i.latitude),a=r.Cartesian3.fromElements(-l,-c,0,this.jv);let u=Dc(a,[s,o,i.height],void 0,new e.Cartesian3);const h=Fc(u,t,this.jv);if(!this.Bv(h,u)){const i=this.Lv(Fc(n.positionWC,t),a,h);if(i){const n=Pc(i,t);e.Cartesian3.fromRadians(n[0],n[1],n[2],void 0,u)}else u.x=n.positionWC.x,u.y=n.positionWC.y,u.z=n.positionWC.z}n.setView({destination:u,orientation:{heading:n.heading,pitch:n.pitch,roll:0}})}else this.dd.inertiaing=!1,this.Sv=void 0;this.Mv=s}}this.Cf=requestAnimationFrame(this.Of)}move(t,n,i=!0){t instanceof r.Cartesian3||(t=new r.Cartesian3(t[0],t[1],t[2])),t=r.Cartesian3.normalize(t,t);const s=this.bo.viewer.camera,o=r.Matrix3.fromRotationZ(-s.heading),a=this.Ov.enuCenter;r.Matrix3.multiplyByVector(o,t,t);const u=t.x*n,h=t.y*n,l=t.z*n,c=r.Cartographic.fromCartesian(s.positionWC,void 0,this.Pv),f=r.Math.toDegrees(c.longitude),d=r.Math.toDegrees(c.latitude),p=new r.Cartesian3(u,h,l);let v=Dc(p,[f,d,c.height]);const m=Fc(v,a);if(i&&!this.Bv(m,v)){const t=this.Lv(Fc(s.positionWC,a),p,m);if(!t)return;{const n=Pc(t,a);e.Cartesian3.fromRadians(n[0],n[1],n[2],void 0,v)}}s.setView({destination:v,orientation:{heading:s.heading,pitch:s.pitch,roll:0}})}setMode(t){this.bo.lookingMode=t,this.bv="fixedLine"===this.bo.lookingMode,this.wv.open()}moveByLine(t,e){if(!this.Lf||!this.bv)return;if("forward"===t){if(this.Wf+=e*this.kv,this.Wf=Math.min(this.Wf,this.xv),this.Wf===this.xv)return!0}else if(this.Wf+=e*this.kv,this.Wf=Math.max(this.Wf,0),0===this.Wf)return!0;const{position:n,rotation:i,up:s,dir:o}=this.ld(this.Lf,this.Wf),a=this.bo.viewer.camera;if(n&&s&&o){const t=r.Cartesian3.fromDegrees(n[0],n[1],n[2]);a.flyTo({duration:0,destination:t,orientation:{up:s,direction:o}})}else if(n&&i){const t=r.Cartesian3.fromDegrees(n[0],n[1],n[2]);a.flyTo({duration:0,destination:t,orientation:i})}return!1}Wv(t){if(!this.yv||this.dd.noObstacleAvoidance)return!1;const e=this.bo.buffer;if(this.yv.isCode){const n=this.yv.dis,i=Math.floor((t.x-e)/n),r=Math.floor((t.x+e)/n),s=Math.floor((t.y-e)/n),o=Math.floor((t.y+e)/n),a=Math.floor((t.z-e)/n),u=Math.floor((t.z+e)/n);for(let t=i;t<=r;t+=1)for(let e=s;e<=o;e+=1)for(let n=a;n<=u;n+=1){const i=`${t}_${e}_${n}`;if(this.yv.codes.has(i))return!0}return!1}return this.yv.find(((n,i)=>{const r=t.x;if(r>=n[0]-e&&r<=n[3]+e){const i=t.y;if(i>=n[1]-e&&i<=n[4]+e){const i=t.z;if(i>=n[2]-e&&i<=n[5]+e)return!0}}}))}jv=new e.Cartesian3;Vv=new e.Cartesian3;Bv(t,e){const n=Fc(this.bo.viewer.camera.positionWC,this.Ov.enuCenter,this.Vv),i=this.Iv;if(i){if(this.dd.noObstacleAvoidance)return!0;let e=!1;var r=new Py(t.x,t.y,t.z),s=new Py(t.x,t.y,t.z-1e3),o=new Sw;if(i.world.raycastClosest(r,s,{skipBackfaces:!0},o),o.hasHit&&o.body){const t=i.infos[o.body.index].extrudedHeight;o.distance<t&&(e=!0)}return!!e}return!!this.Wv(n)||!this.Wv(t)}Lv(t,e,n){const i=this.Iv;if(i&&this.Iv){let t,e=1/0;return i.infos.forEach((i=>{const{point:r,distance:s}=Xx.closestPointOnMesh(n,i.mesh.vertices,i.mesh.indices);s<e&&(t=r,e=s)})),t}}ld(t,e){let n=0;const i=this._v;for(let s=1;s<t.length;s++){const o=t[s-1],a=t[s],u=i[s-1],h=i[s],l=1e3*wf({type:"Point",coordinates:o},{type:"Point",coordinates:a},{units:"kilometers"});if(n<=e&&n+l>e){const t=(e-n)/l,c=[o[0]+(a[0]-o[0])*t,o[1]+(a[1]-o[1])*t,o[2]+(a[2]-o[2])*t];return u.up?{position:c,up:new r.Cartesian3(u.up[0]+(h.up[0]-u.up[0])*t,u.up[1]+(h.up[1]-u.up[1])*t,u.up[2]+(h.up[2]-u.up[2])*t),dir:new r.Cartesian3(u.dir[0]+(h.dir[0]-u.dir[0])*t,u.dir[1]+(h.dir[1]-u.dir[1])*t,u.dir[2]+(h.dir[2]-u.dir[2])*t)}:{position:c,rotation:new r.HeadingPitchRoll(i[s-1].rotation[0]+(i[s].rotation[0]-i[s-1].rotation[0])*t,i[s-1].rotation[1]+(i[s].rotation[1]-i[s-1].rotation[1])*t,i[s-1].rotation[2]+(i[s].rotation[2]-i[s-1].rotation[2])*t)}}n+=l}return{}}}class ek extends r.Primitive{framebuffer;clearCommand;textures=[];_scene;Hn;constructor(t){if(super(t),!t.viewer)throw new Error("AMapPrimitive: viewer 属性需要在构造函数中传入!");this.Hn=t.viewer,this._scene=t.viewer.scene,this.An(),this.clearCommand=this.Gv()}update(t){this.In(),super.update()}getTextures(){return{color:this.framebuffer.getColorTexture(0),depth:this.framebuffer.depthTexture}}An(){const{drawingBufferWidth:t,drawingBufferHeight:e}=this._scene.context,n=2*Math.floor(t),i=2*Math.floor(e),s=this._scene.context,o=new r.Texture({context:s,width:n,height:i,pixelFormat:r.PixelFormat.RGBA,pixelDatatype:r.PixelDatatype.UNSIGNED_BYTE}),a=new r.Texture({context:s,width:n,height:i,pixelFormat:r.PixelFormat.DEPTH_COMPONENT,pixelDatatype:r.PixelDatatype.UNSIGNED_INT});this.textures=[o],this.framebuffer&&this.framebuffer.destroy(),this.framebuffer=new r.Framebuffer({context:this._scene.context,colorTextures:this.textures,depthTexture:a}),this.framebuffer.Pn="AMapPrimitive",this.framebuffer.Nn=[n,i]}In(){}Gv(){return new r.ClearCommand({framebuffer:this.framebuffer,color:new r.Color(0,0,0,0),depth:1,stencil:0,pass:r.Pass.OVERLAY})}}class nk extends Il{Ud;qd;jd=[];Os="closed";Bd=[];Ld;Xn=[];Hn;bo;me=!1;Vc;Yv;Kv=[];Xv=-1;Qv;Zv=-1;Jv=[];constructor(t){super(),this.bo={},this.Hn=t,this.Ud=new e.ScreenSpaceEventHandler(t.canvas),this.Vc=[]}tm(t){return this.Kv.find((e=>{const n=e.position?.getValue(r.JulianDate.now());if(n){const e=this.Hn.scene.cartesianToCanvasCoordinates(n);if(r.Cartesian2.distance(t,e)<5)return!0}return!1}))}open(t){const e=this.Hn;if(this.me||(this.Os="open"),!this.Yv||t!=this.Yv){if(this.Gd(),t&&t.polygon){const n=t.polygon?.hierarchy?.getValue(r.JulianDate.now()).positions,i=n.length;r.Cartesian3.equals(n[0],n[i-1])&&n.pop(),this.Vc=n,t.polygon.hierarchy=new r.CallbackProperty((()=>new r.PolygonHierarchy(this.Vc)),!1),t.polyline&&(t.polyline.positions=new r.CallbackProperty((()=>this.Vc),!1)),this.Vc.forEach((t=>{const n=e.entities.add({position:t,point:{pixelSize:10,color:r.Color.YELLOW,outlineColor:r.Color.BLACK,outlineWidth:2,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.Kv.push(n)})),this.Yv=t}else this.Vc=[],this.Yv=e.entities.add({polygon:{hierarchy:new r.CallbackProperty((()=>new r.PolygonHierarchy(this.Vc)),!1),material:new r.Color(0,98/255,254/255,.5),outline:!0,outlineColor:r.Color.WHITE,outlineWidth:2},polyline:{positions:new r.CallbackProperty((()=>this.Vc),!1),material:r.Color.RED}});this.Ud.setInputAction((t=>{const n=e.scene.pickPosition(t.endPosition);n&&(this.Qv&&-1!==this.Zv?(this.Qv.position=n,this.Vc[this.Zv]=n):this.Ld?(this.Ld.position=n,this.Vc[this.Xv]=n):(this.Ld=e.entities.add({position:n,point:{pixelSize:10,color:r.Color.YELLOW,outlineColor:r.Color.BLACK,outlineWidth:2,disableDepthTestDistance:Number.POSITIVE_INFINITY}}),this.Vc.push(n),this.Xv=this.Vc.length-1))}),r.ScreenSpaceEventType.MOUSE_MOVE),this.Ud.setInputAction((t=>{this.Gd()}),r.ScreenSpaceEventType.RIGHT_DOWN),this.Ud.setInputAction((t=>{const n=e.scene.pickPosition(t.position);if(n)if(this.Qv)this.Qv=void 0,this.Zv=-1;else{const i=this.tm(t.position);if(i){this.Ld&&(e.entities.remove(this.Ld),this.Vc.pop()),this.Ld=void 0,this.Xv=-1,this.Qv=i;const t=this.Kv.indexOf(i);t!==this.Kv.length-1&&(this.Kv.unshift(...this.Kv.splice(t+1)),this.Vc.unshift(...this.Vc.splice(t+1))),this.Zv=this.Kv.length-1}else{this.Vc[this.Xv]=n;const t=e.entities.add({position:n,point:{pixelSize:10,color:r.Color.YELLOW,outlineColor:r.Color.BLACK,outlineWidth:2,disableDepthTestDistance:Number.POSITIVE_INFINITY}});this.Kv.push(t),this.Ld&&e.entities.remove(this.Ld),this.Ld=void 0}}}),r.ScreenSpaceEventType.LEFT_CLICK)}}destroy(){this.close(!0),this.Ud.destroy(),this.me=!0}Gd(){if(this.Ld&&(this.Hn.entities.remove(this.Ld),this.Xv=-1,this.Ld=void 0,this.Vc.pop()),this.Qv&&(this.Qv=void 0,this.Zv=-1),this.Yv)return this.Kv.forEach((t=>{this.Hn.entities.remove(t)})),this.Kv=[],this.Vc.length>=3?(this.Vc.push(this.Vc[0]),this.Yv.polygon&&(this.Yv.polygon.hierarchy=this.Yv.polygon.hierarchy?.getValue(r.JulianDate.now()),this.Yv.polygon.material=new r.Color(0,150/255,254/255,.5)),this.Yv.polyline&&(this.Yv.polyline.positions=this.Yv.polyline.positions?.getValue(r.JulianDate.now()),this.Yv.polyline.material=r.Color.GREEN),this.emit("EditComplete",{polygon:this.Yv}),this.Jv.push(this.Yv),this.Vc=[],this.Yv=this.Hn.entities.add({polygon:{hierarchy:new r.CallbackProperty((()=>new r.PolygonHierarchy(this.Vc)),!1),material:new r.Color(0,98/255,254/255,.5)},polyline:{positions:new r.CallbackProperty((()=>this.Vc),!1),material:r.Color.RED}})):this.Vc=[],this.Hn.scene.requestRender(),this.qd}close(t){this.Os="closed",this.Ud.removeInputAction(r.ScreenSpaceEventType.LEFT_CLICK),this.Ud.removeInputAction(r.ScreenSpaceEventType.RIGHT_DOWN),this.Ud.removeInputAction(r.ScreenSpaceEventType.MOUSE_MOVE),this.Gd(),t&&this.clear()}clear(){this.Gd(),this.Ld&&this.Hn.entities.remove(this.Ld),this.Jv.forEach((t=>{this.Hn.entities.remove(t)})),this.Vc=[],this.Hn.scene.requestRender()}}const ik=t=>String.fromCharCode.apply(String,t);function rk(){let t=0,e=0;for(let n=0;n<28;n+=7){let i=this.buf[this.pos++];if(t|=(127&i)<<n,!(128&i))return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(15&n)<<28,e=(112&n)>>4,!(128&n))return this.assertBounds(),[t,e];for(let n=3;n<=31;n+=7){let i=this.buf[this.pos++];if(e|=(127&i)<<n,!(128&i))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}const sk=4294967296;function ok(t){let e="-"==t[0];e&&(t=t.slice(1));const n=1e6;let i=0,r=0;function s(e,s){const o=Number(t.slice(e,s));r*=n,i=i*n+o,i>=sk&&(r+=i/sk|0,i%=sk)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),[e,i,r]}function ak(t,e){if(e<=2097151)return""+(sk*e+t);let n=(t>>>24|e<<8)>>>0&16777215,i=e>>16&65535,r=(16777215&t)+6777216*n+6710656*i,s=n+8147497*i,o=2*i,a=1e7;function u(t,e){let n=t?String(t):"";return e?"0000000".slice(n.length)+n:n}return r>=a&&(s+=Math.floor(r/a),r%=a),s>=a&&(o+=Math.floor(s/a),s%=a),u(o,0)+u(s,o)+u(r,1)}function uk(){let t=this.buf[this.pos++],e=127&t;if(!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<7,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<14,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<21,!(128&t))return this.assertBounds(),e;t=this.buf[this.pos++],e|=(15&t)<<28;for(let e=5;128&t&&e<10;e++)t=this.buf[this.pos++];if(128&t)throw new Error("invalid varint");return this.assertBounds(),e>>>0}const hk=function(){const t=new DataView(new ArrayBuffer(8));return void 0!==globalThis.BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64?{MIN:BigInt("-9223372036854775808"),MAX:BigInt("9223372036854775807"),UMIN:BigInt("0"),UMAX:BigInt("18446744073709551615"),C:BigInt,V:t}:void 0}();function lk(t){if(!t)throw new Error("BigInt unavailable, see https://github.com/timostamm/protobuf-ts/blob/v1.0.8/MANUAL.md#bigint-support")}const ck=/^-?[0-9]+$/,fk=4294967296;class dk{constructor(t,e){this.lo=0|t,this.hi=0|e}isZero(){return 0==this.lo&&0==this.hi}toNumber(){let t=this.hi*fk+(this.lo>>>0);if(!Number.isSafeInteger(t))throw new Error("cannot convert to safe number");return t}}class pk extends dk{static from(t){if(hk)switch(typeof t){case"string":if("0"==t)return this.ZERO;if(""==t)throw new Error("string is no integer");t=hk.C(t);case"number":if(0===t)return this.ZERO;t=hk.C(t);case"bigint":if(!t)return this.ZERO;if(t<hk.UMIN)throw new Error("signed value for ulong");if(t>hk.UMAX)throw new Error("ulong too large");return hk.V.setBigUint64(0,t,!0),new pk(hk.V.getInt32(0,!0),hk.V.getInt32(4,!0))}else switch(typeof t){case"string":if("0"==t)return this.ZERO;if(t=t.trim(),!ck.test(t))throw new Error("string is no integer");let[e,n,i]=ok(t);if(e)throw new Error("signed value");return new pk(n,i);case"number":if(0==t)return this.ZERO;if(!Number.isSafeInteger(t))throw new Error("number is no integer");if(t<0)throw new Error("signed value for ulong");return new pk(t,t/fk)}throw new Error("unknown value "+typeof t)}toString(){return hk?this.toBigInt().toString():ak(this.lo,this.hi)}toBigInt(){return lk(hk),hk.V.setInt32(0,this.lo,!0),hk.V.setInt32(4,this.hi,!0),hk.V.getBigUint64(0,!0)}}pk.ZERO=new pk(0,0);class vk extends dk{static from(t){if(hk)switch(typeof t){case"string":if("0"==t)return this.ZERO;if(""==t)throw new Error("string is no integer");t=hk.C(t);case"number":if(0===t)return this.ZERO;t=hk.C(t);case"bigint":if(!t)return this.ZERO;if(t<hk.MIN)throw new Error("ulong too small");if(t>hk.MAX)throw new Error("ulong too large");return hk.V.setBigInt64(0,t,!0),new vk(hk.V.getInt32(0,!0),hk.V.getInt32(4,!0))}else switch(typeof t){case"string":if("0"==t)return this.ZERO;if(t=t.trim(),!ck.test(t))throw new Error("string is no integer");let[e,n,i]=ok(t),r=new vk(n,i);return e?r.negate():r;case"number":if(0==t)return this.ZERO;if(!Number.isSafeInteger(t))throw new Error("number is no integer");return t>0?new vk(t,t/fk):new vk(-t,-t/fk).negate()}throw new Error("unknown value "+typeof t)}isNegative(){return!!(2147483648&this.hi)}negate(){let t=~this.hi,e=this.lo;return e?e=1+~e:t+=1,new vk(e,t)}toString(){if(hk)return this.toBigInt().toString();if(this.isNegative()){let t=this.negate();return"-"+ak(t.lo,t.hi)}return ak(this.lo,this.hi)}toBigInt(){return lk(hk),hk.V.setInt32(0,this.lo,!0),hk.V.setInt32(4,this.hi,!0),hk.V.getBigInt64(0,!0)}}vk.ZERO=new vk(0,0);class mk{constructor(t){this.varint64=rk,this.uint32=uk,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.uint32(),e=t>>>3,n=7&t;if(e<=0||n<0||n>5)throw new Error("illegal tag: field no "+e+" wire type "+n);return[e,n]}skip(t){let e=this.pos;switch(t){case wk.Bit64:this.pos+=4;case wk.Bit32:this.pos+=4;break;case wk.LengthDelimited:let t=this.uint32();this.pos+=t;break;case wk.Varint:for(;128&this.buf[this.pos++];);}return this.assertBounds(),this.buf.slice(e,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let t=this.uint32();return t>>>1^-(1&t)}int64(){return new vk(...this.varint64())}uint64(){return new pk(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,new vk(t,e)}bool(){let[t,e]=this.varint64();return 0!==t||0!==e}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return new pk(this.sfixed32(),this.sfixed32())}sfixed64(){return new vk(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),e=this.pos;return this.pos+=t,this.assertBounds(),this.buf.slice(e,this.pos)}string(){return function(t){if(t.length<1)return"";let e,n=0,i=[],r=[],s=0,o=t.length;for(;n<o;)e=t[n++],e<128?r[s++]=e:e>191&&e<224?r[s++]=(31&e)<<6|63&t[n++]:e>239&&e<365?(e=((7&e)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,r[s++]=55296+(e>>10),r[s++]=56320+(1023&e)):r[s++]=(15&e)<<12|(63&t[n++])<<6|63&t[n++],s>8191&&(i.push(ik(r)),s=0);return i.length?(s&&i.push(ik(r.slice(0,s))),i.join("")):ik(r.slice(0,s))}(this.bytes())}}var yk,wk;!function(t){t.symbol=Symbol("protobuf-ts/unknown"),t.onRead=(n,i,r,s,o)=>{(e(i)?i[t.symbol]:i[t.symbol]=[]).push({no:r,wireType:s,data:o})},t.onWrite=(e,n,i)=>{for(let{no:e,wireType:r,data:s}of t.list(n))i.tag(e,r).raw(s)},t.list=(n,i)=>{if(e(n)){let e=n[t.symbol];return i?e.filter((t=>t.no==i)):e}return[]},t.last=(e,n)=>t.list(e,n).slice(-1)[0];const e=e=>e&&Array.isArray(e[t.symbol])}(yk||(yk={})),function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"}(wk||(wk={}));var gk=function(t,e){this.x=t,this.y=e},bk=function(t,e){void 0===e&&(e="number"),this.longType=e,this.layers={},this.reader=new mk(t);for(var n=this.reader.len;this.reader.pos<n;){this.reader.uint32();var i=new _k(this.reader,this.reader.uint32()+this.reader.pos,this.longType);i.length&&(this.layers[i.name]=i)}},_k=function(){function t(t,e,n){for(this.reader=t,this.longType=n,this.name="",this.version=0,this.extent=0,this.featureOffsets=[],this.keys=[],this.values=[];t.pos<e;){var i=t.tag(),r=i[0],s=i[1];15==r?this.version=t.uint32():1==r?this.name=t.string():5==r?this.extent=t.uint32():2==r?(this.featureOffsets.push(t.pos),t.skip(s)):3==r?this.keys.push(t.string()):4==r&&this.values.push(this.decodeValue())}this.length=this.featureOffsets.length}var e=t.prototype;return e.feature=function(t){if(t<0||t>=this.featureOffsets.length)throw new Error("out of bounds");this.reader.pos=this.featureOffsets[t];var e=this.reader.uint32()+this.reader.pos;return new xk(this.reader,e,this.keys,this.values,this.extent)},e.decodeValue=function(){for(var t=this.reader,e=t.uint32()+t.pos,n=null;t.pos<e;){var i=t.tag()[0];n=1==i?t.string():2==i?t.float():3==i?t.double():4==i?this.convertLong(t.int64()):5==i?this.convertLong(t.uint64()):6==i?this.convertLong(t.sint64()):7==i?t.bool():null}return n},e.convertLong=function(t){switch(this.longType){case"number":return t.toNumber();case"string":return t.toString();case"bigint":return t.toBigInt()}},t}(),xk=function(){function t(t,e,n,i,r){for(this.reader=t,this.extent=r,this.type=0,this.properties={},this.geometryOffset=0;t.pos<e;){var s=t.tag(),o=s[0],a=s[1];if(1==o)this.id=t.int64().toString();else if(2==o)for(var u=t.uint32()+t.pos;t.pos<u;){var h=n[t.uint32()],l=i[t.uint32()];this.properties[h]=l}else 3==o?this.type=t.uint32():4==o&&(this.geometryOffset=t.pos,t.skip(a))}}var e=t.prototype;return e.loadGeometry=function(){this.reader.pos=this.geometryOffset;for(var t=this.reader.uint32()+this.reader.pos,e=1,n=0,i=0,r=0,s=[],o=null;this.reader.pos<t;){if(n<=0){var a=this.reader.uint32();e=7&a,n=a>>>3}var u;--n,1==e||2==e?(i+=this.reader.sint32(),r+=this.reader.sint32(),1==e&&(o&&s.push(o),o=[]),null==(u=o)||u.push(new gk(i,r))):7==e&&o&&o.push(new gk(o[0].x,o[0].y))}return o&&s.push(o),s},e.bbox=function(){this.reader.pos=this.geometryOffset;for(var t=this.reader.uint32()+this.reader.pos,e=0,n=0,i=0,r=0,s=Number.MAX_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,u=Number.MIN_SAFE_INTEGER;this.reader.pos<t;){if(n<=0){var h=this.reader.uint32();e=7&h,n=h>>>3}--n,1!=e&&2!=e||(i+=this.reader.sint32(),r+=this.reader.sint32(),o=Math.max(i,o),s=Math.min(i,s),u=Math.max(r,u),a=Math.min(r,a))}return[s,a,o,u]},e.toGeoJSON=function(t,e,n){var i,r=this.extent*Math.pow(2,n),s=this.extent*t,o=this.extent*e,a="",u=function(t){return t.map((function(t){var e=180-360*(t.y+o)/r;return[360*(t.x+s)/r-180,360/Math.PI*Math.atan(Math.exp(e*Math.PI/180))-90]}))};switch(this.type){case 1:a="Point",i=u(this.asPoints());break;case 2:a="LineString",i=this.asLines().map((function(t){return u(t)}));break;case 3:a="Polygon",(i=this.asPolygons()).forEach((function(t,e){t.forEach((function(t,n){i[e][n]=u(t)}))}))}1==i.length?i=i[0]:a="Multi"+a;var h={type:"Feature",geometry:{type:a,coordinates:i},properties:this.properties};return null!=this.id&&(h.id=this.id),h},e.asPoints=function(){var t=this.loadGeometry().map((function(t){return t[0]}));return 1==this.type?t:null},e.asLines=function(){return 2==this.type?this.loadGeometry():null},e.asPolygons=function(){return 3==this.type?function(t){var e=t.length;if(e<=1)return[t];for(var n=[],i=null,r=0;r<e;r++){var s,o=kk(t[r]);0!=o&&(o>0?(i&&n.push(i),i=[t[r]]):null==(s=i)||s.push(t[r]))}return i&&n.push(i),n}(this.loadGeometry()):null},t}();function kk(t){for(var e=0,n=0,i=t.length,r=i-1;n<i;r=n++){var s=t[n],o=t[r];e+=(o.x-s.x)*(s.y+o.y)}return e}class $k extends r.UrlTemplateImageryProvider{Hn;Oe;Xd;bo;nm=new Map;im=!0;constructor(t){super({url:t.url}),null==t.cacheSize&&(t.cacheSize=1e3),this.bo=t,this.bo.dataZooms=t.dataZooms||[3,18],this.Hn=t.viewer,this.Oe=t.url,this.Hn.imageryLayers.addImageryProvider(this),this.Hn.scene.postRender.addEventListener(this.$f.bind(this)),this.Xd=new Gc({Hi:t.cacheSize,Bi:(t,e)=>{if(e){const n=t.split("_"),i=this.nm.get(t);return i&&(i.abort({reason:"缓存被删除"}),this.nm.delete(t)),this.bo.customPrimitive.destroyPrimitives({x:+n[0],y:+n[1],level:+n[2]},e),!0}}})}hide(){this.im=!1}show(){this.im=!0}destroy(){this.Hn=void 0,this.Xd.ir(((t,e)=>{const n=e.split("_");this.bo.customPrimitive.destroyPrimitives({x:+n[0],y:+n[1],level:+n[2]},t)}),this),this.Xd.xe()}$f(){if(!this.Hn)return;if(0==this.Hn.scene.globe._surface._tilesToRender.length)return;const t=Math.min(this.bo.dataZooms[1],Math.max(this.bo.dataZooms[0],(this.rm()||10)-2)),e=this.sm(t);if(this.Xd.Wi=Math.max(this.bo.cacheSize||1e3,2*e.length),!e)return;this.om(e),this.am();const n=[],i=[];for(let t=0;t<e.length;t++){const r=e[t],{x:s,y:o,level:a}=r;i.push({x:s,y:o,level:a});const u=this.um(s,o,a);if(this.Xd.ar(this.hm(s,o,a))){const t=this.Xd.nr(this.hm(s,o,a),!1);n.push(t),this.im&&this.bo.customPrimitive.showPrimitives({x:s,y:o,level:a},t)}else this.lm(u,s,o,a)}this.bo.customPrimitive.updatePrimitives(i,n)}requestImage(t,e,n,i){}sm(t){const e=256,n=20037508.34,i=this.Hn;if(!i)return;const s=this.fm(i);if(!s)return null;let{x:o,y:a}=this.dm(t);const u=r.Cartographic.fromRadians(s.west,s.north),h=r.Cartographic.fromRadians(s.east,s.south),l=this.pm(u),c=this.pm(h),f=40075016.68/(Math.pow(2,t)*e),d=Math.floor((l.x+n)/(e*f)),p=Math.floor((c.x+n)/(e*f)),v=Math.floor((n-l.y)/(e*f)),m=Math.floor((n-c.y)/(e*f)),y={xMin:Math.min(d,p),xMax:Math.max(d,p),yMin:Math.min(v,m),yMax:Math.max(v,m),z:t},w=[],g={},b=new Set;for(let e=y.xMin;e<=y.xMax;e++)for(let n=y.yMin;n<=y.yMax;n++){let i=0,r=0;const s=0,u=e>>s,h=n>>s,l=o>>s,c=a>>s;u<l&&l%2!=0&&(i=-1),h<c&&c%2!=0&&(r=-1),u>l&&l%2==0&&(i=1),h>c&&c%2==0&&(r=1);let f=Math.max(Math.abs(u-l+i),Math.abs(h-c-r))+1;const d=Math.max(Math.floor(Math.log(f)/Math.log(4)),0);let p=t-d,v=e>>d,m=n>>d;const y=`${v}_${m}_${p}`;!b.has(y)&&d<=3&&(b.add(y),w.push({x:v,y:m,level:p}),g[p]?g[p].push({x:v,y:m,level:p}):g[p]=[{x:v,y:m,level:p}])}const _=[],x=new Set,k=new Set;w.forEach((t=>{x.add(`${t.x}_${t.y}_${t.level}`),k.add(t.level)}));const $=[];return k.forEach((t=>$.push(t))),$.sort(((t,e)=>e-t)).forEach((t=>{g[t].forEach((t=>{const{x:e,y:n,level:i}=t;this.vm(e,n,i,x)||_.push(t)}))})),_}vm(t,e,n,i){const r=`${t>>1}_${e>>1}_${n-1}`;return!!i.has(r)}fm(t,e=5){const n=t.scene.canvas,i=n.clientWidth,s=n.clientHeight,o=[{x:0,y:s},{x:i,y:s},{x:0,y:0},{x:i,y:0}],a=[];for(const n of o){const i=this.ym(t,n,e);if(i){const e=t.scene.globe.ellipsoid.cartesianToCartographic(i);a.push(e)}}if(0===a.length)return;const u=Math.min(...a.map((t=>r.Math.toDegrees(t.longitude)))),h=Math.max(...a.map((t=>r.Math.toDegrees(t.longitude)))),l=Math.min(...a.map((t=>r.Math.toDegrees(t.latitude)))),c=Math.max(...a.map((t=>r.Math.toDegrees(t.latitude))));return r.Rectangle.fromDegrees(u,l,h,c)}ym(t,e,n=5){let i,s=e.y,o=t.scene.canvas.height;for(let a=0;a<n;a++){const n=(s+o)/2,a=new r.Cartesian2(e.x,n),u=t.camera.pickEllipsoid(a,t.scene.globe.ellipsoid);r.defined(u)?(i=u,o=n):s=n}return i}pm(t){return new r.WebMercatorTilingScheme({ellipsoid:r.Ellipsoid.WGS84}).projection.project(t)}om(t){this.nm.forEach(((e,n)=>{t.some((t=>this.hm(t.x,t.y,t.level)===n))||e.signal.aborted||(this.nm.delete(n),e.abort({reason:"Tile no longer needed"}))}))}am(){this.Xd.ir(((t,e)=>{const n=e.split("_");this.bo.customPrimitive.hidePrimitives({x:+n[0],y:+n[1],level:+n[2]},t)}),this)}async lm(t,e,n,i){const r=this.hm(e,n,i);this.Xd.rr(r,[]);const s=new AbortController,{signal:o}=s;this.nm.set(r,s);try{const s=await fetch(t,{signal:o});if(this.nm.delete(r),200!==s.status)return;const a=await s.arrayBuffer(),u=new bk(new Uint8Array(a));if(0===Object.keys(u.layers).length)return;if(this.Xd.nr(r,!0).length>0)return;const h=this.wm(u,e,n,i),l=this.bo.customPrimitive.createPrimitives({x:e,y:n,level:i},h);this.Xd.rr(r,l),this.im||this.bo.customPrimitive.hidePrimitives({x:e,y:n,level:i},l)}catch(t){const e=this.Xd.nr(r,!0);e&&0===e.length&&this.Xd.ur(r),this.nm.delete(r),t.reason}}wm(t,e,n,i){const r={};for(const s in t.layers){const o=t.layers[s];r[s]=[];for(let t=0;t<o.length;t++){const a=o.feature(t);r[s].push(a.toGeoJSON(e,n,i))}}return r}um(t,e,n){return this.Oe.replace("{x}",t.toString()).replace("{y}",e.toString()).replace("{z}",n.toString())}hm(t,e,n){return`${t}_${e}_${n}`}dm(t){const e=this.Hn;if(!e)return{x:0,y:0};const n=Math.min(-50,r.Math.toDegrees(e.camera.pitch))/-90,i=e.scene.canvas,s=i.clientWidth,o=i.clientHeight/2+n*i.clientHeight/2,a=new r.Cartesian2(s/2,o),u=r.Ellipsoid.WGS84,h=e.scene.camera.pickEllipsoid(a,u);if(!h)return{x:0,y:0};const l=r.Ellipsoid.WGS84.cartesianToCartographic(h),c=this.pm(l);return this.gm(c.x,c.y,t)}gm(t,e,n){const i=20037508.34,r=40075016.68/(256*Math.pow(2,n));return{x:Math.floor((t+i)/(256*r)),y:Math.floor((i-e)/(256*r))}}rm(){const t=this.Hn;if(!t)return;const e=Math.ceil(t.camera.positionCartographic.height);return Math.round(80955.31/(1+Math.pow(e/91610.74,7096758e-11))-40467.74)}}const Sk=Ey.sp,Mk={set baseUrl(t){Ey.op=t},version:Sk,YunJingLayer:Cp,CameraLayer:Np,AMapTerrain:s,AMapSatelliteLayer:o,ENU2ECEF:Dc,ECEF2ENU:Fc,ECEF2LLA:Nc,ENU2LLA:Pc,ModelEntity:qp,ModelAnimationPath:jp,AnimationPath:jp,AMapTraffic:Up,SinglePick:Wc,SinglePlane:Vc,FixedLineViewControl:Lp,CameraAnimation:Wp,CameraAnimationPath:Vp,CameraAnimationStatus:t.CameraAnimationStatus,TrackPoint:Kp,FirstViewControl:Hp,RangingTool:Xp,TrafficHistoryLayer:uv,RoadNetLayer:hv,TrafficLayer:cv,PoiLayer:Cy,BuildingLayer:Ty,MonomerLayer:tf,MonomerDrawLayer:dv,FirstPersonInteraction:tk,LLA2ENU:Ic,TerrainSampler:zy,PlaceSearch:Ay,PolygonEditor:nk,Math:Qx,TileLayer:a,GridVTLayer:$k};window.YunJing=Mk,t.AMapPrimitive=ek,t.AMapSatelliteLayer=o,t.AMapTerrain=s,t.AMapTraffic=Up,t.AnimationPath=jp,t.BuildingLayer=Ty,t.CameraAnimation=Wp,t.CameraAnimationPath=Vp,t.CameraLayer=Np,t.ECEF2ENU=Fc,t.ECEF2LLA=Nc,t.ENU2ECEF=Dc,t.ENU2LLA=Pc,t.FirstPersonInteraction=tk,t.FirstViewControl=Hp,t.FixedLineViewControl=Lp,t.GridVTLayer=$k,t.LLA2ENU=Ic,t.Math=Qx,t.ModelAnimationPath=jp,t.ModelEntity=qp,t.MonomerDrawLayer=dv,t.MonomerLayer=tf,t.PlaceSearch=Ay,t.PoiLayer=Cy,t.PolygonEditor=nk,t.RangingTool=Xp,t.RoadNetLayer=hv,t.SinglePick=Wc,t.SinglePlane=Vc,t.TerrainSampler=zy,t.TileLayer=a,t.TrackPoint=Kp,t.TrafficHistoryLayer=uv,t.TrafficLayer=cv,t.YunJingLayer=Cp,t.version=Sk}({},Cesium);