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

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