UNPKG

weatherlayers-gl

Version:

WeatherLayers GL - Weather Visualization Layers for deck.gl

15 lines (13 loc) 30.9 kB
/*! * Copyright (c) 2021-2026 WeatherLayers.com * * WeatherLayers Cloud Client 2026.5.1 * * A valid access token is required to use the library. Contact support@weatherlayers.com for details. * * Homepage - https://weatherlayers.com/ * Demo - https://demo.weatherlayers.com/ * Docs - https://docs.weatherlayers.com/ * WeatherLayers Cloud Terms of Use - https://weatherlayers.com/terms-of-use.html */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).WeatherLayersClient={})}(this,(function(t){"use strict";const e="2026.5.1",a=new Map;const n=new Map;const r=new class{constructor(){this.queue=Promise.resolve()}async run(t){const e=this.queue;let a;this.queue=new Promise((t=>{a=t}));try{return await e,await t()}finally{a()}}};async function o(t,e){const n=await async function(t){if(a.has(t))return a.get(t);try{if("geotiff"===t)return await import("geotiff")}catch(e){throw new Error(`Optional dependency '${t}' is missing, install it with a package manager or provide with \`setLibrary('${t}', library)\``,{cause:e})}}("geotiff");let r;try{r=await n.fromUrl(t,{allowFullFile:!0,blockSize:Number.MAX_SAFE_INTEGER,fetch:(t,a)=>fetch(t,{...a,headers:{...a?.headers,...e?.headers}})},e?.signal)}catch(e){throw new Error(`Image ${t} can't be decoded.`,{cause:e})}const o=await r.getImage(0),i=await o.readRasters({interleave:!0,signal:e?.signal});if(!(i instanceof Uint8Array||i instanceof Uint8ClampedArray||i instanceof Float32Array))throw new Error("Unsupported data format");const s=function(t,e){if(null==e)return t;const a=t.slice(0);for(let t=0;t<a.length;t++)Math.abs(a[t]-e)<2*Number.EPSILON&&(a[t]=NaN);return a}(i,o.getGDALNoData());return{data:s,width:o.getWidth(),height:o.getHeight()}}function i(t){return async(e,a)=>{if(!1===a?.cache)return t(e);const r=a?.cache??n,o=e+(a?.headers?":"+JSON.stringify(a?.headers):""),i=r.get(o);if(i)return i;const s={...a,cache:void 0},c=t(e,s);return r.set(o,c),c.then((t=>{r.set(o,t)})),c}}const s=i((async(t,e)=>{if(t.includes(".png")||t.includes(".webp")||t.includes("image/png")||t.includes("image/webp"))return async function(t,e){let a;if(e?.headers||e?.signal){const n=await fetch(t,{headers:e.headers,signal:e.signal});if(!n.ok)throw new Error(`URL ${t} can't be loaded. Status: ${n.status}`);const r=await n.blob();a=URL.createObjectURL(r)}const n=new Image;try{await new Promise(((e,r)=>{n.addEventListener("load",e),n.addEventListener("error",r),n.crossOrigin="anonymous",n.src=a??t}))}catch(e){throw new Error(`URL ${t} can't be loaded.`,{cause:e})}finally{a&&URL.revokeObjectURL(a)}try{await r.run((()=>n.decode()))}catch(e){throw new Error(`Image ${t} can't be decoded.`,{cause:e})}const o=document.createElement("canvas");o.width=n.width,o.height=n.height;const i=o.getContext("2d");i.drawImage(n,0,0);const s=i.getImageData(0,0,o.width,o.height),{data:c,width:l,height:f}=s;return{data:c,width:l,height:f}}(t,e);if(t.includes(".tif")||t.includes("image/tif"))return o(t,e);throw new Error("Unsupported data format")})),c=i((async(t,e)=>{const a=await fetch(t,{headers:e?.headers});if(!a.ok)throw new Error(`URL ${t} can't be loaded. Status: ${a.status}`);return a.json()}));function l(t,e,a){if(!e){if(t===a)return 0;throw new Error("Invalid state")}if(a<=t)return 0;if(a>=e)return 1;{const n=new Date(t),r=new Date(e);return(new Date(a).getTime()-n.getTime())/(r.getTime()-n.getTime())}}function f(t,e){return[...t].reverse().find((t=>t<=e))}function u(t,e){return t.find((t=>t>=e))}function h(t,e){const a=new Date(t);return new Date(a.getTime()+1e3*e*60*60).toISOString()}const d={METRIC:"METRIC",METRIC_KILOMETERS:"METRIC_KILOMETERS",IMPERIAL:"IMPERIAL",NAUTICAL:"NAUTICAL"};function g(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var m,p,b,w,y,_,S,D,C,k,v,I,$,E,A,T,L,M;function U(){return p?m:(p=1,m=(t,e=0,a=1)=>t<e?e:t>a?a:t)}function R(){if(w)return b;w=1;const t=U();return b=e=>{e._clipped=!1,e._unclipped=e.slice(0);for(let a=0;a<=3;a++)a<3?((e[a]<0||e[a]>255)&&(e._clipped=!0),e[a]=t(e[a],0,255)):3===a&&(e[a]=t(e[a],0,1));return e},b}function N(){if(_)return y;_=1;const t={};for(let e of["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"])t[`[object ${e}]`]=e.toLowerCase();return y=function(e){return t[Object.prototype.toString.call(e)]||"object"}}function x(){if(D)return S;D=1;const t=N();return S=(e,a=null)=>e.length>=3?Array.prototype.slice.call(e):"object"==t(e[0])&&a?a.split("").filter((t=>void 0!==e[0][t])).map((t=>e[0][t])):e[0]}function O(){if(k)return C;k=1;const t=N();return C=e=>{if(e.length<2)return null;const a=e.length-1;return"string"==t(e[a])?e[a].toLowerCase():null}}function F(){if(I)return v;I=1;const t=Math.PI;return v={clip_rgb:R(),limit:U(),type:N(),unpack:x(),last:O(),PI:t,TWOPI:2*t,PITHIRD:t/3,DEG2RAD:t/180,RAD2DEG:180/t}}function P(){return E?$:(E=1,$={format:{},autodetect:[]})}function j(){if(T)return A;T=1;const{last:t,clip_rgb:e,type:a}=F(),n=P();return A=class{constructor(...r){const o=this;if("object"===a(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];let i=t(r),s=!1;if(!i){s=!0,n.sorted||(n.autodetect=n.autodetect.sort(((t,e)=>e.p-t.p)),n.sorted=!0);for(let t of n.autodetect)if(i=t.test(...r),i)break}if(!n.format[i])throw new Error("unknown format: "+r);{const t=n.format[i].apply(null,s?r:r.slice(0,-1));o._rgb=e(t)}3===o._rgb.length&&o._rgb.push(1)}toString(){return"function"==a(this.hex)?this.hex():`[${this._rgb.join(",")}]`}},A}function z(){if(M)return L;M=1;const t=(...e)=>new t.Color(...e);return t.Color=j(),t.version="@@version",L=t}var q,W,G,H,V,B,J,K,Z,X,Y,Q=g(z()),tt={};function et(){if(H)return G;H=1;const{unpack:t}=F();return G=(...e)=>{e=t(e,"rgba");let[a,n,r]=e;a/=255,n/=255,r/=255;const o=Math.min(a,n,r),i=Math.max(a,n,r),s=(i+o)/2;let c,l;return i===o?(c=0,l=Number.NaN):c=s<.5?(i-o)/(i+o):(i-o)/(2-i-o),a==i?l=(n-r)/(i-o):n==i?l=2+(r-a)/(i-o):r==i&&(l=4+(a-n)/(i-o)),l*=60,l<0&&(l+=360),e.length>3&&void 0!==e[3]?[l,c,s,e[3]]:[l,c,s]}}function at(){if(B)return V;B=1;const{unpack:t,last:e}=F(),a=function(){if(W)return q;W=1;const{unpack:t,last:e}=F(),a=t=>Math.round(100*t)/100;return q=(...n)=>{const r=t(n,"hsla");let o=e(n)||"lsa";return r[0]=a(r[0]||0),r[1]=a(100*r[1])+"%",r[2]=a(100*r[2])+"%","hsla"===o||r.length>3&&r[3]<1?(r[3]=r.length>3?r[3]:1,o="hsla"):r.length=3,`${o}(${r.join(",")})`}}(),n=et(),{round:r}=Math;return V=(...o)=>{const i=t(o,"rgba");let s=e(o)||"rgb";return"hsl"==s.substr(0,3)?a(n(i),s):(i[0]=r(i[0]),i[1]=r(i[1]),i[2]=r(i[2]),("rgba"===s||i.length>3&&i[3]<1)&&(i[3]=i.length>3?i[3]:1,s="rgba"),`${s}(${i.slice(0,"rgb"===s?3:4).join(",")})`)}}function nt(){if(K)return J;K=1;const{unpack:t}=F(),{round:e}=Math;return J=(...a)=>{a=t(a,"hsl");const[n,r,o]=a;let i,s,c;if(0===r)i=s=c=255*o;else{const t=[0,0,0],a=[0,0,0],l=o<.5?o*(1+r):o+r-o*r,f=2*o-l,u=n/360;t[0]=u+1/3,t[1]=u,t[2]=u-1/3;for(let e=0;e<3;e++)t[e]<0&&(t[e]+=1),t[e]>1&&(t[e]-=1),6*t[e]<1?a[e]=f+6*(l-f)*t[e]:2*t[e]<1?a[e]=l:3*t[e]<2?a[e]=f+(l-f)*(2/3-t[e])*6:a[e]=f;[i,s,c]=[e(255*a[0]),e(255*a[1]),e(255*a[2])]}return a.length>3?[i,s,c,a[3]]:[i,s,c,1]}}!function(){if(Y)return tt;Y=1;const t=z(),e=j(),a=P(),{type:n}=F(),r=at(),o=function(){if(X)return Z;X=1;const t=nt(),e=P(),a=/^rgb\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*\)$/,n=/^rgba\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*([01]|[01]?\.\d+)\)$/,r=/^rgb\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/,o=/^rgba\(\s*(-?\d+(?:\.\d+)?)%,\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,i=/^hsl\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*\)$/,s=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,{round:c}=Math,l=l=>{let f;if(l=l.toLowerCase().trim(),e.format.named)try{return e.format.named(l)}catch(t){}if(f=l.match(a)){const t=f.slice(1,4);for(let e=0;e<3;e++)t[e]=+t[e];return t[3]=1,t}if(f=l.match(n)){const t=f.slice(1,5);for(let e=0;e<4;e++)t[e]=+t[e];return t}if(f=l.match(r)){const t=f.slice(1,4);for(let e=0;e<3;e++)t[e]=c(2.55*t[e]);return t[3]=1,t}if(f=l.match(o)){const t=f.slice(1,5);for(let e=0;e<3;e++)t[e]=c(2.55*t[e]);return t[3]=+t[3],t}if(f=l.match(i)){const e=f.slice(1,4);e[1]*=.01,e[2]*=.01;const a=t(e);return a[3]=1,a}if(f=l.match(s)){const e=f.slice(1,4);e[1]*=.01,e[2]*=.01;const a=t(e);return a[3]=+f[4],a}};return l.test=t=>a.test(t)||n.test(t)||r.test(t)||o.test(t)||i.test(t)||s.test(t),Z=l}();e.prototype.css=function(t){return r(this._rgb,t)},t.css=(...t)=>new e(...t,"css"),a.format.css=o,a.autodetect.push({p:5,test:(t,...e)=>{if(!e.length&&"string"===n(t)&&o.test(t))return"css"}})}();var rt,ot,it,st,ct,lt={};function ft(){if(ot)return rt;ot=1;const{unpack:t,last:e}=F(),{round:a}=Math;return rt=(...n)=>{let[r,o,i,s]=t(n,"rgba"),c=e(n)||"auto";void 0===s&&(s=1),"auto"===c&&(c=s<1?"rgba":"rgb"),r=a(r),o=a(o),i=a(i);let l="000000"+(r<<16|o<<8|i).toString(16);l=l.substr(l.length-6);let f="0"+a(255*s).toString(16);switch(f=f.substr(f.length-2),c.toLowerCase()){case"rgba":return`#${l}${f}`;case"argb":return`#${f}${l}`;default:return`#${l}`}}}function ut(){if(st)return it;st=1;const t=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,e=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/;return it=a=>{if(a.match(t)){4!==a.length&&7!==a.length||(a=a.substr(1)),3===a.length&&(a=(a=a.split(""))[0]+a[0]+a[1]+a[1]+a[2]+a[2]);const t=parseInt(a,16);return[t>>16,t>>8&255,255&t,1]}if(a.match(e)){5!==a.length&&9!==a.length||(a=a.substr(1)),4===a.length&&(a=(a=a.split(""))[0]+a[0]+a[1]+a[1]+a[2]+a[2]+a[3]+a[3]);const t=parseInt(a,16);return[t>>24&255,t>>16&255,t>>8&255,Math.round((255&t)/255*100)/100]}throw new Error(`unknown hex color: ${a}`)},it}!function(){if(ct)return lt;ct=1;const t=z(),e=j(),{type:a}=F(),n=P(),r=ft();e.prototype.hex=function(t){return r(this._rgb,t)},t.hex=(...t)=>new e(...t,"hex"),n.format.hex=ut(),n.autodetect.push({p:4,test:(t,...e)=>{if(!e.length&&"string"===a(t)&&[3,4,5,6,7,8,9].indexOf(t.length)>=0)return"hex"}})}();var ht,dt={};function gt(){if(ht)return dt;ht=1;const{unpack:t,type:e}=F(),a=z(),n=j(),r=P(),o=et();return n.prototype.hsl=function(){return o(this._rgb)},a.hsl=(...t)=>new n(...t,"hsl"),r.format.hsl=nt(),r.autodetect.push({p:2,test:(...a)=>{if(a=t(a,"hsl"),"array"===e(a)&&3===a.length)return"hsl"}}),dt}gt();var mt,pt,bt,wt,yt,_t={};function St(){if(pt)return mt;pt=1;const{unpack:t}=F(),{min:e,max:a}=Math;return mt=(...n)=>{n=t(n,"rgb");let[r,o,i]=n;const s=e(r,o,i),c=a(r,o,i),l=c-s;let f,u,h;return h=c/255,0===c?(f=Number.NaN,u=0):(u=l/c,r===c&&(f=(o-i)/l),o===c&&(f=2+(i-r)/l),i===c&&(f=4+(r-o)/l),f*=60,f<0&&(f+=360)),[f,u,h]}}function Dt(){if(yt)return _t;yt=1;const{unpack:t,type:e}=F(),a=z(),n=j(),r=P(),o=St();return n.prototype.hsv=function(){return o(this._rgb)},a.hsv=(...t)=>new n(...t,"hsv"),r.format.hsv=function(){if(wt)return bt;wt=1;const{unpack:t}=F(),{floor:e}=Math;return bt=(...a)=>{a=t(a,"hsv");let n,r,o,[i,s,c]=a;if(c*=255,0===s)n=r=o=c;else{360===i&&(i=0),i>360&&(i-=360),i<0&&(i+=360),i/=60;const t=e(i),a=i-t,l=c*(1-s),f=c*(1-s*a),u=c*(1-s*(1-a));switch(t){case 0:[n,r,o]=[c,u,l];break;case 1:[n,r,o]=[f,c,l];break;case 2:[n,r,o]=[l,c,u];break;case 3:[n,r,o]=[l,f,c];break;case 4:[n,r,o]=[u,l,c];break;case 5:[n,r,o]=[c,l,f]}}return[n,r,o,a.length>3?a[3]:1]}}(),r.autodetect.push({p:2,test:(...a)=>{if(a=t(a,"hsv"),"array"===e(a)&&3===a.length)return"hsv"}}),_t}Dt();var Ct,kt,vt,It={};!function(){if(vt)return It;vt=1;const t=j(),e=P(),{type:a}=F(),n=kt?Ct:(kt=1,Ct={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflower:"#6495ed",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",maroon2:"#7f0000",maroon3:"#b03060",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",purple2:"#7f007f",purple3:"#a020f0",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"}),r=ut(),o=ft();t.prototype.name=function(){const t=o(this._rgb,"rgb");for(let e of Object.keys(n))if(n[e]===t)return e.toLowerCase();return t},e.format.named=t=>{if(t=t.toLowerCase(),n[t])return r(n[t]);throw new Error("unknown color name: "+t)},e.autodetect.push({p:5,test:(t,...e)=>{if(!e.length&&"string"===a(t)&&n[t.toLowerCase()])return"named"}})}();var $t,Et={};!function(){if($t)return Et;$t=1;const t=z(),e=j(),a=P(),{unpack:n,type:r}=F(),{round:o}=Math;e.prototype.rgb=function(t=!0){return!1===t?this._rgb.slice(0,3):this._rgb.slice(0,3).map(o)},e.prototype.rgba=function(t=!0){return this._rgb.slice(0,4).map(((e,a)=>a<3?!1===t?e:o(e):e))},t.rgb=(...t)=>new e(...t,"rgb"),a.format.rgb=(...t)=>{const e=n(t,"rgba");return void 0===e[3]&&(e[3]=1),e},a.autodetect.push({p:3,test:(...t)=>{if(t=n(t,"rgba"),"array"===r(t)&&(3===t.length||4===t.length&&"number"==r(t[3])&&t[3]>=0&&t[3]<=1))return"rgb"}})}();var At,Tt,Lt,Mt,Ut,Rt,Nt,xt,Ot,Ft,Pt,jt,zt,qt={};function Wt(){if(Lt)return Tt;Lt=1;const t=j();return Tt=(e,a,n,r)=>{let o,i,s,c,l,f,u,h,d,g,m,p;return"hsl"===r?(o=e.hsl(),i=a.hsl()):"hsv"===r?(o=e.hsv(),i=a.hsv()):"hcg"===r?(o=e.hcg(),i=a.hcg()):"hsi"===r?(o=e.hsi(),i=a.hsi()):"lch"===r||"hcl"===r?(r="hcl",o=e.hcl(),i=a.hcl()):"oklch"===r&&(o=e.oklch().reverse(),i=a.oklch().reverse()),"h"!==r.substr(0,1)&&"oklch"!==r||([s,l,u]=o,[c,f,h]=i),isNaN(s)||isNaN(c)?isNaN(s)?isNaN(c)?g=Number.NaN:(g=c,1!=u&&0!=u||"hsv"==r||(d=f)):(g=s,1!=h&&0!=h||"hsv"==r||(d=l)):(p=c>s&&c-s>180?c-(s+360):c<s&&s-c>180?c+360-s:c-s,g=s+n*p),void 0===d&&(d=l+n*(f-l)),m=u+n*(h-u),new t("oklch"===r?[m,d,g]:[g,d,m],r)}}function Gt(){return Ut?Mt:(Ut=1,Mt={})}!function(){if(At)return qt;At=1;const t=j(),{type:e}=F();t.prototype.alpha=function(a,n=!1){return void 0!==a&&"number"===e(a)?n?(this._rgb[3]=a,this):new t([this._rgb[0],this._rgb[1],this._rgb[2],a],"rgb"):this._rgb[3]}}(),function(){if(Nt)return Rt;Nt=1,gt();const t=Wt(),e=(e,a,n)=>t(e,a,n,"hsl");Gt().hsl=e,Rt=e}(),function(){if(Ot)return xt;Ot=1,Dt();const t=Wt(),e=(e,a,n)=>t(e,a,n,"hsv");Gt().hsv=e,xt=e}(),function(){if(Pt)return Ft;Pt=1;const t=j(),e=(e,a,n)=>{const r=e._rgb,o=a._rgb;return new t(r[0]+n*(o[0]-r[0]),r[1]+n*(o[1]-r[1]),r[2]+n*(o[2]-r[2]),"rgb")};Gt().rgb=e,Ft=e}();var Ht,Vt,Bt=function(){if(zt)return jt;zt=1;const t=j(),{type:e}=F(),a=Gt();return jt=(n,r,o=.5,...i)=>{let s=i[0]||"lrgb";if(a[s]||i.length||(s=Object.keys(a)[0]),!a[s])throw new Error(`interpolation mode ${s} is not defined`);return"object"!==e(n)&&(n=new t(n)),"object"!==e(r)&&(r=new t(r)),a[s](n,r,o).alpha(n.alpha()+o*(r.alpha()-n.alpha()))}}(),Jt=g(Bt);var Kt=function(){if(Vt)return Ht;Vt=1;const t=z(),{type:e}=F(),{pow:a}=Math;return Ht=function(n){let r="rgb",o=t("#ccc"),i=0,s=[0,1],c=[],l=[0,0],f=!1,u=[],h=!1,d=0,g=1,m=!1,p={},b=!0,w=1;const y=function(a){if((a=a||["#fff","#000"])&&"string"===e(a)&&t.brewer&&t.brewer[a.toLowerCase()]&&(a=t.brewer[a.toLowerCase()]),"array"===e(a)){1===a.length&&(a=[a[0],a[0]]),a=a.slice(0);for(let e=0;e<a.length;e++)a[e]=t(a[e]);c.length=0;for(let t=0;t<a.length;t++)c.push(t/(a.length-1))}return C(),u=a};let _=t=>t,S=t=>t;const D=function(n,i){let s,h;if(null==i&&(i=!1),isNaN(n)||null===n)return o;if(i)h=n;else if(f&&f.length>2){h=function(t){if(null!=f){const e=f.length-1;let a=0;for(;a<e&&t>=f[a];)a++;return a-1}return 0}(n)/(f.length-2)}else h=g!==d?(n-d)/(g-d):1;h=S(h),i||(h=_(h)),1!==w&&(h=a(h,w)),h=l[0]+h*(1-l[0]-l[1]),h=Math.min(1,Math.max(0,h));const m=Math.floor(1e4*h);if(b&&p[m])s=p[m];else{if("array"===e(u))for(let e=0;e<c.length;e++){const a=c[e];if(h<=a){s=u[e];break}if(h>=a&&e===c.length-1){s=u[e];break}if(h>a&&h<c[e+1]){h=(h-a)/(c[e+1]-a),s=t.interpolate(u[e],u[e+1],h,r);break}}else"function"===e(u)&&(s=u(h));b&&(p[m]=s)}return s};var C=()=>p={};y(n);const k=function(e){const a=t(D(e));return h&&a[h]?a[h]():a};return k.classes=function(a){if(null!=a){if("array"===e(a))f=a,s=[a[0],a[a.length-1]];else{const e=t.analyze(s);f=0===a?[e.min,e.max]:t.limits(e,"e",a)}return k}return f},k.domain=function(t){if(!arguments.length)return s;d=t[0],g=t[t.length-1],c=[];const e=u.length;if(t.length===e&&d!==g)for(let e of Array.from(t))c.push((e-d)/(g-d));else{for(let t=0;t<e;t++)c.push(t/(e-1));if(t.length>2){const e=t.map(((e,a)=>a/(t.length-1))),a=t.map((t=>(t-d)/(g-d)));a.every(((t,a)=>e[a]===t))||(S=t=>{if(t<=0||t>=1)return t;let n=0;for(;t>=a[n+1];)n++;const r=(t-a[n])/(a[n+1]-a[n]);return e[n]+r*(e[n+1]-e[n])})}}return s=[d,g],k},k.mode=function(t){return arguments.length?(r=t,C(),k):r},k.range=function(t,e){return y(t),k},k.out=function(t){return h=t,k},k.spread=function(t){return arguments.length?(i=t,k):i},k.correctLightness=function(t){return null==t&&(t=!0),m=t,C(),_=m?function(t){const e=D(0,!0).lab()[0],a=D(1,!0).lab()[0],n=e>a;let r=D(t,!0).lab()[0];const o=e+(a-e)*t;let i=r-o,s=0,c=1,l=20;for(;Math.abs(i)>.01&&l-- >0;)n&&(i*=-1),i<0?(s=t,t+=.5*(c-t)):(c=t,t+=.5*(s-t)),r=D(t,!0).lab()[0],i=r-o;return t}:t=>t,k},k.padding=function(t){return null!=t?("number"===e(t)&&(t=[t,t]),l=t,k):l},k.colors=function(e,a){arguments.length<2&&(a="hex");let r=[];if(0===arguments.length)r=u.slice(0);else if(1===e)r=[k(.5)];else if(e>1){const t=s[0],a=s[1]-t;r=function(t,e,a){let n=[],r=t<e,o=e;for(let e=t;r?e<o:e>o;r?e++:e--)n.push(e);return n}(0,e).map((n=>k(t+n/(e-1)*a)))}else{n=[];let t=[];if(f&&f.length>2)for(let e=1,a=f.length,n=1<=a;n?e<a:e>a;n?e++:e--)t.push(.5*(f[e-1]+f[e]));else t=s;r=t.map((t=>k(t)))}return t[a]&&(r=r.map((t=>t[a]()))),r},k.cache=function(t){return null!=t?(b=t,k):b},k.gamma=function(t){return null!=t?(w=t,k):w},k.nodata=function(e){return null!=e?(o=t(e),k):o},k},Ht}(),Zt=g(Kt);Q.mix=Q.interpolate=Jt,Q.scale=Zt;const Xt=/[ ,\t:]+/g,Yt=/[\-\/]/g;function Qt(t){return t.startsWith("#")}function te(t){const e=t.split(Yt);return 1===e.length?e[0]:e}function ee(t){const e=t.trim().split("\n"),a=function(t){return t.some((t=>!Qt(t)&&t.split(Xt).length>=8))}(e),n=function(t){return t.some((t=>!(Qt(t)||!t.match(/\d+\-\d+\-\d+/)&&!t.match(/\d+\/\d+\/\d+/))))}(e),r=function(t){const e=t.find((t=>Qt(t)&&t.includes("COLOR_MODEL = ")));if(e){const t=e.match(/COLOR_MODEL = ([a-zA-Z]+)/);if(t)return t[1].toLowerCase()}}(e),o=e.filter((t=>!!t&&!t.startsWith("#"))),i=[];for(let t of o){const e=t.split(Xt);a?8===e.length||9===e.length?(i.push([e[0],[e[1],e[2],e[3]]]),i.push([e[4],[e[5],e[6],e[7]]])):4!==e.length&&5!==e.length||i.push([e[0],[e[1],e[2],e[3]]]):n?4===e.length||5===e.length?(i.push([e[0],te(e[1])]),i.push([e[2],te(e[3])])):2!==e.length&&3!==e.length||i.push([e[0],te(e[1])]):5===e.length?i.push([e[0],[e[1],e[2],e[3],e[4]]]):4===e.length?i.push([e[0],[e[1],e[2],e[3]]]):2===e.length&&i.push([e[0],e[1]])}return{paletteArray:i,mode:r}}const ae="rgb";function ne(t,e){if("string"==typeof t){if("%"===t[t.length-1]){const a=parseFloat(t)/100;if(a<0||a>1)throw new Error(`Invalid value for a percentage ${t}`);return e[0]+(e[1]-e[0])*a}return"N"===t?null:"B"===t||"F"===t?void 0:"nv"===t?null:"default"===t?void 0:"null"===t||"nodata"===t?null:parseFloat(t)}if("number"==typeof t)return t;throw new Error("Invalid state")}function re(t,e){if(Array.isArray(t)){if(4===t.length)return{[e[0]]:parseFloat(t[0].toString()),[e[1]]:parseFloat(t[1].toString()),[e[2]]:parseFloat(t[2].toString()),a:parseFloat(t[3].toString())/255};if(3===t.length)return{[e[0]]:parseFloat(t[0].toString()),[e[1]]:parseFloat(t[1].toString()),[e[2]]:parseFloat(t[2].toString())};throw new Error(`Invalid color ${t}`)}if("string"==typeof t||"number"==typeof t)return t.toString().match(/^\d+$/)||"number"==typeof t?{[e[0]]:parseFloat(t.toString()),[e[1]]:parseFloat(t.toString()),[e[2]]:parseFloat(t.toString())}:t;throw new Error(`Invalid color ${t}`)}function oe(t,{bounds:e=[0,1],mode:a=ae}={}){const n=[],r=[];let o;for(let[i,s]of t){const t=ne(i,e),c=re(s,a);null!=t?(n.push(c),r.push(t)):null===t&&(o=c)}let i=Q.scale(n).domain(r).mode(a);return void 0!==o&&(i=i.nodata(o)),i}const ie="producer",se="processor",ce="item",le="data",fe="search",ue="palette",he=d.METRIC;function de(t,e){const a=t.providers.find((t=>t.roles.includes(ie))),n=t.providers.find((t=>t.roles.includes(se)));return[...a?[`<a href="${a.url}"${e?` class="${e}"`:""}>${a.name}</a>`]:[],...n?[`<a href="${n.url}"${e?` class="${e}"`:""}>${n.name}</a>`]:[]].join(" via ")}function ge(t,e){const a=t["weatherLayers:units"],n=a.find((t=>t.system===e))??a.find((t=>t.system===he))??a[0],{unit:r,scale:o,offset:i,decimals:s}=n;return{unit:r,scale:o,offset:i,decimals:s}}t.Client=class{constructor(t){this._cache=new Map,this._datasetStacCollectionCache=new Map,this._datasetDataStacItemCache=new Map,this._config=t}getConfig(){return{...this._config}}setConfig(t){this._config=t}updateConfig(t){this.setConfig({...this._config,...t})}_getAuthenticatedUrl(t,a={}){const n=a.accessToken??this._config.accessToken??null,r=new URL(t);return r.searchParams.has("access_token")||null==n||r.searchParams.set("access_token",n),r.searchParams.has("version")||r.searchParams.set("version",e),r.toString()}_cacheDatasetStacCollection(t){this._datasetStacCollectionCache.set(t.id,t)}_cacheDatasetDataStacItem(t,e){this._datasetDataStacItemCache.has(t)||this._datasetDataStacItemCache.set(t,new Map),this._datasetDataStacItemCache.get(t).set(e.properties.datetime,e)}async _loadStacCatalog(t={}){const e=t.url??this._config.url??"https://catalog.weatherlayers.com",a=this._getAuthenticatedUrl(`${e}/catalog`,t);return await c(a,{cache:this._cache})}async _loadDatasetStacCollections(t={}){const e=(await this._loadStacCatalog(t)).links.find((t=>t.rel===le));if(!e)throw new Error("STAC Catalog data link not found");const a=this._getAuthenticatedUrl(e.href,t),n=(await c(a,{cache:this._cache})).collections;for(const t of n)this._cacheDatasetStacCollection(t);return n}async _loadDatasetStacCollection(t,e={}){await this._loadDatasetStacCollections(e);let a=this._datasetStacCollectionCache.get(t);if(!a)throw new Error(`STAC Collection ${t} not found`);return this._cacheDatasetStacCollection(a),a}async _loadDatasetStacCollectionPalette(t,e={}){const a=await this._loadDatasetStacCollection(t,e),n=Object.values(a.assets??{}).find((t=>t.roles.includes(ue)&&"application/json"===t.type));if(!n)throw new Error(`STAC Collection ${t} palette asset not found`);const r=this._getAuthenticatedUrl(n.href,this._config);return await c(r,{cache:this._cache})}async _searchDatasetDataStacItems(t,e,a,n={}){const r=(await this._loadStacCatalog(n)).links.find((t=>t.rel===fe));if(!r)throw new Error("STAC Catalog search link not found");const o=new URL(r.href);o.searchParams.set("collections",t),o.searchParams.set("datetime",function(t){if(Array.isArray(t)&&2===t.length){const[e,a]=t;return`${e??".."}/${a??".."}`}throw new Error("Invalid datetime range")}(e)),"number"==typeof a&&a>1&&o.searchParams.set("datetime_step",`${a}`);const i=this._getAuthenticatedUrl(o.toString(),n),s=(await c(i,{cache:this._cache})).features;for(const e of s)this._cacheDatasetDataStacItem(t,e);return s}async _loadDatasetDataStacItem(t,e,a={}){const n=a.datetimeStep??this._config.datetimeStep??1;let r=this._datasetDataStacItemCache.get(t)?.get(e);if(!r){r=(await this._searchDatasetDataStacItems(t,[e,e],n,a))[0]}if(!r)throw new Error(`STAC Item ${t}/${e} not found`);return r}async _loadStacItemData(t,e={}){const a=e.dataFormat??this._config.dataFormat??"byte.webp",n=t.assets[`data.${a}`];if(!n)throw new Error("STAC Item data asset not found");const r=this._getAuthenticatedUrl(n.href,this._config),o=await s(r,{cache:this._cache,signal:e.signal});return{datetime:t.properties.datetime,referenceDatetime:t.properties["forecast:reference_datetime"],horizon:t.properties["forecast:horizon"],image:o}}async _loadDatasetDataStacItemDataNow(t,e={}){const a=(await this._loadDatasetStacCollection(t,e)).links.find((t=>t.rel===ce&&"!now"===t.datetime));if(!a)throw new Error("STAC Collection now item link not found");const n=this._getAuthenticatedUrl(a.href,this._config),r=await c(n,{cache:this._cache});return await this._loadStacItemData(r,e)}async _loadDatasetDataStacItemData(t,e,a={}){const n=await this._loadDatasetDataStacItem(t,e);return await this._loadStacItemData(n,a)}async loadCatalog(t={}){return(await this._loadDatasetStacCollections(t)).map((t=>t.id))}async loadDataset(t,e={}){const a=await this._loadDatasetStacCollection(t,e),n=e.unitSystem??this._config.unitSystem??he,r=e.attributionLinkClass??this._config.attributionLinkClass??"";return{title:a.title,unitFormat:ge(a,n),attribution:de(a,r),bounds:a.extent.spatial.bbox[0],datetimeRange:a.extent.temporal.interval[0],datetimes:a.links.filter((t=>t.rel===ce)).map((t=>t.datetime)).filter((t=>!!t)),palette:await this._loadDatasetStacCollectionPalette(t),layers:a["weatherLayers:layers"],controls:a["weatherLayers:controls"]}}async loadDatasetSlice(t,e,a={}){const n=a.datetimeStep??this._config.datetimeStep??1;return{datetimes:(await this._searchDatasetDataStacItems(t,e,n,a)).map((t=>t.properties.datetime))}}async loadDatasetData(t,e,a={}){const n=a.datetimeStep??this._config.datetimeStep??1,r=a.datetimeInterpolate??this._config.datetimeInterpolate??!1,o=await this._loadDatasetStacCollection(t,a);if(!e){const e=await this._loadDatasetDataStacItemDataNow(t,a);return{datetime:e.datetime,referenceDatetime:e.referenceDatetime,horizon:e.horizon,image:e.image,datetime2:null,referenceDatetime2:null,horizon2:null,image2:null,imageWeight:0,imageType:o["weatherLayers:imageType"],imageUnscale:e.image.data instanceof Uint8Array||e.image.data instanceof Uint8ClampedArray?o["weatherLayers:imageUnscale"]:null,bounds:o.extent.spatial.bbox[0]}}let i=this._datasetDataStacItemCache.has(t)?Array.from(this._datasetDataStacItemCache.get(t).values()):[],s=i.map((t=>t.properties.datetime)).sort();if((!s.length||s[0]>e||s[s.length-1]<e)&&(i=await this._searchDatasetDataStacItems(t,[e,e],n,a),s=i.map((t=>t.properties.datetime)).sort()),!s.length)throw new Error(`STAC Item ${t}/${e} not found`);const c=f(s,e),h=u(s,e);let d,g;if(r&&c&&h&&c!==h)d=c,g=h;else{if(!c)throw new Error(`STAC Item ${t}/${e} not found`);d=c,g=null}const[m,p]=await Promise.all([this._loadDatasetDataStacItemData(t,d,a),r&&g?this._loadDatasetDataStacItemData(t,g,a):null]);return{datetime:m.datetime,referenceDatetime:m.referenceDatetime,horizon:m.horizon,image:m.image,datetime2:p?p.datetime:null,referenceDatetime2:p?p.referenceDatetime:null,horizon2:p?p.horizon:null,image2:p?p.image:null,imageWeight:p?l(m.datetime,p.datetime,e):0,imageType:o["weatherLayers:imageType"],imageUnscale:m.image.data instanceof Uint8Array||m.image.data instanceof Uint8ClampedArray?o["weatherLayers:imageUnscale"]:null,bounds:o.extent.spatial.bbox[0]}}},t.DATETIME="2026-05-11T19:53:53.178Z",t.ImageType={SCALAR:"SCALAR",VECTOR:"VECTOR"},t.UnitSystem=d,t.VERSION=e,t.colorRampCanvas=function(t,{width:e=256,height:a=1}={}){const n=t.colors(e,"css"),r=document.createElement("canvas");r.width=e,r.height=a,r.style.imageRendering="-moz-crisp-edges",r.style.imageRendering="pixelated";const o=r.getContext("2d");for(let t=0;t<e;t++)o.fillStyle=n[t],o.fillRect(t,0,1,a);return r},t.formatDatetime=function(t){if(!t)return t;const e=new Date(t);return e.getDate()?`${e.getUTCFullYear()}/${`${e.getUTCMonth()+1}`.padStart(2,"0")}/${`${e.getUTCDate()}`.padStart(2,"0")} ${`${e.getUTCHours()}`.padStart(2,"0")}:${`${e.getUTCMinutes()}`.padStart(2,"0")} UTC`:t},t.getClosestEndDatetime=u,t.getClosestStartDatetime=f,t.getDatetimeWeight=l,t.interpolateDatetime=function(t,e,a){if(!e){if(0===a)return t;throw new Error("Invalid state")}if(a<=0)return t;if(a>=1)return e;{const n=new Date(t),r=new Date(e);return new Date(n.getTime()+(r.getTime()-n.getTime())*a).toISOString()}},t.loadJson=c,t.loadTextureData=s,t.offsetDatetime=h,t.offsetDatetimeRange=function(t,e,a){return[h(t,e),h(t,a)]},t.parsePalette=function(t,{bounds:e=[0,1]}={}){if("string"==typeof t)return function(t,{bounds:e=[0,1]}={}){const{paletteArray:a,mode:n}=ee(t);return oe(a,{bounds:e,mode:n})}(t,{bounds:e});if(Array.isArray(t))return oe(t,{bounds:e});throw new Error("Invalid format")},t.setLibrary=function(t,e){a.set(t,e)}}));