UNPKG

wcslight

Version:
1 lines 62.7 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("wcslight",[],e):"object"==typeof exports?exports.wcslight=e():t.wcslight=e()}(self,(()=>(()=>{var t,e,i={674:()=>{}},s={};function r(t){var e=s[t];if(void 0!==e)return e.exports;var n=s[t]={exports:{}};return i[t].call(n.exports,n,n.exports,r),n.exports}r.m=i,r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.f={},r.e=t=>Promise.all(Object.keys(r.f).reduce(((e,i)=>(r.f[i](t,e),e)),[])),r.u=t=>t+".js",r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),t={},e="wcslight:",r.l=(i,s,n,a)=>{if(t[i])t[i].push(s);else{var h,o;if(void 0!==n)for(var l=document.getElementsByTagName("script"),d=0;d<l.length;d++){var c=l[d];if(c.getAttribute("src")==i||c.getAttribute("data-webpack")==e+n){h=c;break}}h||(o=!0,(h=document.createElement("script")).charset="utf-8",h.timeout=120,r.nc&&h.setAttribute("nonce",r.nc),h.setAttribute("data-webpack",e+n),h.src=i),t[i]=[s];var p=(e,s)=>{h.onerror=h.onload=null,clearTimeout(u);var r=t[i];if(delete t[i],h.parentNode&&h.parentNode.removeChild(h),r&&r.forEach((t=>t(s))),e)return e(s)},u=setTimeout(p.bind(null,void 0,{type:"timeout",target:h}),12e4);h.onerror=p.bind(null,h.onerror),h.onload=p.bind(null,h.onload),o&&document.head.appendChild(h)}},r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;r.g.importScripts&&(t=r.g.location+"");var e=r.g.document;if(!t&&e&&(e.currentScript&&(t=e.currentScript.src),!t)){var i=e.getElementsByTagName("script");if(i.length)for(var s=i.length-1;s>-1&&(!t||!/^http(s?):/.test(t));)t=i[s--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=t})(),(()=>{var t={434:0,992:0};r.f.j=(e,i)=>{var s=r.o(t,e)?t[e]:void 0;if(0!==s)if(s)i.push(s[2]);else{var n=new Promise(((i,r)=>s=t[e]=[i,r]));i.push(s[2]=n);var a=r.p+r.u(e),h=new Error;r.l(a,(i=>{if(r.o(t,e)&&(0!==(s=t[e])&&(t[e]=void 0),s)){var n=i&&("load"===i.type?"missing":i.type),a=i&&i.target&&i.target.src;h.message="Loading chunk "+e+" failed.\n("+n+": "+a+")",h.name="ChunkLoadError",h.type=n,h.request=a,s[1](h)}}),"chunk-"+e,e)}};var e=(e,i)=>{var s,n,[a,h,o]=i,l=0;if(a.some((e=>0!==t[e]))){for(s in h)r.o(h,s)&&(r.m[s]=h[s]);o&&o(r)}for(e&&e(i);l<a.length;l++)n=a[l],r.o(t,n)&&t[n]&&t[n][0](),t[n]=0},i=self.webpackChunkwcslight=self.webpackChunkwcslight||[];i.forEach(e.bind(null,0)),i.push=e.bind(null,i.push.bind(i))})();var n={};return(()=>{"use strict";r.r(n),r.d(n,{AbstractProjection:()=>u,CoordsType:()=>l,GnomonicProjection:()=>K,HEALPixProjection:()=>W,HiPSHelper:()=>j,HiPSProjection:()=>U,ImagePixel:()=>f,MercatorProjection:()=>D,NumberType:()=>o,Point:()=>S,TestProj:()=>G,WCSLight:()=>q,astroToSpherical:()=>I,cartesianToSpherical:()=>_,degToRad:()=>A,fillAstro:()=>w,fillSpherical:()=>x,radToDeg:()=>y,sphericalToAstro:()=>g,sphericalToCartesian:()=>m});class t{constructor(t,e,i){this._key=void 0!==t?t:void 0,this._value=void 0!==e?e:void 0,this._comment=void 0!==i?i:void 0}get key(){return this._key}get comment(){return this._comment}get value(){return this._value}}class e extends Map{constructor(){super(),this._offset=void 0,this._items=[]}set offset(t){this._offset=t}get offset(){return this._offset}getItemList(){return this._items}getItemListOf(t){const e=[];for(let i=0;i<this._items.length;i++){const s=this._items[i];s.key==t&&e.push(s)}return e}addItemAtTheBeginning(t){void 0!==t.key&&["SIMPLE","BITPIX","NAXIS","NAXIS1","NAXIS2","BLANK","BZERO","BSCALE","DATAMIN","DATAMAX","NPIX","ORDER","CRPIX1","CRPIX2","CDELT1","CDELT2","CRVAL1","CRVAL2"].includes(t.key)&&this.set(t.key,t.value);const e=[t].concat(this._items);this._items=e}addItem(t){void 0!==t.key&&["SIMPLE","BITPIX","NAXIS","NAXIS1","NAXIS2","BLANK","BZERO","BSCALE","DATAMIN","DATAMAX","NPIX","ORDER","CRPIX1","CRPIX2","CDELT1","CDELT2","CRVAL1","CRVAL2"].includes(t.key)&&this.set(t.key,t.value),this._items.push(t)}getNumRows(){return this._items.length}}class i{static getStringAt(t,e,i){const s=[];for(let r=e,n=0;r<e+i;r++,n++)s[n]=String.fromCharCode(255&t.charCodeAt(r));return s.join("")}static byteString(t){if(t<0||t>255||t%1!=0)throw new Error(t+" does not fit in a byte");return("000000000"+t.toString(2)).substr(-8)}static parse32bitSinglePrecisionFloatingPoint(t,e,i,s){let r=(((t<<8)+e<<8)+i<<8)+s;return r<0&&(r+=4294967296),(1+(8388607&r)/8388608)*Math.pow(2,((2139095040&r)>>23)-127)}static convertBlankToBytes(t,e){let i=Math.abs(t).toString(2);for(;i.length/8<e;)i+="0";const s=new ArrayBuffer(e),r=new Uint8Array(s);for(let t=0;t<e;t++)r[t]=parseInt(i.substr(8*t,8*(t+1)),2);return r}static parseFloatingPointFormat(t,e,i){const s=[];for(let e=t.length;e;e-=1){let i=t[e-1];for(let t=8;t;t-=1)s.push(i%2?1:0),i>>=1}s.reverse();const r=s.join(""),n=(1<<e-1)-1,a=parseInt(r.substring(0,1),2)?-1:1,h=parseInt(r.substring(1,1+e),2),o=parseInt(r.substring(1+e),2);return h===(1<<e)-1?0!==o?void 0:a*(1/0):h>0?a*Math.pow(2,h-n)*(1+o/Math.pow(2,i)):0!==o?a*Math.pow(2,-(n-1))*(o/Math.pow(2,i)):0*a}static generate16bit2sComplement(t){throw new TypeError("not implemented yet"+t)}static parse16bit2sComplement(t,e){const i=t<<8|e;return 32768&i?4294901760|i:i}static parse32bit2sComplement(t,e,i,s){const r=t<<24|e<<16|i<<8|s;let n=4294967295&r;return(2147483648&r)>>31?(n=1+(4294967295&~r),-1*n):n}static getByteAt(t,e){return 255&t.charCodeAt(e+0)}static extractPixelValue(t,e,s){let r;if(8==s)r=e[0];else if(16==s)r=i.parse16bit2sComplement(e[t],e[t+1]);else if(32==s)r=i.parse32bit2sComplement(e[t],e[t+1],e[t+2],e[t+3]);else if(-32==s)r=i.parseFloatingPointFormat(e.slice(t,t+8),8,23);else{if(64==s)throw new Error("BITPIX=64 -> 64-bit 2's complement binary integer NOT supported yet.");-64==s&&(r=i.parseFloatingPointFormat(e.slice(t,t+8),11,52))}return r}}class s{constructor(){this._headerArray=new Uint8Array,this._payloadArray=new Array,this._fitsData=new Uint8Array}run(t,e){this.prepareHeader(t),this._payloadArray=e,this.prepareFITS()}prepareHeader(e){const s=new t("END");e.addItem(s);let r="";for(let t=0;t<e.getItemList().length;t++){const i=e.getItemList()[t];let s=this.formatHeaderLine(i);void 0!==s&&(r+=s)}const n=(new TextEncoder).encode(r).length,a=2880*Math.ceil(n/2880);for(let t=0;t<a-n;t++)r+=" ";const h=new ArrayBuffer(r.length);this._headerArray=new Uint8Array(h);for(let t=0;t<r.length;t++)this._headerArray[t]=i.getByteAt(r,t)}formatHeaderLine(t){let e,i=t.key,s=t.value,r=t.comment;if(null!=i){if(e=i,"END"==i){for(let t=80;t>i.length;t--)e+=" ";return e}if("COMMENT"==i||"HISTORY"==i){for(let t=0;t<10-i.length;t++)e+=" ";e+=s;const t=e.length;for(let i=80;i>t;i--)e+=" ";return e}for(let t=0;t<8-i.length;t++)e+=" ";if(e+="= ",null!=s){e+=s,null!=r&&(e+=r);const t=e.length;for(let i=80;i>t;i--)e+=" "}else{null!=r&&(e+=r);const t=e.length;for(let i=80;i>t;i--)e+=" "}}else{e="";for(let t=0;t<18;t++)e+=" ";if(null!=r){e+=r;const t=e.length;for(let i=80;i>t;i--)e+=" "}else{e="";for(let t=80;t>0;t--)e+=" "}}return e}prepareFITS(){const t=new Uint8Array(this._headerArray.length+this._payloadArray[0].length*this._payloadArray.length);t.set(this._headerArray,0);for(let e=0;e<this._payloadArray.length;e++){const i=this._payloadArray[e];t.set(i,this._headerArray.length+e*i.length)}this._fitsData=t}typedArrayToURL(){const t=new Blob([this._fitsData],{type:"application/fits"});return URL.createObjectURL(t)}}class a{constructor(t,e){this._u8data=new Uint8Array,this._BZERO=void 0,this._BSCALE=void 0,this._BLANK=void 0,this._BITPIX=void 0,this._NAXIS1=void 0,this._NAXIS2=void 0,this._DATAMIN=void 0,this._DATAMAX=void 0,this._physicalblank=void 0;const i=e.slice(t.offset);this._u8data=new Uint8Array(i),this.init(t)}init(e){if(this._BZERO=e.get("BZERO"),void 0===this._BZERO&&(this._BZERO=0),this._BSCALE=e.get("BSCALE"),void 0===this._BSCALE&&(this._BSCALE=1),this._BLANK=e.get("BLANK"),this._BITPIX=e.get("BITPIX"),this._NAXIS1=e.get("NAXIS1"),this._NAXIS2=e.get("NAXIS2"),this._DATAMIN=e.get("DATAMIN"),this._DATAMAX=e.get("DATAMAX"),this._physicalblank=void 0,void 0===this._DATAMAX||void 0===this._DATAMIN){const[i,s]=this.computePhysicalMinAndMax();this._DATAMAX=s,this._DATAMIN=i;const r=new t("DATAMAX",s," / computed with FITSParser"),n=new t("DATAMIN",i," / computed with FITSParser");e.addItem(r),e.addItem(n)}}computePhysicalMinAndMax(){let t=0;if(void 0===this._BITPIX)throw new Error("BITPIX is not defined");const e=Math.abs(this._BITPIX/8),i=this._u8data.byteLength/e;let s,r,n,a;for(void 0!==this._BLANK&&(this._physicalblank=this.pixel2physicalValue(this._BLANK));t<i;)s=this.extractPixelValue(e*t),void 0!==s?(r=this.pixel2physicalValue(s),void 0===n&&(n=r),void 0===a&&(a=r),void 0!==this._physicalblank&&this._physicalblank===r||(void 0!==r&&(r<n||void 0===n)&&(n=r),void 0!==r&&(r>a||void 0===a)&&(a=r)),t++):t++;return[n,a]}parse(){if(void 0===this._BITPIX)throw new Error("BITPIX is undefined");if(void 0===this._NAXIS1)throw new Error("NAXIS1 is undefined");if(void 0===this._NAXIS2)throw new Error("NAXIS2 is undefined");const t=Math.abs(this._BITPIX/8);let e=this._u8data.byteLength/t;e=this._NAXIS1*this._NAXIS2;let i,s,r=0;const n=[];for(;r<e;){s=Math.floor(r/this._NAXIS1),i=(r-s*this._NAXIS1)*t,0===i&&(n[s]=new Uint8Array(this._NAXIS1*t));for(let e=0;e<t;e++)n[s][i+e]=this._u8data[r*t+e];r++}return n}extractPixelValue(t){let e;if(16==this._BITPIX)e=i.parse16bit2sComplement(this._u8data[t],this._u8data[t+1]);else if(32==this._BITPIX)e=i.parse32bit2sComplement(this._u8data[t],this._u8data[t+1],this._u8data[t+2],this._u8data[t+3]);else if(-32==this._BITPIX)e=i.parseFloatingPointFormat(this._u8data.slice(t,t+4),8,23);else{if(64==this._BITPIX)throw new Error("BITPIX=64 -> 64-bit 2's complement binary integer NOT supported yet.");-64==this._BITPIX&&(e=i.parseFloatingPointFormat(this._u8data.slice(t,t+8),11,52))}return e}pixel2physicalValue(t){if(void 0===this._BZERO||void 0===this._BSCALE)throw new Error("Either BZERO or BSCALE is undefined");return this._BZERO+this._BSCALE*t}}class h{static parse(i){const s=new TextDecoder("iso-8859-1"),r=new e;let n,a,o,l,d,c,p,u=0,f="";for(c=null;"END"!==f&&i.length>0;){if(a=new Uint8Array(i.slice(80*u,80*u+80)),u++,o=new Uint8Array(a.slice(0,8)),f=s.decode(o).trim(),d=new Uint8Array(a.slice(8,10)),l=new Uint8Array(a.slice(10,80)),n=s.decode(l).trim(),61==d[0]&&32==d[1]){let e=32;for(let t=0;t<l.length;t++)if(32!=l[t]){e=l[t];break}39!=e&&Number(n)?84==e||70==e?p=h.parseLogicalValue(l):(n=s.decode(l).trim(),p=n.includes(".")?h.parseFloatValue(l):h.parseIntValue(l)):p=h.parseLogicalValue(l),c=new t(f,p.val,p.comment)}else if("COMMENT"==f||"HISTORY"==f)c=new t(f,void 0,n);else{let e=32;for(let t=0;t<l.length;t++)if(32!=l[t]){e=l[t];break}47==e?c=new t(void 0,void 0,n):32==e&&(c=new t(void 0,void 0,void 0))}null!=c&&r.addItem(c)}c=new t("COMMENT","FITS generated with FITSParser on ",void 0),r.addItem(c);const _=new Date;c=new t("COMMENT",_.toString()),r.addItem(c);const g=2880*Math.ceil(u/36);return r.offset=g,r}static parseStringValue(t){const e=new TextDecoder("iso-8859-1").decode(t).trim(),i=e.lastIndexOf("/");return{val:e.substring(0,i),comment:e.substring(i)}}static parseLogicalValue(t){const e=new TextDecoder("iso-8859-1").decode(t).trim().split("/");return void 0===e[1]?{val:e[0].trim(),comment:void 0}:{val:e[0].trim(),comment:" /"+e[1]}}static parseIntValue(t){const e=new TextDecoder("iso-8859-1").decode(t).trim().split("/");return void 0===e[1]?{val:parseInt(e[0].trim()),comment:void 0}:{val:parseInt(e[0].trim()),comment:" /"+e[1]}}static parseFloatValue(t){const e=new TextDecoder("iso-8859-1").decode(t).trim().split("/");return void 0===e[1]?{val:parseFloat(e[0].trim()),comment:void 0}:{val:parseFloat(e[0].trim()),comment:" /"+e[1]}}}var o,l,d=function(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{o(s.next(t))}catch(t){n(t)}}function h(t){try{o(s.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,h)}o((s=s.apply(t,e||[])).next())}))};class c{constructor(t){this._url=t}loadFITS(){return d(this,void 0,void 0,(function*(){return this.getFile(this._url).then((t=>{if(null!==t&&t.byteLength>0){const e=new Uint8Array(t);return this.processFits(e)}return null})).catch((t=>{var e,i;if(null===(i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.data)||void 0===i?void 0:i.message)throw new Error("[FITSParser->loadFITS] "+t.response.data.message);throw t}))}))}processFits(t){const e=h.parse(t);return{header:e,data:new a(e,t).parse()}}static generateFITS(t,e){const i=new s;return i.run(t,e),i.typedArrayToURL()}getFile(t){return d(this,void 0,void 0,(function*(){if(t.substring(0,5).toLowerCase().includes("http"))return(yield r.e(911).then(r.bind(r,911))).getFile(t).then((t=>t)).catch((t=>null));{let e=yield r.e(64).then(r.bind(r,64));return yield e.getLocalFile(t)}}))}}class p{constructor(t,e){this._header=t,this._data=e}get header(){return this._header}get data(){return this._data}}class u{constructor(t,e,i=0,s=0,r=0){this._ctype1=t,this._ctype2=e,this._naxis1=i,this._naxis2=s,this._pxsize=r}get naxis1(){return this._naxis1}set naxis1(t){this._naxis1=t}get naxis2(){return this._naxis2}set naxis2(t){this._naxis2=t}get pxsize(){return this._pxsize}set pxsize(t){this._pxsize=t}get ctype1(){return this._ctype1}set ctype1(t){this._ctype1=t}get ctype2(){return this._ctype2}set ctype2(t){this._ctype2=t}generateFITSWithNaN(){if(!this.naxis1||!this.naxis2)throw new Error("NAXIS1 and NAXIS2 must be initialized before generating FITS.");let i=[],s=new e;s.addItemAtTheBeginning(new t("NAXIS1",this.naxis1)),s.addItemAtTheBeginning(new t("NAXIS2",this.naxis2)),s.addItemAtTheBeginning(new t("NAXIS",2)),s.addItemAtTheBeginning(new t("BITPIX","-64")),s.addItemAtTheBeginning(new t("SIMPLE","T")),s.addItem(new t("BSCALE",1)),s.addItem(new t("BZERO",0)),s.addItem(new t("CTYPE1",this.ctype1)),s.addItem(new t("CTYPE2",this.ctype2)),s.addItem(new t("CDELT1",this.pxsize)),s.addItem(new t("CDELT2",this.pxsize)),s.addItem(new t("CRPIX1",this.naxis1/2)),s.addItem(new t("CRPIX2",this.naxis2/2)),s.addItem(new t("CRVAL1",NaN)),s.addItem(new t("CRVAL2",NaN)),s.addItem(new t("ORIGIN","'WCSLight v.0.x'")),s.addItem(new t("COMMENT","'WCSLight v0.x developed by F.Giordano and Y.Ascasibar'")),s.addItem(new t("END")),i.push(s);let r=new Map;r.set(0,new Array(this.naxis2)),r.get(0);for(let t=0;t<this.naxis2;t++)r.get(0)[t]=new Uint8Array(8*this.naxis1),r.get(0)[t].fill(255);return new p(i,r)}computeSquaredNaxes(t,e){this._naxis1=Math.ceil(t/e),this._naxis2=this._naxis1,this._pxsize=e}}class f{constructor(t=null,e=null,i=null){this._i=t,this._j=e,this._tileno=i}geti(){return this._i}getj(){return this._j}get tileno(){return this._tileno}}function _(t){let e=(s=t,(i=t).x*s.x+i.y*s.y+i.z*s.z);var i,s;let r=Math.sqrt(e),n=Math.acos(t[2]/r),a=y(n),h=Math.atan2(t[1],t[0]),o=y(h);return o<0&&(o+=360),{phiDeg:o,thetaDeg:a,phiRad:h,thetaRad:n}}function g(t){let e,i;return e=t.phiDeg,e<0&&(e+=360),i=90-t.thetaDeg,{raDeg:e,decDeg:i,raRad:A(e),decRad:A(i)}}function I(t){let e,i;return e=t.raDeg,e<0&&(e+=360),i=90-t.decDeg,{phiDeg:e,thetaDeg:i,phiRad:A(e),thetaRad:A(i)}}function m(t,e){return{x:(e=null==e?1:e)*Math.sin(t.thetaRad)*Math.cos(t.phiRad),y:e*Math.sin(t.thetaRad)*Math.sin(t.phiRad),z:e*Math.cos(t.thetaRad)}}function w(t,e,i){return i==o.DEGREES?{raDeg:t,decDeg:e,raRad:A(t),decRad:A(e)}:i==o.RADIANS?{raRad:t,decRad:e,raDeg:y(t),decDeg:y(e)}:void console.error("Wrong operation. NumberType "+i+" not supported")}function x(t,e,i){return i==o.DEGREES?{phiDeg:t,thetaDeg:e,phiRad:A(t),thetaRad:A(e)}:i==o.RADIANS?{phiDeg:y(t),thetaDeg:y(e),phiRad:t,thetaRad:e}:void console.error("Wrong operation. NumberType "+i+" not supported")}function A(t){return t/180*Math.PI}function y(t){return 180*t/Math.PI}!function(t){t[t.DEGREES=0]="DEGREES",t[t.RADIANS=1]="RADIANS",t[t.DECIMAL=2]="DECIMAL",t[t.HMS=3]="HMS",t[t.DMS=4]="DMS"}(o||(o={})),function(t){t.CARTESIAN="cartesian",t.SPHERICAL="spherical",t.ASTRO="astro"}(l||(l={}));var v,M,P,E=function(t,e,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(t):s?s.value:e.get(t)},T=function(t,e,i,s,r){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?r.call(t,i):r?r.value=i:e.set(t,i),i};class S{constructor(t,e,...i){v.set(this,void 0),M.set(this,void 0),P.set(this,void 0),t==l.CARTESIAN?(E(this,P,"f").x=parseFloat(i[0].toFixed(r.g.MAX_DECIMALS)),E(this,P,"f").y=parseFloat(i[1].toFixed(r.g.MAX_DECIMALS)),E(this,P,"f").z=parseFloat(i[2].toFixed(r.g.MAX_DECIMALS)),T(this,M,_(E(this,P,"f")),"f"),T(this,v,g(E(this,M,"f")),"f")):t==l.ASTRO?(T(this,v,w(i[0],i[1],e),"f"),T(this,M,I(E(this,v,"f")),"f"),T(this,P,m(E(this,M,"f"),1),"f")):t==l.SPHERICAL?(T(this,M,x(i[0],i[1],e),"f"),T(this,P,m(E(this,M,"f"),1),"f"),T(this,v,g(E(this,M,"f")),"f")):console.error("CoordsType "+t+" not recognised."),E(this,M,"f").phiDeg>360&&(E(this,M,"f").phiDeg-=360),E(this,v,"f").raDeg>360&&(E(this,v,"f").raDeg-=360)}get spherical(){return E(this,M,"f")}get astro(){return E(this,v,"f")}get cartesian(){return E(this,P,"f")}}v=new WeakMap,M=new WeakMap,P=new WeakMap,r(674);var L=function(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{o(s.next(t))}catch(t){n(t)}}function h(t){try{o(s.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,h)}o((s=s.apply(t,e||[])).next())}))};class D extends u{constructor(){super("'RA---CAR'","'DEC--CAR'"),this._wcsname="MER",this._pxvalues=new Map,this._fitsheader=new Array}initFromFile(t){const e=Object.create(null,{naxis1:{get:()=>super.naxis1,set:t=>super.naxis1=t},naxis2:{get:()=>super.naxis2,set:t=>super.naxis2=t},pxsize:{get:()=>super.pxsize,set:t=>super.pxsize=t}});return L(this,void 0,void 0,(function*(){let i=new c(t);this._infile=t,this._fitsUsed.push(t);let s=i.loadFITS().then((t=>{this._pxvalues.set(0,t.data),this._fitsheader[0]=t.header,e.naxis1=t.header.get("NAXIS1"),e.naxis2=t.header.get("NAXIS2"),this._craDeg=t.header.getItemListOf("CRVAL1")[0].value,this._cdecDeg=t.header.getItemListOf("CRVAL2")[0].value;const i=this._fitsheader[0].getItemListOf("CDELT1")[0].value,s=this._fitsheader[0].getItemListOf("CDELT2")[0].value;if(i!==s||void 0===i||void 0===s)throw new Error("pxsize1 is not equal to pxsize2");return e.pxsize=i,this._minra=this._craDeg-e.pxsize*e.naxis1/2,this._minra<0&&(this._minra+=360),this._mindec=this._cdecDeg-e.pxsize*e.naxis2/2,t}));return yield s,s}))}extractPhysicalValues(t){let e=t.header.get("BZERO"),s=t.header.get("BSCALE"),r=t.header.get("NAXIS1"),n=t.header.get("NAXIS2"),a=t.header.get("BITPIX"),h=Math.abs(a/8),o=(i.convertBlankToBytes(t.header.get("BLANK"),h),new Array(n));for(let l=0;l<n;l++){o[l]=new Array(r);for(let n=0;n<r;n++){let r=e+s*i.extractPixelValue(0,t.data[l].slice(n*h,(n+1)*h),a);o[l][n]=r}}return o}prepareFITSHeader(i){this._fitsheader[0]=new e,this._fitsheader[0].addItemAtTheBeginning(new t("NAXIS1",super.naxis1)),this._fitsheader[0].addItemAtTheBeginning(new t("NAXIS2",super.naxis2)),this._fitsheader[0].addItemAtTheBeginning(new t("NAXIS",2)),this._fitsheader[0].addItemAtTheBeginning(new t("BITPIX",i.get("BITPIX"))),this._fitsheader[0].addItemAtTheBeginning(new t("SIMPLE",i.get("SIMPLE"))),void 0!==i.get("BLANK")&&this._fitsheader[0].addItem(new t("BLANK",i.get("BLANK")));let s=1;void 0!==i.get("BSCALE")&&(s=i.get("BSCALE")),this._fitsheader[0].addItem(new t("BSCALE",s));let r=0;void 0!==i.get("BZERO")&&(r=i.get("BZERO")),this._fitsheader[0].addItem(new t("BZERO",r)),this._fitsheader[0].addItem(new t("CTYPE1",super.ctype1)),this._fitsheader[0].addItem(new t("CTYPE2",super.ctype2)),this._fitsheader[0].addItem(new t("CDELT1",super.pxsize)),this._fitsheader[0].addItem(new t("CDELT2",super.pxsize)),this._fitsheader[0].addItem(new t("CRPIX1",super.naxis1/2)),this._fitsheader[0].addItem(new t("CRPIX2",super.naxis2/2)),this._fitsheader[0].addItem(new t("CRVAL1",this._craDeg)),this._fitsheader[0].addItem(new t("CRVAL2",this._cdecDeg));let n=r+s*this._minphysicalval,a=r+s*this._maxphysicalval;return this._fitsheader[0].addItem(new t("DATAMIN",n)),this._fitsheader[0].addItem(new t("DATAMAX",a)),this._fitsheader[0].addItem(new t("ORIGIN","'WCSLight v.0.x'")),this._fitsheader[0].addItem(new t("COMMENT","'WCSLight v0.x developed by F.Giordano and Y.Ascasibar'")),this._fitsheader[0].addItem(new t("END")),this._fitsheader}getFITSHeader(){return this._fitsheader}getCommonFitsHeaderParams(){let i=new e;for(const[e,s]of this._fitsheader[0])["SIMPLE","BITPIX","BSCALE","BZERO","BLANK","ORDER"].includes(e)&&i.addItem(new t(e,s));return i}get fitsUsed(){return this._fitsUsed}getPixValues(t){const e=Object.create(null,{naxis2:{get:()=>super.naxis2},naxis1:{get:()=>super.naxis1}});return L(this,void 0,void 0,(function*(){return new Promise(((s,r)=>{try{let r=Math.abs(this._fitsheader[0].get("BITPIX")/8),n=i.convertBlankToBytes(this._fitsheader[0].get("BLANK"),r),a=t.length,h=new Uint8Array(a*r);for(let i=0;i<a;i++){let s=t[i];if(s._j<0||s._j>=e.naxis2||s._i<0||s._i>=e.naxis1)for(let t=0;t<r;t++)h[i*r+t]=n[t];else{let t=this._pxvalues.get(0);if(void 0!==t)for(let e=0;e<r;e++)h[i*r+e]=t[s._j][s._i*r+e]}}s(h)}catch(t){r("[MercatorProjection] ERROR: "+t)}}))}))}setPxsValue(t,e){let s=Math.abs(e.get("BITPIX")/8),r=i.extractPixelValue(0,t.slice(0,s),e.get("BITPIX")),n=r,a=void 0!==e.get("BSCALE")?e.get("BSCALE"):1,h=void 0!==e.get("BZERO")?e.get("BZERO"):0;this._minphysicalval=h+a*r,this._maxphysicalval=h+a*n,this._pxvalues.set(0,new Array(super.naxis2));let o=this._pxvalues.get(0);if(void 0!==o){for(let t=0;t<super.naxis2;t++)o[t]=new Uint8Array(super.naxis1*s);let r,n,l;for(let d=0;d*s<t.length;d++)try{for(r=Math.floor(d/super.naxis1),n=(d-r*super.naxis1)*s,l=0;l<s;l++)o[r][n+l]=t[d*s+l];let c=h+a*i.extractPixelValue(0,t.slice(d*s,d*s+s),e.get("BITPIX"));c<this._minphysicalval||isNaN(this._minphysicalval)?this._minphysicalval=c:(c>this._maxphysicalval||isNaN(this._maxphysicalval))&&(this._maxphysicalval=c)}catch(e){console.log(e),console.log("p "+d),console.log("r %, c %, b %"+r,n,l),console.log("this._pxvalues[r][c + b] "+o[r][n+l]),console.log("values[p * bytesXelem + b] "+t[d*s+l])}}return this.prepareFITSHeader(e),this._pxvalues}getImageRADecList(t,e,i){super.computeSquaredNaxes(2*e,i),super.pxsize=i,this._minra=t.astro.raDeg-e,this._minra<0&&(this._minra+=360),this._mindec=t.astro.decDeg-e;let s=new Array;for(let t=0;t<super.naxis2;t++)for(let e=0;e<super.naxis1;e++)s.push([this._minra+e*super.pxsize,this._mindec+t*super.pxsize]);let r=super.naxis2/2*super.naxis1+super.naxis1/2;return super.naxis1%2!=0&&(r=Math.floor(s.length/2)),this._craDeg=s[r][0],this._cdecDeg=s[r][1],s}pix2world(t,e){let i,s;return i=t*super.pxsize+this._minra,s=e*super.pxsize+this._mindec,new S(l.ASTRO,o.DEGREES,i,s)}world2pix(t){let e=[];for(let i of t){let t=i[0],s=i[1],r=Math.floor((t-this._minra)/super.pxsize),n=Math.floor((s-this._mindec)/super.pxsize);e.push(new f(r,n))}return e}}class R{}R.halfpi=1.5707963267948966,R.inv_halfpi=2/Math.PI,R.twopi=2*Math.PI,R.inv_twopi=1/(2*Math.PI);class C{constructor(t,e){this.z=t,this.phi=e}}class B{constructor(t){B.PI4_A=.7853981554508209,B.PI4_B=7.946627356147928e-9,B.PI4_C=3061616997868383e-32,B.M_1_PI=.3183098861837907,t&&(this.sth=0,this.have_sth=!1,this.z=B.cos(t.theta),this._phi=t.phi,Math.abs(this.z)>.99&&(this.sth=B.sin(t.theta),this.have_sth=!0))}setZ(t){this.z=t}get phi(){return this._phi}set phi(t){this._phi=t}setSth(t){this.sth=t}toVec3(){var t=this.have_sth?this.sth:Math.sqrt((1-this.z)*(1+this.z));return new b(t*Math.cos(this.phi),t*Math.sin(this.phi),this.z)}toZphi(){return new C(this.z,this.phi)}static sin(t){let e=t*B.M_1_PI,i=Math.floor(e<0?e-.5:e+.5),s=4*i;return t-=s*B.PI4_A,t-=s*B.PI4_B,t-=s*B.PI4_C,1&i&&(t=-t),this.sincoshelper(t)}static cos(t){let e=t*B.M_1_PI-.5,i=1+2*Math.floor(e<0?e-.5:e+.5),s=2*i;return t-=s*B.PI4_A,t-=s*B.PI4_B,t-=s*B.PI4_C,2&i||(t=-t),B.sincoshelper(t)}static sincoshelper(t){let e=t*t,i=-7972559550090379e-33;return i=i*e+2810099727108632e-30,i=i*e-7647122191181588e-28,i=i*e+1.605904306056645e-10,i=i*e-2.5052108376350205e-8,i=i*e+27557319223919875e-22,i=i*e-.00019841269841269616,i=i*e+.00833333333333333,i=i*e-.16666666666666666,e*i*t+t}static asin(t){return B.mulsign(B.atan2k(Math.abs(t),Math.sqrt((1+t)*(1-t))),t)}static acos(t){return B.mulsign(B.atan2k(Math.sqrt((1+t)*(1-t)),Math.abs(t)),t)+(t<0?Math.PI:0)}static mulsign(t,e){return B.copySign(1,e)*t}static copySign(t,e){return e<0?-Math.abs(t):Math.abs(t)}static atanhelper(t){let e=t*t,i=-1887960084630735e-20;return i=i*e+.00020985007664581698,i=i*e-.0011061183148667248,i=i*e+.003700267441887131,i=i*e-.008898961958876555,i=i*e+.016599329773529202,i=i*e-.025451762493231264,i=i*e+.03378525800013531,i=i*e-.04076291912768365,i=i*e+.04666671500778406,i=i*e-.052367485230348246,i=i*e+.05876663929266736,i=i*e-.06665735793610805,i=i*e+.07692195383117696,i=i*e-.09090899500824501,i=i*e+.11111110564826142,i=i*e-.1428571426677133,i=i*e+.19999999999659127,i=i*e-.3333333333333111,i*e*t+t}static atan2k(t,e){let i=0;if(e<0&&(e=-e,i=-2),t>e){let s=e;e=t,t=-s,i+=1}return B.atanhelper(t/e)+i*(Math.PI/2)}static atan2(t,e){let i=B.atan2k(Math.abs(t),e);return i=B.mulsign(i,e),(B.isinf(e)||0==e)&&(i=Math.PI/2-(B.isinf(e)?B.copySign(1,e)*(Math.PI/2):0)),B.isinf(t)&&(i=Math.PI/2-(B.isinf(e)?B.copySign(1,e)*(1*Math.PI/4):0)),0==t&&(i=-1==B.copySign(1,e)?Math.PI:0),B.isnan(e)||B.isnan(t)?NaN:B.mulsign(i,t)}static isnan(t){return t!=t}static isinf(t){return Math.abs(t)===1/0}}B.PI4_A=.7853981554508209,B.PI4_B=7.946627356147928e-9,B.PI4_C=3061616997868383e-32,B.M_1_PI=.3183098861837907;class N{constructor(t,e,i,s){null!=t?(this.theta=B.atan2(Math.sqrt(t.x*t.x+t.y*t.y),t.z),this.phi=e?-B.atan2(t.y,t.x):B.atan2(t.y,t.x),this.phi<0&&(this.phi=this.phi+2*Math.PI),this.phi>=2*Math.PI&&(this.phi=this.phi-2*Math.PI)):(this.theta=i,this.phi=s)}}class b{constructor(t,e,i){if(t instanceof N){let e=t,i=B.sin(e.theta);this.x=i*B.cos(e.phi),this.y=i*B.sin(e.phi),this.z=B.cos(e.theta)}else this.x=t,this.y=e,this.z=i}getX(){return this.x}getY(){return this.y}getZ(){return this.z}scale(t){this.x*=t,this.y*=t,this.z*=t}cross(t){return new b(this.y*t.z-t.y*this.z,this.z*t.x-t.z*this.x,this.x*t.y-t.x*this.y)}add(t){return new b(this.x+t.x,this.y+t.y,this.z+t.z)}normalize(){let t=1/this.length();this.x*=t,this.y*=t,this.z*=t}norm(){let t=1/this.length();return new b(this.x*t,this.y*t,this.z*t)}length(){return Math.sqrt(this.lengthSquared())}lengthSquared(){return this.x*this.x+this.y*this.y+this.z*this.z}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}sub(t){return new b(this.x-t.x,this.y-t.y,this.z-t.z)}angle(t){return B.atan2(this.cross(t).length(),this.dot(t))}flip(){this.x*=-1,this.y*=-1,this.z*=-1}static pointing2Vec3(t){let e=B.sin(t.theta),i=e*B.cos(t.phi),s=e*B.sin(t.phi),r=B.cos(t.theta);return new b(i,s,r)}}class X{constructor(t){let e=t.length;if(e>=2){this.center=t[0].add(t[1]),this.center.normalize(),this.cosrad=t[0].dot(this.center);for(let i=2;i<e;++i)t[i].dot(this.center)<this.cosrad&&this.getCircle(t,i)}else console.log("too few points")}getCircle(t,e){this.center=t[0].add(t[e]),this.center.normalize(),this.cosrad=t[0].dot(this.center);for(let i=1;i<e;++i)t[i].dot(this.center)<this.cosrad&&this.getCircle2(t,i,e)}getCircle2(t,e,i){this.center=t[e].add(t[i]),this.center.normalize(),this.cosrad=t[e].dot(this.center);for(let s=0;s<e;++s)t[s].dot(this.center)<this.cosrad&&(this.center=t[e].sub(t[s]).cross(t[i].sub(t[s])),this.center.normalize(),this.cosrad=t[s].dot(this.center),this.cosrad<0&&(this.center.flip(),this.cosrad=-this.cosrad))}getCenter(){return new b(this.center.x,this.center.y,this.center.z)}getCosrad(){return this.cosrad}}class O{constructor(t,e,i){this.fx=t,this.fy=e,this.face=i,this.jrll=new Uint8Array([2,2,2,2,3,3,3,3,4,4,4,4]),this.jpll=new Uint8Array([1,3,5,7,0,2,4,6,1,3,5,7]),this.halfpi=Math.PI/2}toHploc(){let t,e=new B,i=this.jrll[this.face]-this.fx-this.fy;if(i<1){t=i;let s=t*t/3;e.z=1-s,e.z>.99&&(e.sth=Math.sqrt(s*(2-s)),e.have_sth=!0)}else if(i>3){t=4-i;let s=t*t/3;e.z=s-1,e.z<-.99&&(e.sth=Math.sqrt(s*(2-s)),e.have_sth=!0)}else t=1,e.z=2*(2-i)/3;let s=this.jpll[this.face]*t+this.fx-this.fy;return s<0&&(s+=8),s>=8&&(s-=8),e.phi=t<1e-15?0:.5*this.halfpi*s/t,e}toVec3(){return this.toHploc().toVec3()}}class z{constructor(t){this.p=new Array(t),this.o=new Int32Array(t),this.s=0,this.m=0}push(t,e){this.p[this.s]=t,this.o[this.s]=e,++this.s}pop(){--this.s}popToMark(){this.s=this.m}size(){return this.s}mark(){this.m=this.s}otop(){return this.o[this.s-1]}ptop(){return this.p[this.s-1]}}class H{constructor(t){t<0&&console.error("capacity must be positive"),this.r=new Int32Array(t<<1),this.sz=0}append(t){this.append1(t,t+1)}append1(t,e){if(t>=e)return;if(this.sz>0&&t<=this.r[this.sz-1])return t<this.r[this.sz-2]&&console.error("bad append operation"),void(e>this.r[this.sz-1]&&(this.r[this.sz-1]=e));let i=this.sz+2;if(this.r.length<i){let t=Math.max(2*this.r.length,i),e=new Int32Array(t);e.set(this.r),this.r=e}this.r[this.sz]=t,this.r[this.sz+1]=e,this.sz+=2}ensureCapacity(t){this.r.length<t&&this.resize(Math.max(2*this.r.length,t))}resize(t){if(t<this.sz&&console.error("requested array size too small"),t==this.r.length)return;new Int32Array(t);let e=this.r.slice(0,this.sz+1);this.r=e}}class F{constructor(t,e,i){this.ix=t,this.iy=e,this.face=i}}class V{constructor(t){this.order_max=29,this.inv_halfpi=2/Math.PI,this.twothird=2/3,this.ns_max=Math.pow(2,this.order_max),this.ctab=new Uint16Array([0,1,256,257,2,3,258,259,512,513,768,769,514,515,770,771,4,5,260,261,6,7,262,263,516,517,772,773,518,519,774,775,1024,1025,1280,1281,1026,1027,1282,1283,1536,1537,1792,1793,1538,1539,1794,1795,1028,1029,1284,1285,1030,1031,1286,1287,1540,1541,1796,1797,1542,1543,1798,1799,8,9,264,265,10,11,266,267,520,521,776,777,522,523,778,779,12,13,268,269,14,15,270,271,524,525,780,781,526,527,782,783,1032,1033,1288,1289,1034,1035,1290,1291,1544,1545,1800,1801,1546,1547,1802,1803,1036,1037,1292,1293,1038,1039,1294,1295,1548,1549,1804,1805,1550,1551,1806,1807,2048,2049,2304,2305,2050,2051,2306,2307,2560,2561,2816,2817,2562,2563,2818,2819,2052,2053,2308,2309,2054,2055,2310,2311,2564,2565,2820,2821,2566,2567,2822,2823,3072,3073,3328,3329,3074,3075,3330,3331,3584,3585,3840,3841,3586,3587,3842,3843,3076,3077,3332,3333,3078,3079,3334,3335,3588,3589,3844,3845,3590,3591,3846,3847,2056,2057,2312,2313,2058,2059,2314,2315,2568,2569,2824,2825,2570,2571,2826,2827,2060,2061,2316,2317,2062,2063,2318,2319,2572,2573,2828,2829,2574,2575,2830,2831,3080,3081,3336,3337,3082,3083,3338,3339,3592,3593,3848,3849,3594,3595,3850,3851,3084,3085,3340,3341,3086,3087,3342,3343,3596,3597,3852,3853,3598,3599,3854,3855]),this.utab=new Uint16Array([0,1,4,5,16,17,20,21,64,65,68,69,80,81,84,85,256,257,260,261,272,273,276,277,320,321,324,325,336,337,340,341,1024,1025,1028,1029,1040,1041,1044,1045,1088,1089,1092,1093,1104,1105,1108,1109,1280,1281,1284,1285,1296,1297,1300,1301,1344,1345,1348,1349,1360,1361,1364,1365,4096,4097,4100,4101,4112,4113,4116,4117,4160,4161,4164,4165,4176,4177,4180,4181,4352,4353,4356,4357,4368,4369,4372,4373,4416,4417,4420,4421,4432,4433,4436,4437,5120,5121,5124,5125,5136,5137,5140,5141,5184,5185,5188,5189,5200,5201,5204,5205,5376,5377,5380,5381,5392,5393,5396,5397,5440,5441,5444,5445,5456,5457,5460,5461,16384,16385,16388,16389,16400,16401,16404,16405,16448,16449,16452,16453,16464,16465,16468,16469,16640,16641,16644,16645,16656,16657,16660,16661,16704,16705,16708,16709,16720,16721,16724,16725,17408,17409,17412,17413,17424,17425,17428,17429,17472,17473,17476,17477,17488,17489,17492,17493,17664,17665,17668,17669,17680,17681,17684,17685,17728,17729,17732,17733,17744,17745,17748,17749,20480,20481,20484,20485,20496,20497,20500,20501,20544,20545,20548,20549,20560,20561,20564,20565,20736,20737,20740,20741,20752,20753,20756,20757,20800,20801,20804,20805,20816,20817,20820,20821,21504,21505,21508,21509,21520,21521,21524,21525,21568,21569,21572,21573,21584,21585,21588,21589,21760,21761,21764,21765,21776,21777,21780,21781,21824,21825,21828,21829,21840,21841,21844,21845]),this.jrll=new Int16Array([2,2,2,2,3,3,3,3,4,4,4,4]),this.jpll=new Int16Array([1,3,5,7,0,2,4,6,1,3,5,7]),this.xoffset=new Int16Array([-1,-1,0,1,1,1,0,-1]),this.yoffset=new Int16Array([0,1,1,1,0,-1,-1,-1]),this.facearray=[new Int16Array([8,9,10,11,-1,-1,-1,-1,10,11,8,9]),new Int16Array([5,6,7,4,8,9,10,11,9,10,11,8]),new Int16Array([-1,-1,-1,-1,5,6,7,4,-1,-1,-1,-1]),new Int16Array([4,5,6,7,11,8,9,10,11,8,9,10]),new Int16Array([0,1,2,3,4,5,6,7,8,9,10,11]),new Int16Array([1,2,3,0,0,1,2,3,5,6,7,4]),new Int16Array([-1,-1,-1,-1,7,4,5,6,-1,-1,-1,-1]),new Int16Array([3,0,1,2,3,0,1,2,4,5,6,7]),new Int16Array([2,3,0,1,-1,-1,-1,-1,0,1,2,3])],this.swaparray=[new Int16Array([0,0,3]),new Int16Array([0,0,6]),new Int16Array([0,0,0]),new Int16Array([0,0,5]),new Int16Array([0,0,0]),new Int16Array([5,0,0]),new Int16Array([0,0,0]),new Int16Array([6,0,0]),new Int16Array([3,0,0])],t<=this.ns_max&&t>0&&(this.nside=t,this.npface=this.nside*this.nside,this.npix=12*this.npface,this.order=this.nside2order(this.nside),this.nl2=2*this.nside,this.nl3=3*this.nside,this.nl4=4*this.nside,this.fact2=4/this.npix,this.fact1=(this.nside<<1)*this.fact2,this.ncap=2*this.nside*(this.nside-1)),this.bn=[],this.mpr=[],this.cmpr=[],this.smpr=[]}computeBn(){for(let t=0;t<=this.order_max;++t)this.bn[t]=new V(1<<t),this.mpr[t]=this.bn[t].maxPixrad(),this.cmpr[t]=B.cos(this.mpr[t]),this.smpr[t]=B.sin(this.mpr[t])}getNPix(){return this.npix}getBoundaries(t){let e=new Array,i=this.nest2xyf(t),s=.5/this.nside,r=(i.ix+.5)/this.nside,n=(i.iy+.5)/this.nside;return e[0]=new O(r+s,n+s,i.face).toVec3(),e[1]=new O(r-s,n+s,i.face).toVec3(),e[2]=new O(r-s,n-s,i.face).toVec3(),e[3]=new O(r+s,n-s,i.face).toVec3(),e}getBoundariesWithStep(t,e){let i=new Array,s=this.nest2xyf(t),r=.5/this.nside,n=(s.ix+.5)/this.nside,a=(s.iy+.5)/this.nside,h=1/(this.nside*e);for(let t=0;t<e;t++)i[t]=new O(n+r-t*h,a+r,s.face).toVec3(),i[t+e]=new O(n-r,a+r-t*h,s.face).toVec3(),i[t+2*e]=new O(n-r+t*h,a-r,s.face).toVec3(),i[t+3*e]=new O(n+r,a-r+t*h,s.face).toVec3();return i}getPointsForXyfNoStep(t,e,i){let s=Math.pow(2,this.order),r=new Array,n=new F(t,e,i),a=.5/s,h=(n.ix+.5)/s,o=(n.iy+.5)/s;return r[0]=new O(h+a,o+a,n.face).toVec3(),r[1]=new O(h-a,o+a,n.face).toVec3(),r[2]=new O(h-a,o-a,n.face).toVec3(),r[3]=new O(h+a,o-a,n.face).toVec3(),r}getPointsForXyf(t,e,i,s){let r=i*Math.pow(2,this.order),n=new Array,a=new F(t,e,s),h=.5/r,o=(a.ix+.5)/r,l=(a.iy+.5)/r;return n[0]=new O(o+h,l+h,a.face).toVec3(),n[1]=new O(o-h,l+h,a.face).toVec3(),n[2]=new O(o-h,l-h,a.face).toVec3(),n[3]=new O(o+h,l-h,a.face).toVec3(),n}neighbours(t){let e=new Int32Array(8),i=this.nest2xyf(t),s=i.ix,r=i.iy,n=i.face;var a=this.nside-1;if(s>0&&s<a&&r>0&&r<a){let t=Math.floor(n<<2*this.order),i=this.spread_bits(s),a=this.spread_bits(r)<<1,h=this.spread_bits(s+1),o=this.spread_bits(r+1)<<1,l=this.spread_bits(s-1),d=this.spread_bits(r-1)<<1;e[0]=t+l+a,e[1]=t+l+o,e[2]=t+i+o,e[3]=t+h+o,e[4]=t+h+a,e[5]=t+h+d,e[6]=t+i+d,e[7]=t+l+d}else for(let t=0;t<8;++t){let i=s+this.xoffset[t],a=r+this.yoffset[t],h=4;i<0?(i+=this.nside,h-=1):i>=this.nside&&(i-=this.nside,h+=1),a<0?(a+=this.nside,h-=3):a>=this.nside&&(a-=this.nside,h+=3);let o=this.facearray[h][n];if(o>=0){let s=this.swaparray[h][n>>>2];if((1&s)>0&&(i=Math.floor(this.nside-i-1)),(2&s)>0&&(a=Math.floor(this.nside-a-1)),(4&s)>0){let t=i;i=a,a=t}e[t]=this.xyf2nest(i,a,o)}else e[t]=-1}return e}nside2order(t){return t&t-1?-1:Math.log2(t)}nest2xyf(t){let e=Math.floor(t&this.npface-1);return new F(this.compress_bits(e),this.compress_bits(e>>1),Math.floor(t>>2*this.order))}xyf2nest(t,e,i){return Math.floor(i<<2*this.order)+this.spread_bits(t)+(this.spread_bits(e)<<1)}loc2pix(t){let e,i=t.z,s=t.phi,r=Math.abs(i),n=this.fmodulo(s*this.inv_halfpi,4);if(r<=this.twothird){let t=this.nside*(.5+n),s=this.nside*(.75*i),r=Math.floor(t-s),a=Math.floor(t+s),h=Math.floor(r>>>this.order),o=Math.floor(a>>>this.order),l=Math.floor(h==o?4|h:h<o?h:o+8),d=Math.floor(a&this.nside-1),c=Math.floor(this.nside-(r&this.nside-1)-1);e=this.xyf2nest(d,c,l)}else{let s=Math.min(3,Math.floor(n)),a=n-s,h=r<.99||!t.have_sth?this.nside*Math.sqrt(3*(1-r)):this.nside*t.sth/Math.sqrt((1+r)/3),o=Math.floor(a*h),l=Math.floor((1-a)*h);o>=this.nside&&(o=this.nside-1),l>=this.nside&&(l=this.nside-1),e=i>=0?this.xyf2nest(Math.floor(this.nside-l-1),Math.floor(this.nside-o-1),s):this.xyf2nest(Math.floor(o),Math.floor(l),s+8)}return e}pix2vec(t){return this.pix2loc(t).toVec3()}pix2zphi(t){return this.pix2loc(t).toZphi()}pix2loc(t){let e,i=new B(void 0),s=this.nest2xyf(t),r=(this.jrll[s.face]<<this.order)-s.ix-s.iy-1;if(r<this.nside){e=r;let t=e*e*this.fact2;i.z=1-t,i.z>.99&&(i.sth=Math.sqrt(t*(2-t)),i.have_sth=!0)}else if(r>this.nl3){e=this.nl4-r;let t=e*e*this.fact2;i.z=t-1,i.z<-.99&&(i.sth=Math.sqrt(t*(2-t)),i.have_sth=!0)}else e=this.nside,i.z=(this.nl2-r)*this.fact1;let n=this.jpll[s.face]*e+s.ix-s.iy;return n<0&&(n+=8*e),i.phi=e==this.nside?.75*R.halfpi*n*this.fact1:.5*R.halfpi*n/e,i}ang2pix(t,e){return this.loc2pix(new B(t))}fmodulo(t,e){if(t>=0)return t<e?t:t%e;var i=t%e+e;return i===e?0:i}compress_bits(t){var e=Math.floor(21845&t)|Math.floor((1431633920&t)>>>15);return this.ctab[255&e]|this.ctab[e>>>8]<<4}spread_bits(t){return Math.floor(this.utab[255&t])|Math.floor(this.utab[t>>>8&255]<<16)|Math.floor(this.utab[t>>>16&255]<<32)|Math.floor(this.utab[t>>>24&255]<<48)}queryPolygonInclusive(t,e){let i=0!=e,s=t.length;if(!(s>=3))return void console.log("not enough vertices in polygon");let r=new Array;for(let e=0;e<s;++e)r[e]=b.pointing2Vec3(t[e]);let n=new Array,a=0,h=0,o=!1;for(;h<r.length;){let t=r[h],e=null,i=null;h==r.length-1?(i=r[1],e=r[0]):h==r.length-2?(i=r[0],e=r[h+1]):(e=r[h+1],i=r[h+2]),n[h]=t.cross(e).norm();let s=n[h].dot(i);if(0==h)a=s<0?-1:1,new N(t),o=!1;else{if(a*s<0){new N(e),r.splice(h+1,1),n.splice(h,1),o=!0,h-=1;continue}new N(t),o=!1}n[h].scale(a),h+=1}s=r.length;let l=new Array(i?s+1:s);if(l=l.fill(R.halfpi),i){let t=new X(r);n[s]=t.getCenter(),l[s]=B.acos(t.getCosrad())}return this.queryMultiDisc(n,l,e)}queryMultiDisc(t,e,i){this.computeBn();let s=0!=i,r=t.length;if(r!=e.length)return void console.error("inconsistent input arrays");let n=new H(8),a=0;s&&(Math.pow(2,this.order_max-this.order)>=i||console.error("invalid oversampling factor"),i&i-1&&console.error("oversampling factor must be a power of 2"),a=this.ilog2(i));let h,o,l=this.order+a,d=new Array(l+1);for(h=0;h<=l;++h){d[h]=new Array(r);let t=this.bn[h].maxPixrad();for(o=0;o<r;++o)d[h][o]=new Float64Array(3),d[h][o][0]=e[o]+t>Math.PI?-1:B.cos(e[o]+t),d[h][o][1]=0==h?B.cos(e[o]):d[0][o][1],d[h][o][2]=e[o]-t<0?1:B.cos(e[o]-t)}let c=new z(12+3*l);for(let t=0;t<12;t++)c.push(11-t,0);for(;c.size()>0;){let e=c.ptop(),i=c.otop();c.pop();let a=this.bn[i].pix2vec(e),h=3;for(let e=0;e<r&&h>0;++e){let s=a.dot(t[e]);for(let t=0;t<h;++t)s<d[i][e][t]&&(h=t)}h>0&&this.check_pixel(i,l,h,n,e,c,s)}return n}ilog2(t){let e=Math.max(t,1);return 31-Math.clz32(e)}cosdist_zphi(t,e,i,s){return t*i+B.cos(e-s)*Math.sqrt((1-t*t)*(1-i*i))}check_pixel(t,e,i,s,r,n,a){if(0!=i)if(t<this.order)if(i>=3){let e=2*(this.order-t);s.append1(r<<e,r+1<<e)}else for(let e=0;e<4;++e)n.push(4*r+3-e,t+1);else if(t>this.order)if(i>=2)s.append(r>>>2*(t-this.order)),n.popToMark();else if(t<e)for(let e=0;e<4;++e)n.push(4*r+3-e,t+1);else s.append(r>>>2*(t-this.order)),n.popToMark();else if(i>=2)s.append(r);else if(a)if(this.order<e){n.mark();for(let e=0;e<4;++e)n.push(4*r+3-e,t+1)}else s.append(r)}maxPixrad(){let t=new C(2/3,Math.PI/this.nl4),e=this.convertZphi2xyz(t),i=new b(e[0],e[1],e[2]),s=1-1/this.nside;s*=s;let r=new C(1-s/3,0),n=this.convertZphi2xyz(r),a=new b(n[0],n[1],n[2]);return i.angle(a)}convertZphi2xyz(t){let e=Math.sqrt((1-t.z)*(1+t.z));return[e*B.cos(t.phi),e*B.sin(t.phi),t.z]}queryDiscInclusive(t,e,i){this.computeBn();let s=0!=i,r=new H;if(e>=Math.PI)return r.append1(0,this.npix),r;let n=0;s&&(i&i-1&&console.error("oversampling factor must be a power of 2"),n=this.ilog2(i));let a=Math.min(this.order_max,this.order+n),h=b.pointing2Vec3(t),o=new Array(a+1),l=new Array(a+1),d=B.cos(e),c=B.sin(e);for(let t=0;t<=a;t++){let i=this.mpr[t],s=this.cmpr[t],r=this.smpr[t];o[t]=e+i>Math.PI?-1:d*s-c*r,l[t]=e-i<0?1:d*s+c*r}let p=new z(12+3*a);for(let t=0;t<12;t++)p.push(11-t,0);for(;p.size()>0;){let e=p.ptop(),i=p.otop();p.pop();let n=this.bn[i].pix2zphi(e),c=this.cosdist_zphi(h.z,t.phi,n.z,n.phi);if(c>o[i]){let t=c<d?1:c<=l[i]?2:3;this.check_pixel(i,a,t,r,e,p,s)}}return r}}class j{static computeHiPSOrder(t,e){let i=Math.log2(j.RES_ORDER_0/e/t);return i=Math.round(i),i}static computeHiPSOrder2(t,e){const i=Math.log2(Math.sqrt(Math.PI/3)/(t*e)),s=Math.round(i);return console.warn(i),s}static computeOrder(t,e){console.log(`Computing HiPS order having pixel angular size of ${t} in degrees`);const i=t*(Math.PI/180);console.log(`pixel angular res in radians ${i}`);const s=.5*Math.log2(Math.PI/(3*i*i*e*e));return console.log(`Order ${s}`),s<0?0:Math.floor(s)}static computePxAngularSize(t,e){const i=Math.sqrt(4*Math.PI/(12*Math.pow(t*Math.pow(2,e),2)));console.log(`Computing Pixel size with tile of ${t} pixels and order ${e}`);const s=180/Math.PI,r=i*s,n=i*s*60,a=i*s*3600;return console.log("Pixel size in radiant:"+i),console.log("Pixel size in degrees:"+r),console.log("Pixel size in arcmin:"+n),console.log("Pixel size in arcsec:"+a),{rad:i,deg:r,arcmin:n,arcsec:a}}static computePxSize(t,e){return 1/(e*Math.pow(2,t))*Math.sqrt(Math.PI/3)}static computeBbox(t,e){let i=[];return i.push(new N(null,!1,t.spherical.thetaRad-e,t.spherical.phiRad-e)),i.push(new N(null,!1,t.spherical.thetaRad-e,t.spherical.phiRad+e)),i.push(new N(null,!1,t.spherical.thetaRad+e,t.spherical.phiRad+e)),i.push(new N(null,!1,t.spherical.thetaRad-e,t.spherical.phiRad-e)),i}static setupByTile(t,e){let i={min_y:NaN,max_y:NaN,min_x:NaN,max_x:NaN,gridPointsDeg:[]},s=e.getBoundariesWithStep(t,1),r=[];for(let t=0;t<s.length;t++)if(r[t]=new N(s[t]),t>=1){let e=r[t-1].phi,i=r[t].phi;Math.abs(e-i)>Math.PI&&(r[t-1].phi<r[t].phi?r[t-1].phi+=2*Math.PI:r[t].phi+=2*Math.PI)}for(let t=0;t<r.length;t++){let e=r[t].theta,s=Math.PI/2-e,n=r[t].phi,a=new S(l.ASTRO,o.RADIANS,n,s),h=j.world2intermediate(a.astro);i.gridPointsDeg[2*t]=h[0],i.gridPointsDeg[2*t+1]=h[1],(isNaN(i.max_y)||h[1]>i.max_y)&&(i.max_y=h[1]),(isNaN(i.min_y)||h[1]<i.min_y)&&(i.min_y=h[1]),(isNaN(i.max_x)||h[0]>i.max_x)&&(i.max_x=h[0]),(isNaN(i.min_x)||h[0]<i.min_x)&&(i.min_x=h[0])}return i}static world2intermediate(t){let e,i;if(Math.abs(t.decRad)<=j.THETAX)e=t.raDeg,i=B.sin(t.decRad)*j.K*90/j.H;else if(Math.abs(t.decRad)>j.THETAX){let s=t.raDeg,r=0;(j.K%2!=0||t.decRad>0)&&(r=1);let n=Math.sqrt(j.K*(1-Math.abs(B.sin(t.decRad)))),a=(2*Math.floor((t.raDeg+180)*j.H/360+(1-r)/2)+r)*(180/j.H)-180;e=a+(s-a)*n,i=180/j.H*((j.K+1)/2-n),t.decRad<0&&(i*=-1)}return[e,i]}static intermediate2pix(t,e,i,s){let r,n,a=Math.abs(i.max_x-i.min_x),h=Math.abs(i.max_y-i.min_y);r=(i.min_x>360||i.max_x>360)&&t<i.min_x?(t+360-i.min_x)/a:(t-i.min_x)/a,n=(e-i.min_y)/h;let o=.5-(r-n),l=r+n-.5;return o=Math.floor(o*s),l=Math.floor(l*s),[o,s-l-1]}static pix2intermediate(t,e,i,s,r){let n=s,a=r;s&&(n=s),r&&(a=r);let h=(t+.5)/n,o=(e+.5)/a,l=Math.abs(i.max_x-i.min_x)/2,d=Math.abs(i.max_y-i.min_y)/2,c=(i.max_y+i.min_y)/2;return[i.max_x-l*(h+o),c-d*(o-h)]}static intermediate2world(t,e){let i,s,r=90*(j.K-1)/j.H;if(Math.abs(e)<=r)i=t,s=y(Math.asin(e*j.H/(90*j.K)));else if(Math.abs(e)>r){let r=(j.K+1)/2-Math.abs(e*j.H)/180,n=B.asin(1-r*r/j.K),a=0;(j.K%2!=0||n>0)&&(a=1);let h=(2*Math.floor((t+180)*j.H/360+(1-a)/2)+a)*(180/j.H)-180;i=h+(t-h)/r,s=y(n),e<=0&&(s*=-1)}return new S(l.ASTRO,o.DEGREES,i,s)}}j.DEFAULT_Naxis1_2=512,j.RES_ORDER_0=58.6,j.H=4,j.K=3,j.THETAX=B.asin((j.K-1)/j.K);var k=function(t,e,i,s){return new(i||(i=Promise))((function(r,n){function a(t){try{o(s.next(t))}catch(t){n(t)}}function h(t){try{o(s.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,h)}o((s=s.apply(t,e||[])).next())}))};class U extends u{constructor(){super("'RA---HPX'","'DEC--HPX'"),this._isGalactic=!1,this._fitsUsed=[],this._wcsname="HPX",this._pxvalues=new Map,this._fitsheaderlist=new Array,this._radeclist=new Array}parsePropertiesFile(t){const e=Object.create(null,{naxis1:{get:()=>super.naxis1,set:t=>super.naxis1=t},naxis2:{get:()=>super.naxis2,set:t=>super.naxis2=t}});return k(this,void 0,void 0,(function*(){const i=new c(null).getFile(t+"/properties").then((t=>{let i;i=t instanceof ArrayBuffer?new TextDecoder("iso-8859-1").decode(new Uint8Array(t)):t.toString("utf8");const s=i.split("\n");this._HIPS_TILE_WIDTH=512;for(let t of s){if(!t.includes("="))continue;const i=t.split("=");if(void 0===i[1])continue;const s=i[0].trim(),r=i[1].trim();"hips_order"==s?(this._HIPS_MAX_ORDER=parseInt(r),console.log("hips_order "+this._HIPS_MAX_ORDER)):"hips_tile_width"==s?(this._HIPS_TILE_WIDTH=parseInt(r),e.naxis1=this._HIPS_TILE_WIDTH,e.naxis2=this._HIPS_TILE_WIDTH,console.log("hips_tile_width "+this._HIPS_TILE_WIDTH)):"hips_frame"==s&&"galactic"==r&&(this._isGalactic=!0)}return t}));return yield i,i}))}initFromFile(t){const e=Object.create(null,{naxis1:{get:()=>super.naxis1,set:t=>super.naxis1=t},naxis2:{get:()=>super.naxis2,set:t=>super.naxis2=t}});return k(this,void 0,void 0,(function*(){let i=new c(t).loadFITS().then((t=>{this._pxvalues.set(0,t.data),this._fitsheaderlist[0]=t.header;let i=t.header.get("ORDER");return this.init(i),e.naxis1=t.header.get("NAXIS1"),e.naxis2=t.header.get("NAXIS2"),this._HIPS_TILE_WIDTH=e.naxis1,this._pixno=t.header.get("NPIX"),this._xyGridProj=j.setupByTile(this._pixno,this._hp),t}));return yield i,i}))}initFromHiPSLocationAndPxSize(t,e){const i=Object.create(null,{pxsize:{get:()=>super.pxsize,set:t=>super.pxsize=t}});return k(this,void 0,void 0,(function*(){this._hipsBaseURI=t,i.pxsize=e,void 0===this._HIPS_TILE_WIDTH&&(yield this.parsePropertiesFile(t));let s=j.computeOrder(e,this._HIPS_TILE_WIDTH);s>this._HIPS_MAX_ORDER&&(s=this._HIPS_MAX_ORDER),this.init(s)}))}initFromHiPSLocationAndOrder(t,e){const i=Object.create(null,{pxsize:{get:()=>super.pxsize,set:t=>super.pxsize=t}});return k(this,void 0,void 0,(function*(){this._hipsBaseURI=t,void 0===this._HIPS_TILE_WIDTH&&(yield this.parsePropertiesFile(t)),e>this._HIPS_MAX_ORDER&&(e=this._HIPS_MAX_ORDER),i.pxsize=j.computePxSize(e,this._HIPS_TILE_WIDTH),this.init(e)}))}init(t){this._norder=t,this._nside=Math.pow(2,t),this._hp=new V(this._nside)}prepareFITSHeader(e){for(let i of this._fitsheaderlist){i.addItemAtTheBeginning(new t("BITPIX",e.get("BITPIX"))),i.addItemAtTheBeginning(new t("SIMPLE",e.get("SIMPLE"))),void 0!==e.get("BLANK")&&i.addItem(new t("BLANK",e.get("BLANK")));let s=1;void 0!==e.get("BSCALE")&&(s=e.get("BSCALE"),i.addItem(new t("BSCALE",s)));let r=0;void 0!==e.get("BZERO")&&(r=e.get("BZERO"),i.addItem(new t("BZERO",r))),i.addItem(new t("NAXIS",2)),i.addItem(new t("NAXIS1",j.DEFAULT_Naxis1_2)),i.addItem(new t("NAXIS2",j.DEFAULT_Naxis1_2)),i.addItem(new t("ORDER",this._norder)),i.addItem(new t("CTYPE1",super.ctype1)),i.addItem(new t("CTYPE2",super.ctype2)),i.addItem(new t("ORIGIN","WCSLight v.0.x")),i.addItem(new t("COMMENT","WCSLight v0.x developed by F.Giordano and Y.Ascasibar"))}return this._fitsheaderlist}getFITSHeader(){return this._fitsheaderlist}getCommonFitsHeaderParams(){return this._fh_common}extractPhysicalValues(t){let e=t.header.get("BZERO"),s=t.header.get("BSCALE"),r=t.header.get("NAXIS1"),n=t.header.get("NAXIS2"),a=t.header.get("BITPIX"),h=Math.abs(a/8),o=(i.convertBlankToBytes(t.header.get("BLANK"),h),new Array(n));for(let l=0;l<n;l++){o[l]=new Array(r);for(let n=0;n<r;n++){let r=e+s*i.extractPixelValue(0,t.data[l].slice(n*h,(n+1)*h),a);o[l][n]=r}}return o}getFITSFiles(t,e){return k(this,void 0,void 0,(function*(){const i=new Map;let s=[],r=new Set;t.forEach((t=>{r.add(t.tileno)}));for(let t of r){let r=t,n=1e4*Math.floor(r/1e4),a=this._hipsBaseURI+"/Norder"+this._norder+"/Dir"+n+"/Npix"+r+".fits",h=new c(a);s.push(h.loadFITS().then((t=>{if(null!==t){let s=void 0!==t.header.get("NPIX")?t.header.get("NPIX"):r;i.set(e+"/Npix"+s+".fits",t)}})))}return yield Promise.all(s),i}))}get fitsUsed(){return this._fitsUsed}getPixValues(t){return k(this,void 0,void 0,(function*(){let e=new Set;t.forEach((t=>{e.add(t.tileno)}));let s,r=t.length,n=[],a=[],h=this;for(let o of e){let e=1e4*Math.floor(o/1e4),l=this._hipsBaseURI+"/Norder"+this._norder+"/Dir"+e+"/Npix"+o+".fits";console.log(`Identified source file ${l}`);let d=new c(l);a.push(d.loadFITS().then((e=>{if(null===e)n.push(void 0);else{h._fitsUsed.push(l);let a=Math.abs(e.header.get("BITPIX")/8);i.convertBlankToBytes(e.header.get("BLANK"),a),void 0===s&&(s=new Uint8Array(r*a)),n.push(e.header);for(let i=0;i<r;i++){let r=t[i];if(r.tileno===o&&r._j<e.header.get("NAXIS1")&&r._i<e.header.get("NAXIS2"))for(let t=0;t<a;t++)s[i*a+t]=e.data[r._j][r._i*a+t]}}})))}return yield Promise.all(a),void 0!==n&&this.prepareCommonHeader(n),s}))}prepareCommonHeader(i){if(void 0!==i){this._fh_common||(this._fh_common=new e);for(let e=0;e<i.length;e++){let s=i[e];