react-simple-maps 4.0.0-beta.3 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1,965 @@
1
- "use strict";var e=require("react"),t=require("prop-types"),r=require("d3-geo"),o=require("topojson-client"),n=require("d3-zoom"),a=require("d3-selection");function s(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=s(r),c=s(n),u=s(a);function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){m(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function p(e){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(e)}function m(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},d.apply(this,arguments)}function v(e,t){if(null==e)return{};var r,o,n=function(e,t){if(null==e)return{};var r,o,n={},a=Object.keys(e);for(o=0;o<a.length;o++)r=a[o],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)r=a[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o,n,a,s,i=[],c=!0,u=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(o=a.call(r)).done)&&(i.push(o.value),i.length!==t);c=!0);}catch(e){u=!0,n=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw n}}return i}}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return y(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}var h=["width","height","projection","projectionConfig"],b=i.geoPath,j=v(i,["geoPath"]),x=e.createContext(),E=function(t){var r=t.width,o=t.height,n=t.projection,a=t.projectionConfig,s=v(t,h),i=g(a.center||[],2),c=i[0],u=i[1],l=g(a.rotate||[],3),f=l[0],p=l[1],m=l[2],y=g(a.parallels||[],2),E=y[0],M=y[1],w=a.scale||null,k=e.useMemo((function(){return function(e){var t=e.projectionConfig,r=void 0===t?{}:t,o=e.projection,n=void 0===o?"geoEqualEarth":o,a=e.width,s=void 0===a?800:a,i=e.height,c=void 0===i?600:i;if("function"==typeof n)return n;var u=j[n]().translate([s/2,c/2]);return[u.center?"center":null,u.rotate?"rotate":null,u.scale?"scale":null,u.parallels?"parallels":null].forEach((function(e){e&&(u=u[e](r[e]||u[e]()))})),u}({projectionConfig:{center:c||0===c||u||0===u?[c,u]:null,rotate:f||0===f||p||0===p?[f,p,m]:null,parallels:E||0===E||M||0===M?[E,M]:null,scale:w},projection:n,width:r,height:o})}),[r,o,n,c,u,f,p,m,E,M,w]),O=e.useCallback(k,[k]),N=e.useMemo((function(){return{width:r,height:o,projection:O,path:b().projection(O)}}),[r,o,O]);return e.createElement(x.Provider,d({value:N},s))};E.propTypes={width:t.number,height:t.number,projection:t.oneOfType([t.string,t.func]),projectionConfig:t.object};var M=["width","height","projection","projectionConfig","className"],w=e.forwardRef((function(t,r){var o=t.width,n=void 0===o?800:o,a=t.height,s=void 0===a?600:a,i=t.projection,c=void 0===i?"geoEqualEarth":i,u=t.projectionConfig,l=void 0===u?{}:u,f=t.className,p=void 0===f?"":f,m=v(t,M);return e.createElement(E,{width:n,height:s,projection:c,projectionConfig:l},e.createElement("svg",d({ref:r,viewBox:"0 0 ".concat(n," ").concat(s),className:"rsm-svg ".concat(p)},m)))}));function k(e,t,r){var o=(e*r.k-e)/2,n=(t*r.k-t)/2;return[e/2-(o+r.x)/r.k,t/2-(n+r.y)/r.k]}function O(e,t){if(!("Topology"===e.type))return t?t(e.features||e):e.features||e;var r=o.feature(e,e.objects[Object.keys(e.objects)[0]]).features;return t?t(r):r}function N(e){return"Topology"===e.type?{outline:o.mesh(e,e.objects[Object.keys(e.objects)[0]],(function(e,t){return e===t})),borders:o.mesh(e,e.objects[Object.keys(e.objects)[0]],(function(e,t){return e!==t}))}:null}function S(e,t){return e?e.map((function(e,r){return f(f({},e),{},{rsmKey:"geo-".concat(r),svgPath:t(e)})})):[]}function P(t){var r=t.geography,o=t.parseGeographies,n=e.useContext(x).path,a=g(e.useState({}),2),s=a[0],i=a[1];e.useEffect((function(){var e;"undefined"!==("undefined"==typeof window?"undefined":p(window))&&(r&&("string"==typeof r?(e=r,fetch(e).then((function(e){if(!e.ok)throw Error(e.statusText);return e.json()})).catch((function(e){console.log("There was a problem when fetching the data: ",e)}))).then((function(e){e&&i({geographies:O(e,o),mesh:N(e)})})):i({geographies:O(r,o),mesh:N(r)})))}),[r,o]);var c=e.useMemo((function(){var e=s.mesh||{},t=function(e,t,r){return e&&t?{outline:f(f({},e),{},{rsmKey:"outline",svgPath:r(e)}),borders:f(f({},t),{},{rsmKey:"borders",svgPath:r(t)})}:{}}(e.outline,e.borders,n);return{geographies:S(s.geographies,n),outline:t.outline,borders:t.borders}}),[s,n]);return{geographies:c.geographies,outline:c.outline,borders:c.borders}}w.displayName="ComposableMap",w.propTypes={width:t.number,height:t.number,projection:t.oneOfType([t.string,t.func]),projectionConfig:t.object,className:t.string};var C=["geography","children","parseGeographies","className"],T=e.forwardRef((function(t,r){var o=t.geography,n=t.children,a=t.parseGeographies,s=t.className,i=void 0===s?"":s,c=v(t,C),u=e.useContext(x),l=u.path,f=u.projection,p=P({geography:o,parseGeographies:a}),m=p.geographies,g=p.outline,y=p.borders;return e.createElement("g",d({ref:r,className:"rsm-geographies ".concat(i)},c),m&&m.length>0&&n({geographies:m,outline:g,borders:y,path:l,projection:f}))}));T.displayName="Geographies",T.propTypes={geography:t.oneOfType([t.string,t.object,t.array]),children:t.func,parseGeographies:t.func,className:t.string};var Z=["geography","onMouseEnter","onMouseLeave","onMouseDown","onMouseUp","onFocus","onBlur","style","className"],G=e.forwardRef((function(t,r){var o=t.geography,n=t.onMouseEnter,a=t.onMouseLeave,s=t.onMouseDown,i=t.onMouseUp,c=t.onFocus,u=t.onBlur,l=t.style,f=void 0===l?{}:l,p=t.className,m=void 0===p?"":p,y=v(t,Z),h=g(e.useState(!1),2),b=h[0],j=h[1],x=g(e.useState(!1),2),E=x[0],M=x[1];return e.createElement("path",d({ref:r,tabIndex:"0",className:"rsm-geography ".concat(m),d:o.svgPath,onMouseEnter:function(e){M(!0),n&&n(e)},onMouseLeave:function(e){M(!1),b&&j(!1),a&&a(e)},onFocus:function(e){M(!0),c&&c(e)},onBlur:function(e){M(!1),b&&j(!1),u&&u(e)},onMouseDown:function(e){j(!0),s&&s(e)},onMouseUp:function(e){j(!1),i&&i(e)},style:f[b||E?b?"pressed":"hover":"default"]},y))}));G.displayName="Geography",G.propTypes={geography:t.object,onMouseEnter:t.func,onMouseLeave:t.func,onMouseDown:t.func,onMouseUp:t.func,onFocus:t.func,onBlur:t.func,style:t.object,className:t.string};var R=e.memo(G),z=["fill","stroke","step","className"],D=e.forwardRef((function(t,r){var o=t.fill,n=void 0===o?"transparent":o,a=t.stroke,s=void 0===a?"currentcolor":a,c=t.step,u=void 0===c?[10,10]:c,l=t.className,f=void 0===l?"":l,p=v(t,z),m=e.useContext(x).path;return e.createElement("path",d({ref:r,d:m(i.geoGraticule().step(u)()),fill:n,stroke:s,className:"rsm-graticule ".concat(f)},p))}));D.displayName="Graticule",D.propTypes={fill:t.string,stroke:t.string,step:t.array,className:t.string};var L=e.memo(D),A=["value"],B=e.createContext(),F={x:0,y:0,k:1,transformString:"translate(0 0) scale(1)"},U=function(t){var r=t.value,o=void 0===r?F:r,n=v(t,A);return e.createElement(B.Provider,d({value:o},n))};U.propTypes={x:t.number,y:t.number,k:t.number,transformString:t.string};function q(t){var r=t.center,o=t.filterZoomEvent,n=t.onMoveStart,a=t.onMoveEnd,s=t.onMove,i=t.translateExtent,l=void 0===i?[[-1/0,-1/0],[1/0,1/0]]:i,f=t.scaleExtent,p=void 0===f?[1,8]:f,m=t.zoom,d=void 0===m?1:m,v=e.useContext(x),y=v.width,h=v.height,b=v.projection,j=g(r,2),E=j[0],M=j[1],w=g(e.useState({x:0,y:0,k:1}),2),O=w[0],N=w[1],S=e.useRef({x:0,y:0,k:1}),P=e.useRef(),C=e.useRef(),T=e.useRef(!1),Z=g(l,2),G=Z[0],R=Z[1],z=g(G,2),D=z[0],L=z[1],A=g(R,2),B=A[0],F=A[1],U=g(p,2),q=U[0],W=U[1];return e.useEffect((function(){var e=u.select(P.current);var t=c.zoom().filter((function(e){return o?o(e):!!e&&(!e.ctrlKey&&!e.button)})).scaleExtent([q,W]).translateExtent([[D,L],[B,F]]).on("start",(function(e){n&&!T.current&&n({coordinates:b.invert(k(y,h,e.transform)),zoom:e.transform.k},e)})).on("zoom",(function(e){if(!T.current){var t=e.transform,r=e.sourceEvent;N({x:t.x,y:t.y,k:t.k,dragging:r}),s&&s({x:t.x,y:t.y,zoom:t.k,dragging:r},e)}})).on("end",(function(e){if(T.current)T.current=!1;else{var t=g(b.invert(k(y,h,e.transform)),2),r=t[0],o=t[1];S.current={x:r,y:o,k:e.transform.k},a&&a({coordinates:[r,o],zoom:e.transform.k},e)}}));C.current=t,e.call(t)}),[y,h,D,L,B,F,q,W,b,n,s,a,o]),e.useEffect((function(){if(E!==S.current.x||M!==S.current.y||d!==S.current.k){var e=b([E,M]),t=e[0]*d,r=e[1]*d,o=u.select(P.current);T.current=!0,o.call(C.current.transform,c.zoomIdentity.translate(y/2-t,h/2-r).scale(d)),N({x:y/2-t,y:h/2-r,k:d}),S.current={x:E,y:M,k:d}}}),[E,M,d,y,h,b]),{mapRef:P,position:O,transformString:"translate(".concat(O.x," ").concat(O.y,") scale(").concat(O.k,")")}}var W=["center","zoom","minZoom","maxZoom","translateExtent","filterZoomEvent","onMoveStart","onMove","onMoveEnd","className"],I=e.forwardRef((function(t,r){var o=t.center,n=void 0===o?[0,0]:o,a=t.zoom,s=void 0===a?1:a,i=t.minZoom,c=void 0===i?1:i,u=t.maxZoom,l=void 0===u?8:u,f=t.translateExtent,p=t.filterZoomEvent,m=t.onMoveStart,g=t.onMove,y=t.onMoveEnd,h=t.className,b=v(t,W),j=e.useContext(x),E=j.width,M=j.height,w=q({center:n,filterZoomEvent:p,onMoveStart:m,onMove:g,onMoveEnd:y,scaleExtent:[c,l],translateExtent:f,zoom:s}),k=w.mapRef,O=w.transformString,N=w.position;return e.createElement(U,{value:{x:N.x,y:N.y,k:N.k,transformString:O}},e.createElement("g",{ref:k},e.createElement("rect",{width:E,height:M,fill:"transparent"}),e.createElement("g",d({ref:r,transform:O,className:"rsm-zoomable-group ".concat(h)},b))))}));I.displayName="ZoomableGroup",I.propTypes={center:t.array,zoom:t.number,minZoom:t.number,maxZoom:t.number,translateExtent:t.arrayOf(t.array),onMoveStart:t.func,onMove:t.func,onMoveEnd:t.func,className:t.string};var K=["id","fill","stroke","strokeWidth","className"],Q=e.forwardRef((function(t,r){var o=t.id,n=void 0===o?"rsm-sphere":o,a=t.fill,s=void 0===a?"transparent":a,i=t.stroke,c=void 0===i?"currentcolor":i,u=t.strokeWidth,l=void 0===u?.5:u,f=t.className,p=void 0===f?"":f,m=v(t,K),g=e.useContext(x).path,y=e.useMemo((function(){return g({type:"Sphere"})}),[g]);return e.createElement(e.Fragment,null,e.createElement("defs",null,e.createElement("clipPath",{id:n},e.createElement("path",{d:y}))),e.createElement("path",d({ref:r,d:y,fill:s,stroke:c,strokeWidth:l,style:{pointerEvents:"none"},className:"rsm-sphere ".concat(p)},m)))}));Q.displayName="Sphere",Q.propTypes={id:t.string,fill:t.string,stroke:t.string,strokeWidth:t.number,className:t.string};var $=e.memo(Q),H=["coordinates","children","onMouseEnter","onMouseLeave","onMouseDown","onMouseUp","onFocus","onBlur","style","className"],J=e.forwardRef((function(t,r){var o=t.coordinates,n=t.children,a=t.onMouseEnter,s=t.onMouseLeave,i=t.onMouseDown,c=t.onMouseUp,u=t.onFocus,l=t.onBlur,f=t.style,p=void 0===f?{}:f,m=t.className,y=void 0===m?"":m,h=v(t,H),b=e.useContext(x).projection,j=g(e.useState(!1),2),E=j[0],M=j[1],w=g(e.useState(!1),2),k=w[0],O=w[1],N=g(b(o),2),S=N[0],P=N[1];return e.createElement("g",d({ref:r,transform:"translate(".concat(S,", ").concat(P,")"),className:"rsm-marker ".concat(y),onMouseEnter:function(e){O(!0),a&&a(e)},onMouseLeave:function(e){O(!1),E&&M(!1),s&&s(e)},onFocus:function(e){O(!0),u&&u(e)},onBlur:function(e){O(!1),E&&M(!1),l&&l(e)},onMouseDown:function(e){M(!0),i&&i(e)},onMouseUp:function(e){M(!1),c&&c(e)},style:p[E||k?E?"pressed":"hover":"default"]},h),n)}));J.displayName="Marker",J.propTypes={coordinates:t.array,children:t.oneOfType([t.node,t.arrayOf(t.node)]),onMouseEnter:t.func,onMouseLeave:t.func,onMouseDown:t.func,onMouseUp:t.func,onFocus:t.func,onBlur:t.func,style:t.object,className:t.string};var V=["from","to","coordinates","stroke","strokeWidth","fill","className"],X=e.forwardRef((function(t,r){var o=t.from,n=void 0===o?[0,0]:o,a=t.to,s=void 0===a?[0,0]:a,i=t.coordinates,c=t.stroke,u=void 0===c?"currentcolor":c,l=t.strokeWidth,f=void 0===l?3:l,p=t.fill,m=void 0===p?"transparent":p,g=t.className,y=void 0===g?"":g,h=v(t,V),b=e.useContext(x).path,j={type:"LineString",coordinates:i||[n,s]};return e.createElement("path",d({ref:r,d:b(j),className:"rsm-line ".concat(y),stroke:u,strokeWidth:f,fill:m},h))}));X.displayName="Line",X.propTypes={from:t.array,to:t.array,coordinates:t.array,stroke:t.string,strokeWidth:t.number,fill:t.string,className:t.string};var Y=["subject","children","connectorProps","dx","dy","curve","className"],_=e.forwardRef((function(t,r){var o=t.subject,n=t.children,a=t.connectorProps,s=t.dx,i=void 0===s?30:s,c=t.dy,u=void 0===c?30:c,l=t.curve,f=void 0===l?0:l,p=t.className,m=void 0===p?"":p,y=v(t,Y),h=g((0,e.useContext(x).projection)(o),2),b=h[0],j=h[1],E=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:30,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:30,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,o=Array.isArray(r)?r:[r,r],n=e/2*o[0],a=t/2*o[1];return"M".concat(0,",",0," Q",-e/2-n,",").concat(-t/2+a," ").concat(-e,",").concat(-t)}(i,u,f);return e.createElement("g",d({ref:r,transform:"translate(".concat(b+i,", ").concat(j+u,")"),className:"rsm-annotation ".concat(m)},y),e.createElement("path",d({d:E,fill:"transparent",stroke:"#000"},a)),n)}));_.displayName="Annotation",_.propTypes={subject:t.array,children:t.oneOfType([t.node,t.arrayOf(t.node)]),dx:t.number,dy:t.number,curve:t.number,connectorProps:t.object,className:t.string},exports.Annotation=_,exports.ComposableMap=w,exports.Geographies=T,exports.Geography=R,exports.Graticule=L,exports.Line=X,exports.MapContext=x,exports.MapProvider=E,exports.Marker=J,exports.Sphere=$,exports.ZoomPanContext=B,exports.ZoomPanProvider=U,exports.ZoomableGroup=I,exports.useGeographies=P,exports.useMapContext=function(){return e.useContext(x)},exports.useZoomPan=q,exports.useZoomPanContext=function(){return e.useContext(B)};
1
+ import React, { createContext, useMemo, useCallback, useContext, forwardRef, useState, useEffect, memo, useRef, Fragment } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import * as d3 from 'd3-geo';
4
+ import { feature, mesh } from 'topojson-client';
5
+ import * as d3$1 from 'd3-selection';
6
+ import * as d3$2 from 'd3-zoom';
7
+
8
+ function _iterableToArrayLimit(arr, i) {
9
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
10
+ if (null != _i) {
11
+ var _s,
12
+ _e,
13
+ _x,
14
+ _r,
15
+ _arr = [],
16
+ _n = !0,
17
+ _d = !1;
18
+ try {
19
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
20
+ if (Object(_i) !== _i) return;
21
+ _n = !1;
22
+ } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
23
+ } catch (err) {
24
+ _d = !0, _e = err;
25
+ } finally {
26
+ try {
27
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
28
+ } finally {
29
+ if (_d) throw _e;
30
+ }
31
+ }
32
+ return _arr;
33
+ }
34
+ }
35
+ function ownKeys(object, enumerableOnly) {
36
+ var keys = Object.keys(object);
37
+ if (Object.getOwnPropertySymbols) {
38
+ var symbols = Object.getOwnPropertySymbols(object);
39
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
40
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
41
+ })), keys.push.apply(keys, symbols);
42
+ }
43
+ return keys;
44
+ }
45
+ function _objectSpread2(target) {
46
+ for (var i = 1; i < arguments.length; i++) {
47
+ var source = null != arguments[i] ? arguments[i] : {};
48
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
49
+ _defineProperty(target, key, source[key]);
50
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
51
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
52
+ });
53
+ }
54
+ return target;
55
+ }
56
+ function _typeof(obj) {
57
+ "@babel/helpers - typeof";
58
+
59
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
60
+ return typeof obj;
61
+ } : function (obj) {
62
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
63
+ }, _typeof(obj);
64
+ }
65
+ function _defineProperty(obj, key, value) {
66
+ key = _toPropertyKey(key);
67
+ if (key in obj) {
68
+ Object.defineProperty(obj, key, {
69
+ value: value,
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true
73
+ });
74
+ } else {
75
+ obj[key] = value;
76
+ }
77
+ return obj;
78
+ }
79
+ function _extends() {
80
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
81
+ for (var i = 1; i < arguments.length; i++) {
82
+ var source = arguments[i];
83
+ for (var key in source) {
84
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
85
+ target[key] = source[key];
86
+ }
87
+ }
88
+ }
89
+ return target;
90
+ };
91
+ return _extends.apply(this, arguments);
92
+ }
93
+ function _objectWithoutPropertiesLoose(source, excluded) {
94
+ if (source == null) return {};
95
+ var target = {};
96
+ var sourceKeys = Object.keys(source);
97
+ var key, i;
98
+ for (i = 0; i < sourceKeys.length; i++) {
99
+ key = sourceKeys[i];
100
+ if (excluded.indexOf(key) >= 0) continue;
101
+ target[key] = source[key];
102
+ }
103
+ return target;
104
+ }
105
+ function _objectWithoutProperties(source, excluded) {
106
+ if (source == null) return {};
107
+ var target = _objectWithoutPropertiesLoose(source, excluded);
108
+ var key, i;
109
+ if (Object.getOwnPropertySymbols) {
110
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
111
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
112
+ key = sourceSymbolKeys[i];
113
+ if (excluded.indexOf(key) >= 0) continue;
114
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
115
+ target[key] = source[key];
116
+ }
117
+ }
118
+ return target;
119
+ }
120
+ function _slicedToArray(arr, i) {
121
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
122
+ }
123
+ function _arrayWithHoles(arr) {
124
+ if (Array.isArray(arr)) return arr;
125
+ }
126
+ function _unsupportedIterableToArray(o, minLen) {
127
+ if (!o) return;
128
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
129
+ var n = Object.prototype.toString.call(o).slice(8, -1);
130
+ if (n === "Object" && o.constructor) n = o.constructor.name;
131
+ if (n === "Map" || n === "Set") return Array.from(o);
132
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
133
+ }
134
+ function _arrayLikeToArray(arr, len) {
135
+ if (len == null || len > arr.length) len = arr.length;
136
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
137
+ return arr2;
138
+ }
139
+ function _nonIterableRest() {
140
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
141
+ }
142
+ function _toPrimitive(input, hint) {
143
+ if (typeof input !== "object" || input === null) return input;
144
+ var prim = input[Symbol.toPrimitive];
145
+ if (prim !== undefined) {
146
+ var res = prim.call(input, hint || "default");
147
+ if (typeof res !== "object") return res;
148
+ throw new TypeError("@@toPrimitive must return a primitive value.");
149
+ }
150
+ return (hint === "string" ? String : Number)(input);
151
+ }
152
+ function _toPropertyKey(arg) {
153
+ var key = _toPrimitive(arg, "string");
154
+ return typeof key === "symbol" ? key : String(key);
155
+ }
156
+
157
+ var _excluded$a = ["width", "height", "projection", "projectionConfig"];
158
+ var geoPath = d3.geoPath,
159
+ projections = _objectWithoutProperties(d3, ["geoPath"]);
160
+ var MapContext = createContext();
161
+ var makeProjection = function makeProjection(_ref) {
162
+ var _ref$projectionConfig = _ref.projectionConfig,
163
+ projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
164
+ _ref$projection = _ref.projection,
165
+ projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
166
+ _ref$width = _ref.width,
167
+ width = _ref$width === void 0 ? 800 : _ref$width,
168
+ _ref$height = _ref.height,
169
+ height = _ref$height === void 0 ? 600 : _ref$height;
170
+ var isFunc = typeof projection === "function";
171
+ if (isFunc) return projection;
172
+ var proj = projections[projection]().translate([width / 2, height / 2]);
173
+ var supported = [proj.center ? "center" : null, proj.rotate ? "rotate" : null, proj.scale ? "scale" : null, proj.parallels ? "parallels" : null];
174
+ supported.forEach(function (d) {
175
+ if (!d) return;
176
+ proj = proj[d](projectionConfig[d] || proj[d]());
177
+ });
178
+ return proj;
179
+ };
180
+ var MapProvider = function MapProvider(_ref2) {
181
+ var width = _ref2.width,
182
+ height = _ref2.height,
183
+ projection = _ref2.projection,
184
+ projectionConfig = _ref2.projectionConfig,
185
+ restProps = _objectWithoutProperties(_ref2, _excluded$a);
186
+ var _ref3 = projectionConfig.center || [],
187
+ _ref4 = _slicedToArray(_ref3, 2),
188
+ cx = _ref4[0],
189
+ cy = _ref4[1];
190
+ var _ref5 = projectionConfig.rotate || [],
191
+ _ref6 = _slicedToArray(_ref5, 3),
192
+ rx = _ref6[0],
193
+ ry = _ref6[1],
194
+ rz = _ref6[2];
195
+ var _ref7 = projectionConfig.parallels || [],
196
+ _ref8 = _slicedToArray(_ref7, 2),
197
+ p1 = _ref8[0],
198
+ p2 = _ref8[1];
199
+ var s = projectionConfig.scale || null;
200
+ var projMemo = useMemo(function () {
201
+ return makeProjection({
202
+ projectionConfig: {
203
+ center: cx || cx === 0 || cy || cy === 0 ? [cx, cy] : null,
204
+ rotate: rx || rx === 0 || ry || ry === 0 ? [rx, ry, rz] : null,
205
+ parallels: p1 || p1 === 0 || p2 || p2 === 0 ? [p1, p2] : null,
206
+ scale: s
207
+ },
208
+ projection: projection,
209
+ width: width,
210
+ height: height
211
+ });
212
+ }, [width, height, projection, cx, cy, rx, ry, rz, p1, p2, s]);
213
+ var proj = useCallback(projMemo, [projMemo]);
214
+ var value = useMemo(function () {
215
+ return {
216
+ width: width,
217
+ height: height,
218
+ projection: proj,
219
+ path: geoPath().projection(proj)
220
+ };
221
+ }, [width, height, proj]);
222
+ return /*#__PURE__*/React.createElement(MapContext.Provider, _extends({
223
+ value: value
224
+ }, restProps));
225
+ };
226
+ MapProvider.propTypes = {
227
+ width: PropTypes.number,
228
+ height: PropTypes.number,
229
+ projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
230
+ projectionConfig: PropTypes.object
231
+ };
232
+ var useMapContext = function useMapContext() {
233
+ return useContext(MapContext);
234
+ };
235
+
236
+ var _excluded$9 = ["width", "height", "projection", "projectionConfig", "className"];
237
+ var ComposableMap = forwardRef(function (_ref, ref) {
238
+ var _ref$width = _ref.width,
239
+ width = _ref$width === void 0 ? 800 : _ref$width,
240
+ _ref$height = _ref.height,
241
+ height = _ref$height === void 0 ? 600 : _ref$height,
242
+ _ref$projection = _ref.projection,
243
+ projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
244
+ _ref$projectionConfig = _ref.projectionConfig,
245
+ projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
246
+ _ref$className = _ref.className,
247
+ className = _ref$className === void 0 ? "" : _ref$className,
248
+ restProps = _objectWithoutProperties(_ref, _excluded$9);
249
+ return /*#__PURE__*/React.createElement(MapProvider, {
250
+ width: width,
251
+ height: height,
252
+ projection: projection,
253
+ projectionConfig: projectionConfig
254
+ }, /*#__PURE__*/React.createElement("svg", _extends({
255
+ ref: ref,
256
+ viewBox: "0 0 ".concat(width, " ").concat(height),
257
+ className: "rsm-svg ".concat(className)
258
+ }, restProps)));
259
+ });
260
+ ComposableMap.displayName = "ComposableMap";
261
+ ComposableMap.propTypes = {
262
+ width: PropTypes.number,
263
+ height: PropTypes.number,
264
+ projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
265
+ projectionConfig: PropTypes.object,
266
+ className: PropTypes.string
267
+ };
268
+
269
+ function select(ref) {
270
+ return d3$1.select(ref);
271
+ }
272
+ function getCoords(w, h, t) {
273
+ var xOffset = (w * t.k - w) / 2;
274
+ var yOffset = (h * t.k - h) / 2;
275
+ return [w / 2 - (xOffset + t.x) / t.k, h / 2 - (yOffset + t.y) / t.k];
276
+ }
277
+ function fetchGeographies(url) {
278
+ return fetch(url).then(function (res) {
279
+ if (!res.ok) {
280
+ throw Error(res.statusText);
281
+ }
282
+ return res.json();
283
+ })["catch"](function (error) {
284
+ console.log("There was a problem when fetching the data: ", error);
285
+ });
286
+ }
287
+ function getFeatures(geographies, parseGeographies) {
288
+ var isTopojson = geographies.type === "Topology";
289
+ if (!isTopojson) {
290
+ return parseGeographies ? parseGeographies(geographies.features || geographies) : geographies.features || geographies;
291
+ }
292
+ var feats = feature(geographies, geographies.objects[Object.keys(geographies.objects)[0]]).features;
293
+ return parseGeographies ? parseGeographies(feats) : feats;
294
+ }
295
+ function getMesh(geographies) {
296
+ var isTopojson = geographies.type === "Topology";
297
+ if (!isTopojson) return null;
298
+ var outline = mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
299
+ return a === b;
300
+ });
301
+ var borders = mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
302
+ return a !== b;
303
+ });
304
+ return {
305
+ outline: outline,
306
+ borders: borders
307
+ };
308
+ }
309
+ function prepareMesh(outline, borders, path) {
310
+ return outline && borders ? {
311
+ outline: _objectSpread2(_objectSpread2({}, outline), {}, {
312
+ rsmKey: "outline",
313
+ svgPath: path(outline)
314
+ }),
315
+ borders: _objectSpread2(_objectSpread2({}, borders), {}, {
316
+ rsmKey: "borders",
317
+ svgPath: path(borders)
318
+ })
319
+ } : {};
320
+ }
321
+ function prepareFeatures(geographies, path) {
322
+ return geographies ? geographies.map(function (d, i) {
323
+ return _objectSpread2(_objectSpread2({}, d), {}, {
324
+ rsmKey: "geo-".concat(i),
325
+ svgPath: path(d)
326
+ });
327
+ }) : [];
328
+ }
329
+ function createConnectorPath() {
330
+ var dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 30;
331
+ var dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;
332
+ var curve = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5;
333
+ var curvature = Array.isArray(curve) ? curve : [curve, curve];
334
+ var curveX = dx / 2 * curvature[0];
335
+ var curveY = dy / 2 * curvature[1];
336
+ return "M".concat(0, ",", 0, " Q", -dx / 2 - curveX, ",").concat(-dy / 2 + curveY, " ").concat(-dx, ",").concat(-dy);
337
+ }
338
+ function isString(geo) {
339
+ return typeof geo === "string";
340
+ }
341
+
342
+ function useGeographies(_ref) {
343
+ var geography = _ref.geography,
344
+ parseGeographies = _ref.parseGeographies;
345
+ var _useContext = useContext(MapContext),
346
+ path = _useContext.path;
347
+ var _useState = useState({}),
348
+ _useState2 = _slicedToArray(_useState, 2),
349
+ output = _useState2[0],
350
+ setOutput = _useState2[1];
351
+ useEffect(function () {
352
+ if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "undefined") return;
353
+ if (!geography) return;
354
+ if (isString(geography)) {
355
+ fetchGeographies(geography).then(function (geos) {
356
+ if (geos) {
357
+ setOutput({
358
+ geographies: getFeatures(geos, parseGeographies),
359
+ mesh: getMesh(geos)
360
+ });
361
+ }
362
+ });
363
+ } else {
364
+ setOutput({
365
+ geographies: getFeatures(geography, parseGeographies),
366
+ mesh: getMesh(geography)
367
+ });
368
+ }
369
+ }, [geography, parseGeographies]);
370
+ var _useMemo = useMemo(function () {
371
+ var mesh = output.mesh || {};
372
+ var preparedMesh = prepareMesh(mesh.outline, mesh.borders, path);
373
+ return {
374
+ geographies: prepareFeatures(output.geographies, path),
375
+ outline: preparedMesh.outline,
376
+ borders: preparedMesh.borders
377
+ };
378
+ }, [output, path]),
379
+ geographies = _useMemo.geographies,
380
+ outline = _useMemo.outline,
381
+ borders = _useMemo.borders;
382
+ return {
383
+ geographies: geographies,
384
+ outline: outline,
385
+ borders: borders
386
+ };
387
+ }
388
+
389
+ var _excluded$8 = ["geography", "children", "parseGeographies", "className"];
390
+ var Geographies = forwardRef(function (_ref, ref) {
391
+ var geography = _ref.geography,
392
+ children = _ref.children,
393
+ parseGeographies = _ref.parseGeographies,
394
+ _ref$className = _ref.className,
395
+ className = _ref$className === void 0 ? "" : _ref$className,
396
+ restProps = _objectWithoutProperties(_ref, _excluded$8);
397
+ var _useContext = useContext(MapContext),
398
+ path = _useContext.path,
399
+ projection = _useContext.projection;
400
+ var _useGeographies = useGeographies({
401
+ geography: geography,
402
+ parseGeographies: parseGeographies
403
+ }),
404
+ geographies = _useGeographies.geographies,
405
+ outline = _useGeographies.outline,
406
+ borders = _useGeographies.borders;
407
+ return /*#__PURE__*/React.createElement("g", _extends({
408
+ ref: ref,
409
+ className: "rsm-geographies ".concat(className)
410
+ }, restProps), geographies && geographies.length > 0 && children({
411
+ geographies: geographies,
412
+ outline: outline,
413
+ borders: borders,
414
+ path: path,
415
+ projection: projection
416
+ }));
417
+ });
418
+ Geographies.displayName = "Geographies";
419
+ Geographies.propTypes = {
420
+ geography: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
421
+ children: PropTypes.func,
422
+ parseGeographies: PropTypes.func,
423
+ className: PropTypes.string
424
+ };
425
+
426
+ var _excluded$7 = ["geography", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
427
+ var Geography = forwardRef(function (_ref, ref) {
428
+ var geography = _ref.geography,
429
+ onMouseEnter = _ref.onMouseEnter,
430
+ onMouseLeave = _ref.onMouseLeave,
431
+ onMouseDown = _ref.onMouseDown,
432
+ onMouseUp = _ref.onMouseUp,
433
+ onFocus = _ref.onFocus,
434
+ onBlur = _ref.onBlur,
435
+ _ref$style = _ref.style,
436
+ style = _ref$style === void 0 ? {} : _ref$style,
437
+ _ref$className = _ref.className,
438
+ className = _ref$className === void 0 ? "" : _ref$className,
439
+ restProps = _objectWithoutProperties(_ref, _excluded$7);
440
+ var _useState = useState(false),
441
+ _useState2 = _slicedToArray(_useState, 2),
442
+ isPressed = _useState2[0],
443
+ setPressed = _useState2[1];
444
+ var _useState3 = useState(false),
445
+ _useState4 = _slicedToArray(_useState3, 2),
446
+ isFocused = _useState4[0],
447
+ setFocus = _useState4[1];
448
+ function handleMouseEnter(evt) {
449
+ setFocus(true);
450
+ if (onMouseEnter) onMouseEnter(evt);
451
+ }
452
+ function handleMouseLeave(evt) {
453
+ setFocus(false);
454
+ if (isPressed) setPressed(false);
455
+ if (onMouseLeave) onMouseLeave(evt);
456
+ }
457
+ function handleFocus(evt) {
458
+ setFocus(true);
459
+ if (onFocus) onFocus(evt);
460
+ }
461
+ function handleBlur(evt) {
462
+ setFocus(false);
463
+ if (isPressed) setPressed(false);
464
+ if (onBlur) onBlur(evt);
465
+ }
466
+ function handleMouseDown(evt) {
467
+ setPressed(true);
468
+ if (onMouseDown) onMouseDown(evt);
469
+ }
470
+ function handleMouseUp(evt) {
471
+ setPressed(false);
472
+ if (onMouseUp) onMouseUp(evt);
473
+ }
474
+ return /*#__PURE__*/React.createElement("path", _extends({
475
+ ref: ref,
476
+ tabIndex: "0",
477
+ className: "rsm-geography ".concat(className),
478
+ d: geography.svgPath,
479
+ onMouseEnter: handleMouseEnter,
480
+ onMouseLeave: handleMouseLeave,
481
+ onFocus: handleFocus,
482
+ onBlur: handleBlur,
483
+ onMouseDown: handleMouseDown,
484
+ onMouseUp: handleMouseUp,
485
+ style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
486
+ }, restProps));
487
+ });
488
+ Geography.displayName = "Geography";
489
+ Geography.propTypes = {
490
+ geography: PropTypes.object,
491
+ onMouseEnter: PropTypes.func,
492
+ onMouseLeave: PropTypes.func,
493
+ onMouseDown: PropTypes.func,
494
+ onMouseUp: PropTypes.func,
495
+ onFocus: PropTypes.func,
496
+ onBlur: PropTypes.func,
497
+ style: PropTypes.object,
498
+ className: PropTypes.string
499
+ };
500
+ var Geography$1 = memo(Geography);
501
+
502
+ var _excluded$6 = ["fill", "stroke", "step", "className"];
503
+ var Graticule = forwardRef(function (_ref, ref) {
504
+ var _ref$fill = _ref.fill,
505
+ fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
506
+ _ref$stroke = _ref.stroke,
507
+ stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
508
+ _ref$step = _ref.step,
509
+ step = _ref$step === void 0 ? [10, 10] : _ref$step,
510
+ _ref$className = _ref.className,
511
+ className = _ref$className === void 0 ? "" : _ref$className,
512
+ restProps = _objectWithoutProperties(_ref, _excluded$6);
513
+ var _useContext = useContext(MapContext),
514
+ path = _useContext.path;
515
+ return /*#__PURE__*/React.createElement("path", _extends({
516
+ ref: ref,
517
+ d: path(d3.geoGraticule().step(step)()),
518
+ fill: fill,
519
+ stroke: stroke,
520
+ className: "rsm-graticule ".concat(className)
521
+ }, restProps));
522
+ });
523
+ Graticule.displayName = "Graticule";
524
+ Graticule.propTypes = {
525
+ fill: PropTypes.string,
526
+ stroke: PropTypes.string,
527
+ step: PropTypes.array,
528
+ className: PropTypes.string
529
+ };
530
+ var Graticule$1 = memo(Graticule);
531
+
532
+ var _excluded$5 = ["value"];
533
+ var ZoomPanContext = createContext();
534
+ var defaultValue = {
535
+ x: 0,
536
+ y: 0,
537
+ k: 1,
538
+ transformString: "translate(0 0) scale(1)"
539
+ };
540
+ var ZoomPanProvider = function ZoomPanProvider(_ref) {
541
+ var _ref$value = _ref.value,
542
+ value = _ref$value === void 0 ? defaultValue : _ref$value,
543
+ restProps = _objectWithoutProperties(_ref, _excluded$5);
544
+ return /*#__PURE__*/React.createElement(ZoomPanContext.Provider, _extends({
545
+ value: value
546
+ }, restProps));
547
+ };
548
+ ZoomPanProvider.propTypes = {
549
+ x: PropTypes.number,
550
+ y: PropTypes.number,
551
+ k: PropTypes.number,
552
+ transformString: PropTypes.string
553
+ };
554
+ var useZoomPanContext = function useZoomPanContext() {
555
+ return useContext(ZoomPanContext);
556
+ };
557
+
558
+ function useZoomPan(_ref) {
559
+ var center = _ref.center,
560
+ filterZoomEvent = _ref.filterZoomEvent,
561
+ onMoveStart = _ref.onMoveStart,
562
+ onMoveEnd = _ref.onMoveEnd,
563
+ onMove = _ref.onMove,
564
+ _ref$translateExtent = _ref.translateExtent,
565
+ translateExtent = _ref$translateExtent === void 0 ? [[-Infinity, -Infinity], [Infinity, Infinity]] : _ref$translateExtent,
566
+ _ref$scaleExtent = _ref.scaleExtent,
567
+ scaleExtent = _ref$scaleExtent === void 0 ? [1, 8] : _ref$scaleExtent,
568
+ _ref$zoom = _ref.zoom,
569
+ zoom = _ref$zoom === void 0 ? 1 : _ref$zoom;
570
+ var _useContext = useContext(MapContext),
571
+ width = _useContext.width,
572
+ height = _useContext.height,
573
+ projection = _useContext.projection;
574
+ var _center = _slicedToArray(center, 2),
575
+ lon = _center[0],
576
+ lat = _center[1];
577
+ var _useState = useState({
578
+ x: 0,
579
+ y: 0,
580
+ k: 1
581
+ }),
582
+ _useState2 = _slicedToArray(_useState, 2),
583
+ position = _useState2[0],
584
+ setPosition = _useState2[1];
585
+ var lastPosition = useRef({
586
+ x: 0,
587
+ y: 0,
588
+ k: 1
589
+ });
590
+ var mapRef = useRef();
591
+ var zoomRef = useRef();
592
+ var bypassEvents = useRef(false);
593
+ var _translateExtent = _slicedToArray(translateExtent, 2),
594
+ a = _translateExtent[0],
595
+ b = _translateExtent[1];
596
+ var _a = _slicedToArray(a, 2),
597
+ a1 = _a[0],
598
+ a2 = _a[1];
599
+ var _b = _slicedToArray(b, 2),
600
+ b1 = _b[0],
601
+ b2 = _b[1];
602
+ var _scaleExtent = _slicedToArray(scaleExtent, 2),
603
+ minZoom = _scaleExtent[0],
604
+ maxZoom = _scaleExtent[1];
605
+ useEffect(function () {
606
+ var svg = select(mapRef.current);
607
+ function handleZoomStart(d3Event) {
608
+ if (!onMoveStart || bypassEvents.current) return;
609
+ onMoveStart({
610
+ coordinates: projection.invert(getCoords(width, height, d3Event.transform)),
611
+ zoom: d3Event.transform.k
612
+ }, d3Event);
613
+ }
614
+ function handleZoom(d3Event) {
615
+ if (bypassEvents.current) return;
616
+ var transform = d3Event.transform,
617
+ sourceEvent = d3Event.sourceEvent;
618
+ setPosition({
619
+ x: transform.x,
620
+ y: transform.y,
621
+ k: transform.k,
622
+ dragging: sourceEvent
623
+ });
624
+ if (!onMove) return;
625
+ onMove({
626
+ x: transform.x,
627
+ y: transform.y,
628
+ zoom: transform.k,
629
+ dragging: sourceEvent
630
+ }, d3Event);
631
+ }
632
+ function handleZoomEnd(d3Event) {
633
+ if (bypassEvents.current) {
634
+ bypassEvents.current = false;
635
+ return;
636
+ }
637
+ var _projection$invert = projection.invert(getCoords(width, height, d3Event.transform)),
638
+ _projection$invert2 = _slicedToArray(_projection$invert, 2),
639
+ x = _projection$invert2[0],
640
+ y = _projection$invert2[1];
641
+ lastPosition.current = {
642
+ x: x,
643
+ y: y,
644
+ k: d3Event.transform.k
645
+ };
646
+ if (!onMoveEnd) return;
647
+ onMoveEnd({
648
+ coordinates: [x, y],
649
+ zoom: d3Event.transform.k
650
+ }, d3Event);
651
+ }
652
+ function filterFunc(d3Event) {
653
+ if (filterZoomEvent) {
654
+ return filterZoomEvent(d3Event);
655
+ }
656
+ return d3Event ? !d3Event.ctrlKey && !d3Event.button : false;
657
+ }
658
+ var zoom = d3$2.zoom().filter(filterFunc).scaleExtent([minZoom, maxZoom]).translateExtent([[a1, a2], [b1, b2]]).on("start", handleZoomStart).on("zoom", handleZoom).on("end", handleZoomEnd);
659
+ zoomRef.current = zoom;
660
+ svg.call(zoom);
661
+ }, [width, height, a1, a2, b1, b2, minZoom, maxZoom, projection, onMoveStart, onMove, onMoveEnd, filterZoomEvent]);
662
+ useEffect(function () {
663
+ if (lon === lastPosition.current.x && lat === lastPosition.current.y && zoom === lastPosition.current.k) return;
664
+ var coords = projection([lon, lat]);
665
+ var x = coords[0] * zoom;
666
+ var y = coords[1] * zoom;
667
+ var svg = select(mapRef.current);
668
+ bypassEvents.current = true;
669
+ svg.call(zoomRef.current.transform, d3$2.zoomIdentity.translate(width / 2 - x, height / 2 - y).scale(zoom));
670
+ setPosition({
671
+ x: width / 2 - x,
672
+ y: height / 2 - y,
673
+ k: zoom
674
+ });
675
+ lastPosition.current = {
676
+ x: lon,
677
+ y: lat,
678
+ k: zoom
679
+ };
680
+ }, [lon, lat, zoom, width, height, projection]);
681
+ return {
682
+ mapRef: mapRef,
683
+ position: position,
684
+ transformString: "translate(".concat(position.x, " ").concat(position.y, ") scale(").concat(position.k, ")")
685
+ };
686
+ }
687
+
688
+ var _excluded$4 = ["center", "zoom", "minZoom", "maxZoom", "translateExtent", "filterZoomEvent", "onMoveStart", "onMove", "onMoveEnd", "className"];
689
+ var ZoomableGroup = forwardRef(function (_ref, ref) {
690
+ var _ref$center = _ref.center,
691
+ center = _ref$center === void 0 ? [0, 0] : _ref$center,
692
+ _ref$zoom = _ref.zoom,
693
+ zoom = _ref$zoom === void 0 ? 1 : _ref$zoom,
694
+ _ref$minZoom = _ref.minZoom,
695
+ minZoom = _ref$minZoom === void 0 ? 1 : _ref$minZoom,
696
+ _ref$maxZoom = _ref.maxZoom,
697
+ maxZoom = _ref$maxZoom === void 0 ? 8 : _ref$maxZoom,
698
+ translateExtent = _ref.translateExtent,
699
+ filterZoomEvent = _ref.filterZoomEvent,
700
+ onMoveStart = _ref.onMoveStart,
701
+ onMove = _ref.onMove,
702
+ onMoveEnd = _ref.onMoveEnd,
703
+ className = _ref.className,
704
+ restProps = _objectWithoutProperties(_ref, _excluded$4);
705
+ var _useContext = useContext(MapContext),
706
+ width = _useContext.width,
707
+ height = _useContext.height;
708
+ var _useZoomPan = useZoomPan({
709
+ center: center,
710
+ filterZoomEvent: filterZoomEvent,
711
+ onMoveStart: onMoveStart,
712
+ onMove: onMove,
713
+ onMoveEnd: onMoveEnd,
714
+ scaleExtent: [minZoom, maxZoom],
715
+ translateExtent: translateExtent,
716
+ zoom: zoom
717
+ }),
718
+ mapRef = _useZoomPan.mapRef,
719
+ transformString = _useZoomPan.transformString,
720
+ position = _useZoomPan.position;
721
+ return /*#__PURE__*/React.createElement(ZoomPanProvider, {
722
+ value: {
723
+ x: position.x,
724
+ y: position.y,
725
+ k: position.k,
726
+ transformString: transformString
727
+ }
728
+ }, /*#__PURE__*/React.createElement("g", {
729
+ ref: mapRef
730
+ }, /*#__PURE__*/React.createElement("rect", {
731
+ width: width,
732
+ height: height,
733
+ fill: "transparent"
734
+ }), /*#__PURE__*/React.createElement("g", _extends({
735
+ ref: ref,
736
+ transform: transformString,
737
+ className: "rsm-zoomable-group ".concat(className)
738
+ }, restProps))));
739
+ });
740
+ ZoomableGroup.displayName = "ZoomableGroup";
741
+ ZoomableGroup.propTypes = {
742
+ center: PropTypes.array,
743
+ zoom: PropTypes.number,
744
+ minZoom: PropTypes.number,
745
+ maxZoom: PropTypes.number,
746
+ translateExtent: PropTypes.arrayOf(PropTypes.array),
747
+ onMoveStart: PropTypes.func,
748
+ onMove: PropTypes.func,
749
+ onMoveEnd: PropTypes.func,
750
+ className: PropTypes.string
751
+ };
752
+
753
+ var _excluded$3 = ["id", "fill", "stroke", "strokeWidth", "className"];
754
+ var Sphere = forwardRef(function (_ref, ref) {
755
+ var _ref$id = _ref.id,
756
+ id = _ref$id === void 0 ? "rsm-sphere" : _ref$id,
757
+ _ref$fill = _ref.fill,
758
+ fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
759
+ _ref$stroke = _ref.stroke,
760
+ stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
761
+ _ref$strokeWidth = _ref.strokeWidth,
762
+ strokeWidth = _ref$strokeWidth === void 0 ? 0.5 : _ref$strokeWidth,
763
+ _ref$className = _ref.className,
764
+ className = _ref$className === void 0 ? "" : _ref$className,
765
+ restProps = _objectWithoutProperties(_ref, _excluded$3);
766
+ var _useContext = useContext(MapContext),
767
+ path = _useContext.path;
768
+ var spherePath = useMemo(function () {
769
+ return path({
770
+ type: "Sphere"
771
+ });
772
+ }, [path]);
773
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
774
+ id: id
775
+ }, /*#__PURE__*/React.createElement("path", {
776
+ d: spherePath
777
+ }))), /*#__PURE__*/React.createElement("path", _extends({
778
+ ref: ref,
779
+ d: spherePath,
780
+ fill: fill,
781
+ stroke: stroke,
782
+ strokeWidth: strokeWidth,
783
+ style: {
784
+ pointerEvents: "none"
785
+ },
786
+ className: "rsm-sphere ".concat(className)
787
+ }, restProps)));
788
+ });
789
+ Sphere.displayName = "Sphere";
790
+ Sphere.propTypes = {
791
+ id: PropTypes.string,
792
+ fill: PropTypes.string,
793
+ stroke: PropTypes.string,
794
+ strokeWidth: PropTypes.number,
795
+ className: PropTypes.string
796
+ };
797
+ var Sphere$1 = memo(Sphere);
798
+
799
+ var _excluded$2 = ["coordinates", "children", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
800
+ var Marker = forwardRef(function (_ref, ref) {
801
+ var coordinates = _ref.coordinates,
802
+ children = _ref.children,
803
+ onMouseEnter = _ref.onMouseEnter,
804
+ onMouseLeave = _ref.onMouseLeave,
805
+ onMouseDown = _ref.onMouseDown,
806
+ onMouseUp = _ref.onMouseUp,
807
+ onFocus = _ref.onFocus,
808
+ onBlur = _ref.onBlur,
809
+ _ref$style = _ref.style,
810
+ style = _ref$style === void 0 ? {} : _ref$style,
811
+ _ref$className = _ref.className,
812
+ className = _ref$className === void 0 ? "" : _ref$className,
813
+ restProps = _objectWithoutProperties(_ref, _excluded$2);
814
+ var _useContext = useContext(MapContext),
815
+ projection = _useContext.projection;
816
+ var _useState = useState(false),
817
+ _useState2 = _slicedToArray(_useState, 2),
818
+ isPressed = _useState2[0],
819
+ setPressed = _useState2[1];
820
+ var _useState3 = useState(false),
821
+ _useState4 = _slicedToArray(_useState3, 2),
822
+ isFocused = _useState4[0],
823
+ setFocus = _useState4[1];
824
+ var _projection = projection(coordinates),
825
+ _projection2 = _slicedToArray(_projection, 2),
826
+ x = _projection2[0],
827
+ y = _projection2[1];
828
+ function handleMouseEnter(evt) {
829
+ setFocus(true);
830
+ if (onMouseEnter) onMouseEnter(evt);
831
+ }
832
+ function handleMouseLeave(evt) {
833
+ setFocus(false);
834
+ if (isPressed) setPressed(false);
835
+ if (onMouseLeave) onMouseLeave(evt);
836
+ }
837
+ function handleFocus(evt) {
838
+ setFocus(true);
839
+ if (onFocus) onFocus(evt);
840
+ }
841
+ function handleBlur(evt) {
842
+ setFocus(false);
843
+ if (isPressed) setPressed(false);
844
+ if (onBlur) onBlur(evt);
845
+ }
846
+ function handleMouseDown(evt) {
847
+ setPressed(true);
848
+ if (onMouseDown) onMouseDown(evt);
849
+ }
850
+ function handleMouseUp(evt) {
851
+ setPressed(false);
852
+ if (onMouseUp) onMouseUp(evt);
853
+ }
854
+ return /*#__PURE__*/React.createElement("g", _extends({
855
+ ref: ref,
856
+ transform: "translate(".concat(x, ", ").concat(y, ")"),
857
+ className: "rsm-marker ".concat(className),
858
+ onMouseEnter: handleMouseEnter,
859
+ onMouseLeave: handleMouseLeave,
860
+ onFocus: handleFocus,
861
+ onBlur: handleBlur,
862
+ onMouseDown: handleMouseDown,
863
+ onMouseUp: handleMouseUp,
864
+ style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
865
+ }, restProps), children);
866
+ });
867
+ Marker.displayName = "Marker";
868
+ Marker.propTypes = {
869
+ coordinates: PropTypes.array,
870
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
871
+ onMouseEnter: PropTypes.func,
872
+ onMouseLeave: PropTypes.func,
873
+ onMouseDown: PropTypes.func,
874
+ onMouseUp: PropTypes.func,
875
+ onFocus: PropTypes.func,
876
+ onBlur: PropTypes.func,
877
+ style: PropTypes.object,
878
+ className: PropTypes.string
879
+ };
880
+
881
+ var _excluded$1 = ["from", "to", "coordinates", "stroke", "strokeWidth", "fill", "className"];
882
+ var Line = forwardRef(function (_ref, ref) {
883
+ var _ref$from = _ref.from,
884
+ from = _ref$from === void 0 ? [0, 0] : _ref$from,
885
+ _ref$to = _ref.to,
886
+ to = _ref$to === void 0 ? [0, 0] : _ref$to,
887
+ coordinates = _ref.coordinates,
888
+ _ref$stroke = _ref.stroke,
889
+ stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
890
+ _ref$strokeWidth = _ref.strokeWidth,
891
+ strokeWidth = _ref$strokeWidth === void 0 ? 3 : _ref$strokeWidth,
892
+ _ref$fill = _ref.fill,
893
+ fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
894
+ _ref$className = _ref.className,
895
+ className = _ref$className === void 0 ? "" : _ref$className,
896
+ restProps = _objectWithoutProperties(_ref, _excluded$1);
897
+ var _useContext = useContext(MapContext),
898
+ path = _useContext.path;
899
+ var lineData = {
900
+ type: "LineString",
901
+ coordinates: coordinates || [from, to]
902
+ };
903
+ return /*#__PURE__*/React.createElement("path", _extends({
904
+ ref: ref,
905
+ d: path(lineData),
906
+ className: "rsm-line ".concat(className),
907
+ stroke: stroke,
908
+ strokeWidth: strokeWidth,
909
+ fill: fill
910
+ }, restProps));
911
+ });
912
+ Line.displayName = "Line";
913
+ Line.propTypes = {
914
+ from: PropTypes.array,
915
+ to: PropTypes.array,
916
+ coordinates: PropTypes.array,
917
+ stroke: PropTypes.string,
918
+ strokeWidth: PropTypes.number,
919
+ fill: PropTypes.string,
920
+ className: PropTypes.string
921
+ };
922
+
923
+ var _excluded = ["subject", "children", "connectorProps", "dx", "dy", "curve", "className"];
924
+ var Annotation = forwardRef(function (_ref, ref) {
925
+ var subject = _ref.subject,
926
+ children = _ref.children,
927
+ connectorProps = _ref.connectorProps,
928
+ _ref$dx = _ref.dx,
929
+ dx = _ref$dx === void 0 ? 30 : _ref$dx,
930
+ _ref$dy = _ref.dy,
931
+ dy = _ref$dy === void 0 ? 30 : _ref$dy,
932
+ _ref$curve = _ref.curve,
933
+ curve = _ref$curve === void 0 ? 0 : _ref$curve,
934
+ _ref$className = _ref.className,
935
+ className = _ref$className === void 0 ? "" : _ref$className,
936
+ restProps = _objectWithoutProperties(_ref, _excluded);
937
+ var _useContext = useContext(MapContext),
938
+ projection = _useContext.projection;
939
+ var _projection = projection(subject),
940
+ _projection2 = _slicedToArray(_projection, 2),
941
+ x = _projection2[0],
942
+ y = _projection2[1];
943
+ var connectorPath = createConnectorPath(dx, dy, curve);
944
+ return /*#__PURE__*/React.createElement("g", _extends({
945
+ ref: ref,
946
+ transform: "translate(".concat(x + dx, ", ").concat(y + dy, ")"),
947
+ className: "rsm-annotation ".concat(className)
948
+ }, restProps), /*#__PURE__*/React.createElement("path", _extends({
949
+ d: connectorPath,
950
+ fill: "transparent",
951
+ stroke: "#000"
952
+ }, connectorProps)), children);
953
+ });
954
+ Annotation.displayName = "Annotation";
955
+ Annotation.propTypes = {
956
+ subject: PropTypes.array,
957
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
958
+ dx: PropTypes.number,
959
+ dy: PropTypes.number,
960
+ curve: PropTypes.number,
961
+ connectorProps: PropTypes.object,
962
+ className: PropTypes.string
963
+ };
964
+
965
+ export { Annotation, ComposableMap, Geographies, Geography$1 as Geography, Graticule$1 as Graticule, Line, MapContext, MapProvider, Marker, Sphere$1 as Sphere, ZoomPanContext, ZoomPanProvider, ZoomableGroup, useGeographies, useMapContext, useZoomPan, useZoomPanContext };