var e=require("react"),t=require("regl"),r=require("path"),n=require("zarr-js"),o=require("d3-geo"),a=require("topojson-client");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=/*#__PURE__*/i(e),u=/*#__PURE__*/i(t),c=/*#__PURE__*/i(n);function s(){return s=Object.assign||function(e){for(var t=1;t0?(console.log("using webgl2 compat due to missing extensions: ",o),a.current=v.overrideContextType(function(){return u.default({container:i.current,extensions:e})})):a.current=u.default({container:i.current,extensions:e}),p(!0)}catch(e){throw console.error("Error initializing regl:",e),e}}return function(){window.removeEventListener("resize",c.current)}},[n]),e.useEffect(function(){return function(){a.current&&a.current.destroy(),p(!1)}},[]),/*#__PURE__*/l.default.createElement(h.Provider,{value:{regl:a.current,viewport:g}},/*#__PURE__*/l.default.createElement("div",{style:s({width:"100%"},r),ref:i}),d&&o)},x=/*#__PURE__*/function(e){var t,r;function n(t){var r;return(r=e.call(this,t)||this).state={errorMessage:null},r}r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,f(t,r),n.getDerivedStateFromError=function(e){var t;return{errorMessage:null!=(t=e.message)?t:defaultError}};var o=n.prototype;return o.componentDidCatch=function(e,t){console.error(e,t.componentStack)},o.render=function(){return this.state.errorMessage?/*#__PURE__*/l.default.createElement("div",{style:{textAlign:"center",padding:24}},this.props.showErrorTrace?this.state.errorMessage:"Your device doesn’t support rendering this map."):this.props.children},n}(l.default.Component),E={naturalEarth1:{aspect:.5,scale:1,translate:[0,0]},orthographic:{aspect:1,scale:3,translate:[0,0]},mercator:{aspect:1,scale:1,translate:[0,0]},equirectangular:{aspect:.5,scale:1,translate:[0,0]}},y=e.createContext(null),w=function(){return e.useContext(y)},_=function(e,t){if(!Object.keys(e).includes(t))throw new Error("variable "+t+" not found in zarr dataset, options are: "+Object.keys(e));return!0},b=function(e){var t=e.data,r=e.lat,n=e.lon;return{lat:[t[r].data.reduce(function(e,t){return Math.min(e,t)}),t[r].data.reduce(function(e,t){return Math.max(e,t)})],lon:[t[n].data.reduce(function(e,t){return Math.min(e,t)}),t[n].data.reduce(function(e,t){return Math.max(e,t)})]}},R=[0,90];exports.Graticule=function(e){var t=e.stroke,r=e.strokeWidth,n=void 0===r?.5:r,a=e.step,i=void 0===a?[45,45]:a,u=e.opacity,c=void 0===u?.2:u,s=w().projection,f="mercator"===s.id?0:.1;/*#__PURE__*/return l.default.createElement("path",{d:o.geoPath(s)(o.geoGraticule().step(i).extentMajor([[-180-f,-90-f],[180+f,90+f]])()),stroke:t,fill:"none",opacity:c,strokeWidth:n,style:{vectorEffect:"non-scaling-stroke"}})},exports.Minimap=function(t){var r=t.id,n=t.tabIndex,o=t.className,a=t.children,i=t.projection,u=t.style,c=t.aspect,f=t.scale,d=t.translate,p=t.showErrorTrace,v=void 0!==p&&p,h=e.useState({value:i(),scale:f,aspect:c,translate:d}),m=h[0],w=h[1],_=800;return e.useEffect(function(){var e=i(),t=E[e.id],r=f||t.scale,n=c||t.aspect,o=d||t.translate;e.scale(r*(_/(2*Math.PI))),e.translate([(1+o[0])*_/2,(1+o[1])*n*_/2]),w({scale:r,aspect:n,value:e,translate:o})},[i,f,c,d]),/*#__PURE__*/l.default.createElement(y.Provider,{value:{projection:m.value,translate:m.translate,scale:m.scale,aspect:m.aspect,width:_,height:_*m.aspect}},/*#__PURE__*/l.default.createElement("div",{id:r,tabIndex:n,className:o,style:s({position:"relative",width:"100%",overflow:"hidden"},u)},/*#__PURE__*/l.default.createElement(x,{showErrorTrace:v},/*#__PURE__*/l.default.createElement(g,{aspect:m.aspect,style:{pointerEvents:"none",zIndex:-1}},/*#__PURE__*/l.default.createElement("svg",{viewBox:"0 0 800 "+_*m.aspect,style:{position:"absolute",width:"100%",top:0,left:0,overflow:"hidden",pointerEvents:"none"}},a)))))},exports.Path=function(t){var r=t.source,n=t.feature,i=t.fill,u=void 0===i?"none":i,c=t.stroke,s=void 0===c?"none":c,f=t.strokeWidth,d=void 0===f?.5:f,p=t.opacity,v=void 0===p?.7:p,h=e.useState(),m=h[0],g=h[1],x=e.useState(),E=x[0],y=x[1],_=w().projection;return e.useEffect(function(){fetch(r).then(function(e){return e.json()}).then(function(e){y(a.feature(e,e.objects[n]))})},[r]),e.useEffect(function(){g(o.geoPath(_)(E))},[E,_]),/*#__PURE__*/l.default.createElement("path",{d:m,stroke:s,fill:u,opacity:v,strokeWidth:d,style:{vectorEffect:"non-scaling-stroke"}})},exports.Points=function(t){var r=t.position,n=t.value,o=t.size,a=void 0===o?5:o,i=t.opacity,l=void 0===i?1:i,u=t.colormap,c=void 0===u?null:u,f=t.clim,d=void 0===f?null:f,p=t.mode,v=void 0===p?"lut":p,h=m(),g=h.viewport,x=h.regl,E=w(),y=E.scale,_=E.translate,b=E.projection,R=e.useRef(),A=e.useRef(),C=e.useRef({}),P=e.useRef(),T=e.useRef(null);if("lut"==v&&!c)throw new Error("must provide 'colormap' when using 'lut' mode");if("lut"==v&&!d)throw new Error("must provide 'clim' when using 'lut' mode");return e.useEffect(function(){x.frame(function(e){C.current=e,T.current&&(x.clear({color:[0,0,0,0],depth:1}),R.current(T.current)),T.current=null})},[]),e.useEffect(function(){P.current||(P.current=x.texture());var e={pixelRatio:x.prop("pixelRatio"),viewportWidth:x.prop("viewportWidth"),viewportHeight:x.prop("viewportHeight"),bounds:x.prop("bounds"),scale:x.prop("scale"),translate:x.prop("translate"),size:x.prop("size"),opacity:x.prop("opacity")};"lut"===v&&(e=s({},e,{lut:x.prop("lut"),clim:x.prop("clim")})),A.current=x({vert:"\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\n attribute vec2 position;\n attribute float value;\n uniform float scale;\n uniform vec2 translate;\n uniform float size;\n const float pi = 3.14159265358979323846264;\n const float halfPi = pi * 0.5;\n varying float valuev;\n\n "+b.glsl.funcForward+"\n void main() {\n valuev = value;\n vec2 location = "+b.glsl.nameForward+"(position.x, position.y);\n gl_PointSize = size;\n gl_Position = vec4(location.x * scale / (halfPi * 2.0) + translate.x, location.y * scale / halfPi - translate.y, 0.0, 1.0);\n }\n ",frag:"\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\n uniform vec2 clim;\n uniform sampler2D lut;\n uniform float opacity;\n varying float valuev;\n \n void main() {\n if (length(gl_PointCoord.xy - 0.5) > 0.5) {\n discard;\n }\n\n float rescaled = (valuev - clim.x)/(clim.y - clim.x);\n vec4 c = texture2D(lut, vec2(rescaled, 1.0));\n gl_FragColor = vec4(c.x, c.y, c.z, 1.0) * opacity;\n }\n ",attributes:{position:x.prop("position"),value:x.prop("value")},uniforms:e,count:r.length,primitive:"points",depth:{enable:!1},blend:{enable:!0,func:{srcRGB:"one",srcAlpha:"one",dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"}}})},[b.glsl.name]),R.current=function(e){if(A.current){var t=C.current.pixelRatio;A.current({bounds:[-90,90,-180,180],lut:P.current,position:r,value:n,scale:y,clim:d,translate:_,size:a,opacity:l,viewportWidth:g.width*t,viewportHeight:g.height*t,pixelRatio:t})}},e.useEffect(function(){T.current="on viewport change"},[g]),e.useEffect(function(){c&&(P.current({data:c,format:"rgb",shape:[c.length,1]}),T.current="on colormap change")},[c]),e.useEffect(function(){T.current="on prop change"},[r,n,b,y,a,l,d&&d[0],d&&d[1],_[0],_[1]]),null},exports.Raster=function(t){var n=t.source,o=t.variable,a=t.mode,i=void 0===a?"rgb":a,l=t.colormap,u=void 0===l?null:l,f=t.clim,d=void 0===f?null:f,p=t.transpose,v=t.northPole,h=void 0===v?R:v,g=t.nullValue,x=void 0===g?-999:g,E=t.bounds,y=void 0===E?null:E,A=t.lat,C=void 0===A?"lat":A,P=t.lon,T=void 0===P?"lon":P,G=m(),F=G.viewport,I=G.regl,L=w(),O=L.scale,S=L.translate,N=L.projection;if("lut"==i&&!u)throw new Error("must provide 'colormap' when using 'lut' mode");if("lut"==i&&!d)throw new Error("must provide 'clim' when using 'lut' mode");var k=e.useRef(),M=e.useRef(),H=e.useRef(),X=e.useRef(),j=e.useRef({}),z=e.useRef(!1),B=e.useRef(null),W=e.useRef(),D=e.useRef(null);return e.useEffect(function(){I.frame(function(e){j.current=e,D.current&&(I.clear({color:[0,0,0,0],depth:1}),k.current(D.current)),D.current=null})},[]),e.useEffect(function(){H.current||(H.current=I.texture({width:1,height:1,data:[0,0,0,0]})),X.current||(X.current=I.texture());var e={pixelRatio:I.prop("pixelRatio"),viewportWidth:I.prop("viewportWidth"),viewportHeight:I.prop("viewportHeight"),texture:I.prop("texture"),scale:I.prop("scale"),translate:I.prop("translate"),northPole:I.prop("northPole"),transpose:I.prop("transpose"),nullValue:I.prop("nullValue"),bounds:I.prop("bounds")};"lut"===i&&(e=s({},e,{lut:I.prop("lut"),clim:I.prop("clim")})),M.current=I({vert:"\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\n attribute vec2 position;\n varying vec2 uv;\n void main() {\n uv = vec2(position.y, position.x);\n gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, 0.0, 1.0);\n }\n ",frag:"\n #ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n #endif\n varying vec2 uv;\n uniform vec2 clim;\n uniform vec4 bounds;\n uniform float viewportWidth;\n uniform float viewportHeight;\n uniform sampler2D texture;\n uniform float pixelRatio;\n uniform float scale;\n uniform vec2 translate;\n uniform vec2 northPole;\n uniform bool transpose;\n uniform float nullValue;\n "+("lut"===i?"uniform sampler2D lut;":"")+"\n "+("lut"===i?"uniform vec3 nullColor;":"")+"\n\n const float pi = 3.14159265358979323846264;\n const float halfPi = pi * 0.5;\n const float twoPi = pi * 2.0;\n\n bool isnan(float val)\n {\n return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true;\n }\n\n vec2 rotateCoords(vec2 coords, vec2 northPole) {\n // Calculate rotation based of north pole coordinates of rotated grid\n float phiOffset = northPole.y == 90.0 ? 0.0 : 180.0;\n float phi = radians(phiOffset + northPole.x);\n float theta = radians(-1.0 * (90.0 - northPole.y));\n\n float lon = radians(coords.x);\n float lat = radians(coords.y);\n\n // Convert from spherical to cartesian coordinates\n vec3 unrotatedCoord = vec3(cos(lon) * cos(lat), sin(lon) * cos(lat), sin(lat));\n\n // From https://en.wikipedia.org/wiki/Rotation_matrix#General_rotations\n mat3 intrinsicRotation = mat3(\n cos(phi) * cos(theta), -1.0 * sin(phi), cos(phi) * sin(theta),\n sin(phi) * cos(theta), cos(phi) , sin(phi) * sin(theta),\n -1.0 * sin(theta) , 0 , cos(theta)\n );\n\n vec3 rotatedCoord = intrinsicRotation * unrotatedCoord;\n\n // Convert from cartesian to spherical coordinates\n float rotatedLon = degrees(atan(rotatedCoord.y, rotatedCoord.x));\n float rotatedLat = degrees(asin(rotatedCoord.z));\n\n return vec2(rotatedLon, rotatedLat);\n }\n\n "+N.glsl.func+"\n void main() {\n \n float width = viewportWidth / pixelRatio;\n float height = viewportHeight / pixelRatio;\n float x = gl_FragCoord.x / pixelRatio;\n float y = gl_FragCoord.y / pixelRatio;\n\n vec2 delta = vec2((1.0 + translate.x) * width / 2.0, (1.0 - translate.y) * height / 2.0); \n\n x = (x - delta.x) / (scale * (width / (pi * 2.0)));\n "+(p?"y = (delta.y - y) / (scale * (width / (pi * 2.0)));":"y = (y - delta.y) / (scale * (width / (pi * 2.0)));")+"\n\n vec2 lookup = "+N.glsl.name+"(x, y);\n vec2 rotated = rotateCoords(lookup, northPole);\n\n // Handle points that wrap\n float offsetX = 0.0;\n if (rotated.x < bounds[2]) {\n offsetX = 360.0;\n } else if (rotated.x > bounds[3]) {\n offsetX = -360.0;\n }\n\n float scaleY = 180.0 / abs(bounds[0] - bounds[1]);\n float scaleX = 360.0 / abs(bounds[2] - bounds[3]);\n float translateY = 90.0 + bounds[0];\n float translateX = 180.0 + bounds[2];\n\n float rescaledY = scaleY * (radians(rotated.y - translateY) + halfPi) / pi;\n float rescaledX = scaleX * (radians(rotated.x + offsetX - translateX) + pi) / twoPi;\n\n vec2 coord;\n "+(p?"coord = vec2(rescaledX, rescaledY);":"coord = vec2(rescaledY, rescaledX);")+"\n\n vec4 value = texture2D(texture, coord);\n\n bool inboundsY = rotated.y > bounds[0] && rotated.y < bounds[1];\n bool inboundsX = rotated.x + offsetX > bounds[2] && rotated.x + offsetX < bounds[3];\n\n "+("lut"===i?"\n vec4 c;\n if ((!inboundsY || !inboundsX) || (value.x == nullValue || isnan(value.x))) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n } else {\n float rescaled = (value.x - clim.x)/(clim.y - clim.x);\n c = texture2D(lut, vec2(rescaled, 1.0));\n gl_FragColor = vec4(c.x, c.y, c.z, 1.0);\n }":"")+"\n\n "+("rgb"===i?"\n if (value.x == nullValue) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n } else {\n gl_FragColor = vec4(value.x , value.y, value.z, 1.0);\n }\n ":"")+"\n }\n ",attributes:{position:[0,0,0,1,1,0,1,0,0,1,1,1]},uniforms:e,count:6,primitive:"triangles"})},[N.glsl.name]),k.current=function(e){if(M.current&&z.current){var t=j.current.pixelRatio;M.current({texture:H.current,lut:X.current,bounds:B.current?[B.current.lat[0],B.current.lat[1],B.current.lon[0],B.current.lon[1]]:[-90,90,-180,180],scale:O,translate:S,northPole:h,clim:d,nullValue:x,viewportWidth:F.width*t,viewportHeight:F.height*t,pixelRatio:t})}},e.useEffect(function(){if("string"==typeof n){var e=r.extname(n);if([".png",".jpg",".jpeg"].includes(e)){var t=document.createElement("img");t.src=n,t.crossOrigin="anonymous",t.onload=function(){setTimeout(function(){z.current=!0,H.current(t),D.current="on image load"},0)}}".zarr"===e&&(o?c.default().loadGroup(n,function(e,t,r){_(t,o),!y&&t[C]&&t[T]&&(B.current=b({data:t,lat:C,lon:T})),W.current=t,z.current=!0,H.current(W.current[o]),D.current="on zarr group load"}):c.default().load(n,function(e,t){z.current=!0,H.current(t),D.current="on zarr array load"}))}else o?(_(n,o),!y&&n[C]&&n[T]&&(B.current=b({data:n,lat:C,lon:T})),W.current=n,z.current=!0,H.current(W.current[o]),D.current="on zarr group read"):(z.current=!0,H.current(n),D.current="on zarr array read")},[n,C,T]),e.useEffect(function(){W.current&&(H.current(W.current[o]),D.current="on variable change")},[o]),e.useEffect(function(){y&&(B.current=y),D.current="on bounds change"},[y&&y.lat[0],y&&y.lat[1],y&&y.lon[0],y&&y.lon[1]]),e.useEffect(function(){u&&(X.current({data:u,format:"rgb",shape:[u.length,1]}),D.current="on colormap change")},[u]),e.useEffect(function(){D.current="on viewport change"},[F]),e.useEffect(function(){D.current="on prop change"},[d&&d[0],d&&d[1],i,O,S[0],S[1],h?h[0]:void 0,h?h[1]:void 0,x,N]),null},exports.Sphere=function(t){var r=t.fill,n=t.stroke,a=t.strokeWidth,i=void 0===a?.5:a,u=t.opacity,c=void 0===u?.2:u,s=w(),f=s.projection,d=s.width,p=s.height,v=e.useState(),h=v[0],m=v[1],g=String(Math.floor(100*Math.random()));return e.useEffect(function(){m(o.geoPath(f)({type:"Sphere"}))},[f]),/*#__PURE__*/l.default.createElement("svg",{viewBox:"0 0 "+d+" "+p,style:{position:"absolute",width:"100%",top:0,left:0}},/*#__PURE__*/l.default.createElement("mask",{id:g},/*#__PURE__*/l.default.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:"#FFFFFF"}),/*#__PURE__*/l.default.createElement("path",{fill:"#000000",id:"circle-cutout",d:h})),/*#__PURE__*/l.default.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",mask:"url(#"+g+")",style:{fill:r}}),n&&/*#__PURE__*/l.default.createElement("path",{fill:"none",stroke:n,strokeWidth:i,opacity:c,style:{vectorEffect:"non-scaling-stroke"},d:h}))},exports.useMinimap=w; //# sourceMappingURL=index.cjs.map