Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-simple-maps

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-maps - npm Package Compare versions

Comparing version 4.0.0-beta.2 to 4.0.0-beta.3

963

dist/index.es.js

@@ -1,962 +0,1 @@

import React, { createContext, useMemo, useCallback, useContext, forwardRef, useState, useEffect, memo, useRef, Fragment } from 'react';
import PropTypes from 'prop-types';
import * as d3Geo from 'd3-geo';
import { feature, mesh } from 'topojson-client';
import * as d3Zoom from 'd3-zoom';
import * as d3Select from 'd3-selection';
function _iterableToArrayLimit(arr, i) {
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
if (null != _i) {
var _s,
_e,
_x,
_r,
_arr = [],
_n = !0,
_d = !1;
try {
if (_x = (_i = _i.call(arr)).next, 0 === i) {
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
} catch (err) {
_d = !0, _e = err;
} finally {
try {
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
} finally {
if (_d) throw _e;
}
}
return _arr;
}
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
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 _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var _excluded$a = ["width", "height", "projection", "projectionConfig"];
var geoPath = d3Geo.geoPath,
projections = _objectWithoutProperties(d3Geo, ["geoPath"]);
var MapContext = createContext();
var makeProjection = function makeProjection(_ref) {
var _ref$projectionConfig = _ref.projectionConfig,
projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
_ref$projection = _ref.projection,
projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
_ref$width = _ref.width,
width = _ref$width === void 0 ? 800 : _ref$width,
_ref$height = _ref.height,
height = _ref$height === void 0 ? 600 : _ref$height;
var isFunc = typeof projection === "function";
if (isFunc) return projection;
var proj = projections[projection]().translate([width / 2, height / 2]);
var supported = [proj.center ? "center" : null, proj.rotate ? "rotate" : null, proj.scale ? "scale" : null, proj.parallels ? "parallels" : null];
supported.forEach(function (d) {
if (!d) return;
proj = proj[d](projectionConfig[d] || proj[d]());
});
return proj;
};
var MapProvider = function MapProvider(_ref2) {
var width = _ref2.width,
height = _ref2.height,
projection = _ref2.projection,
projectionConfig = _ref2.projectionConfig,
restProps = _objectWithoutProperties(_ref2, _excluded$a);
var _ref3 = projectionConfig.center || [],
_ref4 = _slicedToArray(_ref3, 2),
cx = _ref4[0],
cy = _ref4[1];
var _ref5 = projectionConfig.rotate || [],
_ref6 = _slicedToArray(_ref5, 3),
rx = _ref6[0],
ry = _ref6[1],
rz = _ref6[2];
var _ref7 = projectionConfig.parallels || [],
_ref8 = _slicedToArray(_ref7, 2),
p1 = _ref8[0],
p2 = _ref8[1];
var s = projectionConfig.scale || null;
var projMemo = useMemo(function () {
return makeProjection({
projectionConfig: {
center: cx || cx === 0 || cy || cy === 0 ? [cx, cy] : null,
rotate: rx || rx === 0 || ry || ry === 0 ? [rx, ry, rz] : null,
parallels: p1 || p1 === 0 || p2 || p2 === 0 ? [p1, p2] : null,
scale: s
},
projection: projection,
width: width,
height: height
});
}, [width, height, projection, cx, cy, rx, ry, rz, p1, p2, s]);
var proj = useCallback(projMemo, [projMemo]);
var value = useMemo(function () {
return {
width: width,
height: height,
projection: proj,
path: geoPath().projection(proj)
};
}, [width, height, proj]);
return /*#__PURE__*/React.createElement(MapContext.Provider, _extends({
value: value
}, restProps));
};
MapProvider.propTypes = {
width: PropTypes.number,
height: PropTypes.number,
projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
projectionConfig: PropTypes.object
};
var useMapContext = function useMapContext() {
return useContext(MapContext);
};
var _excluded$9 = ["width", "height", "projection", "projectionConfig", "className"];
var ComposableMap = forwardRef(function (_ref, ref) {
var _ref$width = _ref.width,
width = _ref$width === void 0 ? 800 : _ref$width,
_ref$height = _ref.height,
height = _ref$height === void 0 ? 600 : _ref$height,
_ref$projection = _ref.projection,
projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
_ref$projectionConfig = _ref.projectionConfig,
projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$9);
return /*#__PURE__*/React.createElement(MapProvider, {
width: width,
height: height,
projection: projection,
projectionConfig: projectionConfig
}, /*#__PURE__*/React.createElement("svg", _extends({
ref: ref,
viewBox: "0 0 ".concat(width, " ").concat(height),
className: "rsm-svg ".concat(className)
}, restProps)));
});
ComposableMap.displayName = "ComposableMap";
ComposableMap.propTypes = {
width: PropTypes.number,
height: PropTypes.number,
projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
projectionConfig: PropTypes.object,
className: PropTypes.string
};
function getCoords(w, h, t) {
var xOffset = (w * t.k - w) / 2;
var yOffset = (h * t.k - h) / 2;
return [w / 2 - (xOffset + t.x) / t.k, h / 2 - (yOffset + t.y) / t.k];
}
function fetchGeographies(url) {
return fetch(url).then(function (res) {
if (!res.ok) {
throw Error(res.statusText);
}
return res.json();
})["catch"](function (error) {
console.log("There was a problem when fetching the data: ", error);
});
}
function getFeatures(geographies, parseGeographies) {
var isTopojson = geographies.type === "Topology";
if (!isTopojson) {
return parseGeographies ? parseGeographies(geographies.features || geographies) : geographies.features || geographies;
}
var feats = feature(geographies, geographies.objects[Object.keys(geographies.objects)[0]]).features;
return parseGeographies ? parseGeographies(feats) : feats;
}
function getMesh(geographies) {
var isTopojson = geographies.type === "Topology";
if (!isTopojson) return null;
var outline = mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
return a === b;
});
var borders = mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
return a !== b;
});
return {
outline: outline,
borders: borders
};
}
function prepareMesh(outline, borders, path) {
return outline && borders ? {
outline: _objectSpread2(_objectSpread2({}, outline), {}, {
rsmKey: "outline",
svgPath: path(outline)
}),
borders: _objectSpread2(_objectSpread2({}, borders), {}, {
rsmKey: "borders",
svgPath: path(borders)
})
} : {};
}
function prepareFeatures(geographies, path) {
return geographies ? geographies.map(function (d, i) {
return _objectSpread2(_objectSpread2({}, d), {}, {
rsmKey: "geo-".concat(i),
svgPath: path(d)
});
}) : [];
}
function createConnectorPath() {
var dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 30;
var dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;
var curve = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5;
var curvature = Array.isArray(curve) ? curve : [curve, curve];
var curveX = dx / 2 * curvature[0];
var curveY = dy / 2 * curvature[1];
return "M".concat(0, ",", 0, " Q", -dx / 2 - curveX, ",").concat(-dy / 2 + curveY, " ").concat(-dx, ",").concat(-dy);
}
function isString(geo) {
return typeof geo === "string";
}
function useGeographies(_ref) {
var geography = _ref.geography,
parseGeographies = _ref.parseGeographies;
var _useContext = useContext(MapContext),
path = _useContext.path;
var _useState = useState({}),
_useState2 = _slicedToArray(_useState, 2),
output = _useState2[0],
setOutput = _useState2[1];
useEffect(function () {
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "undefined") return;
if (!geography) return;
if (isString(geography)) {
fetchGeographies(geography).then(function (geos) {
if (geos) {
setOutput({
geographies: getFeatures(geos, parseGeographies),
mesh: getMesh(geos)
});
}
});
} else {
setOutput({
geographies: getFeatures(geography, parseGeographies),
mesh: getMesh(geography)
});
}
}, [geography, parseGeographies]);
var _useMemo = useMemo(function () {
var mesh = output.mesh || {};
var preparedMesh = prepareMesh(mesh.outline, mesh.borders, path);
return {
geographies: prepareFeatures(output.geographies, path),
outline: preparedMesh.outline,
borders: preparedMesh.borders
};
}, [output, path]),
geographies = _useMemo.geographies,
outline = _useMemo.outline,
borders = _useMemo.borders;
return {
geographies: geographies,
outline: outline,
borders: borders
};
}
var _excluded$8 = ["geography", "children", "parseGeographies", "className"];
var Geographies = forwardRef(function (_ref, ref) {
var geography = _ref.geography,
children = _ref.children,
parseGeographies = _ref.parseGeographies,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$8);
var _useContext = useContext(MapContext),
path = _useContext.path,
projection = _useContext.projection;
var _useGeographies = useGeographies({
geography: geography,
parseGeographies: parseGeographies
}),
geographies = _useGeographies.geographies,
outline = _useGeographies.outline,
borders = _useGeographies.borders;
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
className: "rsm-geographies ".concat(className)
}, restProps), geographies && geographies.length > 0 && children({
geographies: geographies,
outline: outline,
borders: borders,
path: path,
projection: projection
}));
});
Geographies.displayName = "Geographies";
Geographies.propTypes = {
geography: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
children: PropTypes.func,
parseGeographies: PropTypes.func,
className: PropTypes.string
};
var _excluded$7 = ["geography", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
var Geography = forwardRef(function (_ref, ref) {
var geography = _ref.geography,
onMouseEnter = _ref.onMouseEnter,
onMouseLeave = _ref.onMouseLeave,
onMouseDown = _ref.onMouseDown,
onMouseUp = _ref.onMouseUp,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur,
_ref$style = _ref.style,
style = _ref$style === void 0 ? {} : _ref$style,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$7);
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isPressed = _useState2[0],
setPressed = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isFocused = _useState4[0],
setFocus = _useState4[1];
function handleMouseEnter(evt) {
setFocus(true);
if (onMouseEnter) onMouseEnter(evt);
}
function handleMouseLeave(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onMouseLeave) onMouseLeave(evt);
}
function handleFocus(evt) {
setFocus(true);
if (onFocus) onFocus(evt);
}
function handleBlur(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onBlur) onBlur(evt);
}
function handleMouseDown(evt) {
setPressed(true);
if (onMouseDown) onMouseDown(evt);
}
function handleMouseUp(evt) {
setPressed(false);
if (onMouseUp) onMouseUp(evt);
}
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
tabIndex: "0",
className: "rsm-geography ".concat(className),
d: geography.svgPath,
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onFocus: handleFocus,
onBlur: handleBlur,
onMouseDown: handleMouseDown,
onMouseUp: handleMouseUp,
style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
}, restProps));
});
Geography.displayName = "Geography";
Geography.propTypes = {
geography: PropTypes.object,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
style: PropTypes.object,
className: PropTypes.string
};
var Geography$1 = memo(Geography);
var _excluded$6 = ["fill", "stroke", "step", "className"];
var Graticule = forwardRef(function (_ref, ref) {
var _ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$step = _ref.step,
step = _ref$step === void 0 ? [10, 10] : _ref$step,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$6);
var _useContext = useContext(MapContext),
path = _useContext.path;
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: path(d3Geo.geoGraticule().step(step)()),
fill: fill,
stroke: stroke,
className: "rsm-graticule ".concat(className)
}, restProps));
});
Graticule.displayName = "Graticule";
Graticule.propTypes = {
fill: PropTypes.string,
stroke: PropTypes.string,
step: PropTypes.array,
className: PropTypes.string
};
var Graticule$1 = memo(Graticule);
var _excluded$5 = ["value"];
var ZoomPanContext = createContext();
var defaultValue = {
x: 0,
y: 0,
k: 1,
transformString: "translate(0 0) scale(1)"
};
var ZoomPanProvider = function ZoomPanProvider(_ref) {
var _ref$value = _ref.value,
value = _ref$value === void 0 ? defaultValue : _ref$value,
restProps = _objectWithoutProperties(_ref, _excluded$5);
return /*#__PURE__*/React.createElement(ZoomPanContext.Provider, _extends({
value: value
}, restProps));
};
ZoomPanProvider.propTypes = {
x: PropTypes.number,
y: PropTypes.number,
k: PropTypes.number,
transformString: PropTypes.string
};
var useZoomPanContext = function useZoomPanContext() {
return useContext(ZoomPanContext);
};
function useZoomPan(_ref) {
var center = _ref.center,
filterZoomEvent = _ref.filterZoomEvent,
onMoveStart = _ref.onMoveStart,
onMoveEnd = _ref.onMoveEnd,
onMove = _ref.onMove,
_ref$translateExtent = _ref.translateExtent,
translateExtent = _ref$translateExtent === void 0 ? [[-Infinity, -Infinity], [Infinity, Infinity]] : _ref$translateExtent,
_ref$scaleExtent = _ref.scaleExtent,
scaleExtent = _ref$scaleExtent === void 0 ? [1, 8] : _ref$scaleExtent,
_ref$zoom = _ref.zoom,
zoom = _ref$zoom === void 0 ? 1 : _ref$zoom;
var _useContext = useContext(MapContext),
width = _useContext.width,
height = _useContext.height,
projection = _useContext.projection;
var _center = _slicedToArray(center, 2),
lon = _center[0],
lat = _center[1];
var _useState = useState({
x: 0,
y: 0,
k: 1
}),
_useState2 = _slicedToArray(_useState, 2),
position = _useState2[0],
setPosition = _useState2[1];
var lastPosition = useRef({
x: 0,
y: 0,
k: 1
});
var mapRef = useRef();
var zoomRef = useRef();
var bypassEvents = useRef(false);
var _translateExtent = _slicedToArray(translateExtent, 2),
a = _translateExtent[0],
b = _translateExtent[1];
var _a = _slicedToArray(a, 2),
a1 = _a[0],
a2 = _a[1];
var _b = _slicedToArray(b, 2),
b1 = _b[0],
b2 = _b[1];
var _scaleExtent = _slicedToArray(scaleExtent, 2),
minZoom = _scaleExtent[0],
maxZoom = _scaleExtent[1];
useEffect(function () {
var svg = d3Select.select(mapRef.current);
function handleZoomStart(d3Event) {
if (!onMoveStart || bypassEvents.current) return;
onMoveStart({
coordinates: projection.invert(getCoords(width, height, d3Event.transform)),
zoom: d3Event.transform.k
}, d3Event);
}
function handleZoom(d3Event) {
if (bypassEvents.current) return;
var transform = d3Event.transform,
sourceEvent = d3Event.sourceEvent;
setPosition({
x: transform.x,
y: transform.y,
k: transform.k,
dragging: sourceEvent
});
if (!onMove) return;
onMove({
x: transform.x,
y: transform.y,
zoom: transform.k,
dragging: sourceEvent
}, d3Event);
}
function handleZoomEnd(d3Event) {
if (bypassEvents.current) {
bypassEvents.current = false;
return;
}
var _projection$invert = projection.invert(getCoords(width, height, d3Event.transform)),
_projection$invert2 = _slicedToArray(_projection$invert, 2),
x = _projection$invert2[0],
y = _projection$invert2[1];
lastPosition.current = {
x: x,
y: y,
k: d3Event.transform.k
};
if (!onMoveEnd) return;
onMoveEnd({
coordinates: [x, y],
zoom: d3Event.transform.k
}, d3Event);
}
function filterFunc(d3Event) {
if (filterZoomEvent) {
return filterZoomEvent(d3Event);
}
return d3Event ? !d3Event.ctrlKey && !d3Event.button : false;
}
var zoom = d3Zoom.zoom().filter(filterFunc).scaleExtent([minZoom, maxZoom]).translateExtent([[a1, a2], [b1, b2]]).on("start", handleZoomStart).on("zoom", handleZoom).on("end", handleZoomEnd);
zoomRef.current = zoom;
svg.call(zoom);
}, [width, height, a1, a2, b1, b2, minZoom, maxZoom, projection, onMoveStart, onMove, onMoveEnd, filterZoomEvent]);
useEffect(function () {
if (lon === lastPosition.current.x && lat === lastPosition.current.y && zoom === lastPosition.current.k) return;
var coords = projection([lon, lat]);
var x = coords[0] * zoom;
var y = coords[1] * zoom;
var svg = d3Select.select(mapRef.current);
bypassEvents.current = true;
svg.call(zoomRef.current.transform, d3Zoom.zoomIdentity.translate(width / 2 - x, height / 2 - y).scale(zoom));
setPosition({
x: width / 2 - x,
y: height / 2 - y,
k: zoom
});
lastPosition.current = {
x: lon,
y: lat,
k: zoom
};
}, [lon, lat, zoom, width, height, projection]);
return {
mapRef: mapRef,
position: position,
transformString: "translate(".concat(position.x, " ").concat(position.y, ") scale(").concat(position.k, ")")
};
}
var _excluded$4 = ["center", "zoom", "minZoom", "maxZoom", "translateExtent", "filterZoomEvent", "onMoveStart", "onMove", "onMoveEnd", "className"];
var ZoomableGroup = forwardRef(function (_ref, ref) {
var _ref$center = _ref.center,
center = _ref$center === void 0 ? [0, 0] : _ref$center,
_ref$zoom = _ref.zoom,
zoom = _ref$zoom === void 0 ? 1 : _ref$zoom,
_ref$minZoom = _ref.minZoom,
minZoom = _ref$minZoom === void 0 ? 1 : _ref$minZoom,
_ref$maxZoom = _ref.maxZoom,
maxZoom = _ref$maxZoom === void 0 ? 8 : _ref$maxZoom,
translateExtent = _ref.translateExtent,
filterZoomEvent = _ref.filterZoomEvent,
onMoveStart = _ref.onMoveStart,
onMove = _ref.onMove,
onMoveEnd = _ref.onMoveEnd,
className = _ref.className,
restProps = _objectWithoutProperties(_ref, _excluded$4);
var _useContext = useContext(MapContext),
width = _useContext.width,
height = _useContext.height;
var _useZoomPan = useZoomPan({
center: center,
filterZoomEvent: filterZoomEvent,
onMoveStart: onMoveStart,
onMove: onMove,
onMoveEnd: onMoveEnd,
scaleExtent: [minZoom, maxZoom],
translateExtent: translateExtent,
zoom: zoom
}),
mapRef = _useZoomPan.mapRef,
transformString = _useZoomPan.transformString,
position = _useZoomPan.position;
return /*#__PURE__*/React.createElement(ZoomPanProvider, {
value: {
x: position.x,
y: position.y,
k: position.k,
transformString: transformString
}
}, /*#__PURE__*/React.createElement("g", {
ref: mapRef
}, /*#__PURE__*/React.createElement("rect", {
width: width,
height: height,
fill: "transparent"
}), /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: transformString,
className: "rsm-zoomable-group ".concat(className)
}, restProps))));
});
ZoomableGroup.displayName = "ZoomableGroup";
ZoomableGroup.propTypes = {
center: PropTypes.array,
zoom: PropTypes.number,
minZoom: PropTypes.number,
maxZoom: PropTypes.number,
translateExtent: PropTypes.arrayOf(PropTypes.array),
onMoveStart: PropTypes.func,
onMove: PropTypes.func,
onMoveEnd: PropTypes.func,
className: PropTypes.string
};
var _excluded$3 = ["id", "fill", "stroke", "strokeWidth", "className"];
var Sphere = forwardRef(function (_ref, ref) {
var _ref$id = _ref.id,
id = _ref$id === void 0 ? "rsm-sphere" : _ref$id,
_ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$strokeWidth = _ref.strokeWidth,
strokeWidth = _ref$strokeWidth === void 0 ? 0.5 : _ref$strokeWidth,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$3);
var _useContext = useContext(MapContext),
path = _useContext.path;
var spherePath = useMemo(function () {
return path({
type: "Sphere"
});
}, [path]);
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
id: id
}, /*#__PURE__*/React.createElement("path", {
d: spherePath
}))), /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: spherePath,
fill: fill,
stroke: stroke,
strokeWidth: strokeWidth,
style: {
pointerEvents: "none"
},
className: "rsm-sphere ".concat(className)
}, restProps)));
});
Sphere.displayName = "Sphere";
Sphere.propTypes = {
id: PropTypes.string,
fill: PropTypes.string,
stroke: PropTypes.string,
strokeWidth: PropTypes.number,
className: PropTypes.string
};
var Sphere$1 = memo(Sphere);
var _excluded$2 = ["coordinates", "children", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
var Marker = forwardRef(function (_ref, ref) {
var coordinates = _ref.coordinates,
children = _ref.children,
onMouseEnter = _ref.onMouseEnter,
onMouseLeave = _ref.onMouseLeave,
onMouseDown = _ref.onMouseDown,
onMouseUp = _ref.onMouseUp,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur,
_ref$style = _ref.style,
style = _ref$style === void 0 ? {} : _ref$style,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$2);
var _useContext = useContext(MapContext),
projection = _useContext.projection;
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isPressed = _useState2[0],
setPressed = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isFocused = _useState4[0],
setFocus = _useState4[1];
var _projection = projection(coordinates),
_projection2 = _slicedToArray(_projection, 2),
x = _projection2[0],
y = _projection2[1];
function handleMouseEnter(evt) {
setFocus(true);
if (onMouseEnter) onMouseEnter(evt);
}
function handleMouseLeave(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onMouseLeave) onMouseLeave(evt);
}
function handleFocus(evt) {
setFocus(true);
if (onFocus) onFocus(evt);
}
function handleBlur(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onBlur) onBlur(evt);
}
function handleMouseDown(evt) {
setPressed(true);
if (onMouseDown) onMouseDown(evt);
}
function handleMouseUp(evt) {
setPressed(false);
if (onMouseUp) onMouseUp(evt);
}
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: "translate(".concat(x, ", ").concat(y, ")"),
className: "rsm-marker ".concat(className),
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onFocus: handleFocus,
onBlur: handleBlur,
onMouseDown: handleMouseDown,
onMouseUp: handleMouseUp,
style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
}, restProps), children);
});
Marker.displayName = "Marker";
Marker.propTypes = {
coordinates: PropTypes.array,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
style: PropTypes.object,
className: PropTypes.string
};
var _excluded$1 = ["from", "to", "coordinates", "stroke", "strokeWidth", "fill", "className"];
var Line = forwardRef(function (_ref, ref) {
var _ref$from = _ref.from,
from = _ref$from === void 0 ? [0, 0] : _ref$from,
_ref$to = _ref.to,
to = _ref$to === void 0 ? [0, 0] : _ref$to,
coordinates = _ref.coordinates,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$strokeWidth = _ref.strokeWidth,
strokeWidth = _ref$strokeWidth === void 0 ? 3 : _ref$strokeWidth,
_ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$1);
var _useContext = useContext(MapContext),
path = _useContext.path;
var lineData = {
type: "LineString",
coordinates: coordinates || [from, to]
};
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: path(lineData),
className: "rsm-line ".concat(className),
stroke: stroke,
strokeWidth: strokeWidth,
fill: fill
}, restProps));
});
Line.displayName = "Line";
Line.propTypes = {
from: PropTypes.array,
to: PropTypes.array,
coordinates: PropTypes.array,
stroke: PropTypes.string,
strokeWidth: PropTypes.number,
fill: PropTypes.string,
className: PropTypes.string
};
var _excluded = ["subject", "children", "connectorProps", "dx", "dy", "curve", "className"];
var Annotation = forwardRef(function (_ref, ref) {
var subject = _ref.subject,
children = _ref.children,
connectorProps = _ref.connectorProps,
_ref$dx = _ref.dx,
dx = _ref$dx === void 0 ? 30 : _ref$dx,
_ref$dy = _ref.dy,
dy = _ref$dy === void 0 ? 30 : _ref$dy,
_ref$curve = _ref.curve,
curve = _ref$curve === void 0 ? 0 : _ref$curve,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded);
var _useContext = useContext(MapContext),
projection = _useContext.projection;
var _projection = projection(subject),
_projection2 = _slicedToArray(_projection, 2),
x = _projection2[0],
y = _projection2[1];
var connectorPath = createConnectorPath(dx, dy, curve);
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: "translate(".concat(x + dx, ", ").concat(y + dy, ")"),
className: "rsm-annotation ".concat(className)
}, restProps), /*#__PURE__*/React.createElement("path", _extends({
d: connectorPath,
fill: "transparent",
stroke: "#000"
}, connectorProps)), children);
});
Annotation.displayName = "Annotation";
Annotation.propTypes = {
subject: PropTypes.array,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
dx: PropTypes.number,
dy: PropTypes.number,
curve: PropTypes.number,
connectorProps: PropTypes.object,
className: PropTypes.string
};
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 };
import e,{createContext as r,useMemo as t,useCallback as o,useContext as n,forwardRef as a,useState as i,useEffect as c,memo as s,useRef as u,Fragment as l}from"react";import f from"prop-types";import*as p from"d3-geo";import{feature as m,mesh as d}from"topojson-client";import*as v from"d3-zoom";import*as y from"d3-selection";function g(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function h(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?g(Object(t),!0).forEach((function(r){j(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):g(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function b(e){return b="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},b(e)}function j(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function E(){return E=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},E.apply(this,arguments)}function M(e,r){if(null==e)return{};var t,o,n=function(e,r){if(null==e)return{};var t,o,n={},a=Object.keys(e);for(o=0;o<a.length;o++)t=a[o],r.indexOf(t)>=0||(n[t]=e[t]);return n}(e,r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)t=a[o],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(n[t]=e[t])}return n}function k(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var o,n,a,i,c=[],s=!0,u=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(o=a.call(t)).done)&&(c.push(o.value),c.length!==r);s=!0);}catch(e){u=!0,n=e}finally{try{if(!s&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(u)throw n}}return c}}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return N(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return N(e,r)}(e,r)||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 N(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,o=new Array(r);t<r;t++)o[t]=e[t];return o}var w=["width","height","projection","projectionConfig"],O=p.geoPath,x=M(p,["geoPath"]),S=r(),P=function(r){var n=r.width,a=r.height,i=r.projection,c=r.projectionConfig,s=M(r,w),u=k(c.center||[],2),l=u[0],f=u[1],p=k(c.rotate||[],3),m=p[0],d=p[1],v=p[2],y=k(c.parallels||[],2),g=y[0],h=y[1],b=c.scale||null,j=t((function(){return function(e){var r=e.projectionConfig,t=void 0===r?{}:r,o=e.projection,n=void 0===o?"geoEqualEarth":o,a=e.width,i=void 0===a?800:a,c=e.height,s=void 0===c?600:c;if("function"==typeof n)return n;var u=x[n]().translate([i/2,s/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](t[e]||u[e]()))})),u}({projectionConfig:{center:l||0===l||f||0===f?[l,f]:null,rotate:m||0===m||d||0===d?[m,d,v]:null,parallels:g||0===g||h||0===h?[g,h]:null,scale:b},projection:i,width:n,height:a})}),[n,a,i,l,f,m,d,v,g,h,b]),N=o(j,[j]),P=t((function(){return{width:n,height:a,projection:N,path:O().projection(N)}}),[n,a,N]);return e.createElement(S.Provider,E({value:P},s))};P.propTypes={width:f.number,height:f.number,projection:f.oneOfType([f.string,f.func]),projectionConfig:f.object};var T=function(){return n(S)},z=["width","height","projection","projectionConfig","className"],D=a((function(r,t){var o=r.width,n=void 0===o?800:o,a=r.height,i=void 0===a?600:a,c=r.projection,s=void 0===c?"geoEqualEarth":c,u=r.projectionConfig,l=void 0===u?{}:u,f=r.className,p=void 0===f?"":f,m=M(r,z);return e.createElement(P,{width:n,height:i,projection:s,projectionConfig:l},e.createElement("svg",E({ref:t,viewBox:"0 0 ".concat(n," ").concat(i),className:"rsm-svg ".concat(p)},m)))}));function G(e,r,t){var o=(e*t.k-e)/2,n=(r*t.k-r)/2;return[e/2-(o+t.x)/t.k,r/2-(n+t.y)/t.k]}function C(e,r){if(!("Topology"===e.type))return r?r(e.features||e):e.features||e;var t=m(e,e.objects[Object.keys(e.objects)[0]]).features;return r?r(t):t}function Z(e){return"Topology"===e.type?{outline:d(e,e.objects[Object.keys(e.objects)[0]],(function(e,r){return e===r})),borders:d(e,e.objects[Object.keys(e.objects)[0]],(function(e,r){return e!==r}))}:null}function L(e,r){return e?e.map((function(e,t){return h(h({},e),{},{rsmKey:"geo-".concat(t),svgPath:r(e)})})):[]}function A(e){var r=e.geography,o=e.parseGeographies,a=n(S).path,s=k(i({}),2),u=s[0],l=s[1];c((function(){var e;"undefined"!==("undefined"==typeof window?"undefined":b(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&&l({geographies:C(e,o),mesh:Z(e)})})):l({geographies:C(r,o),mesh:Z(r)})))}),[r,o]);var f=t((function(){var e=u.mesh||{},r=function(e,r,t){return e&&r?{outline:h(h({},e),{},{rsmKey:"outline",svgPath:t(e)}),borders:h(h({},r),{},{rsmKey:"borders",svgPath:t(r)})}:{}}(e.outline,e.borders,a);return{geographies:L(u.geographies,a),outline:r.outline,borders:r.borders}}),[u,a]);return{geographies:f.geographies,outline:f.outline,borders:f.borders}}D.displayName="ComposableMap",D.propTypes={width:f.number,height:f.number,projection:f.oneOfType([f.string,f.func]),projectionConfig:f.object,className:f.string};var B=["geography","children","parseGeographies","className"],U=a((function(r,t){var o=r.geography,a=r.children,i=r.parseGeographies,c=r.className,s=void 0===c?"":c,u=M(r,B),l=n(S),f=l.path,p=l.projection,m=A({geography:o,parseGeographies:i}),d=m.geographies,v=m.outline,y=m.borders;return e.createElement("g",E({ref:t,className:"rsm-geographies ".concat(s)},u),d&&d.length>0&&a({geographies:d,outline:v,borders:y,path:f,projection:p}))}));U.displayName="Geographies",U.propTypes={geography:f.oneOfType([f.string,f.object,f.array]),children:f.func,parseGeographies:f.func,className:f.string};var F=["geography","onMouseEnter","onMouseLeave","onMouseDown","onMouseUp","onFocus","onBlur","style","className"],W=a((function(r,t){var o=r.geography,n=r.onMouseEnter,a=r.onMouseLeave,c=r.onMouseDown,s=r.onMouseUp,u=r.onFocus,l=r.onBlur,f=r.style,p=void 0===f?{}:f,m=r.className,d=void 0===m?"":m,v=M(r,F),y=k(i(!1),2),g=y[0],h=y[1],b=k(i(!1),2),j=b[0],N=b[1];return e.createElement("path",E({ref:t,tabIndex:"0",className:"rsm-geography ".concat(d),d:o.svgPath,onMouseEnter:function(e){N(!0),n&&n(e)},onMouseLeave:function(e){N(!1),g&&h(!1),a&&a(e)},onFocus:function(e){N(!0),u&&u(e)},onBlur:function(e){N(!1),g&&h(!1),l&&l(e)},onMouseDown:function(e){h(!0),c&&c(e)},onMouseUp:function(e){h(!1),s&&s(e)},style:p[g||j?g?"pressed":"hover":"default"]},v))}));W.displayName="Geography",W.propTypes={geography:f.object,onMouseEnter:f.func,onMouseLeave:f.func,onMouseDown:f.func,onMouseUp:f.func,onFocus:f.func,onBlur:f.func,style:f.object,className:f.string};var I=s(W),K=["fill","stroke","step","className"],q=a((function(r,t){var o=r.fill,a=void 0===o?"transparent":o,i=r.stroke,c=void 0===i?"currentcolor":i,s=r.step,u=void 0===s?[10,10]:s,l=r.className,f=void 0===l?"":l,m=M(r,K),d=n(S).path;return e.createElement("path",E({ref:t,d:d(p.geoGraticule().step(u)()),fill:a,stroke:c,className:"rsm-graticule ".concat(f)},m))}));q.displayName="Graticule",q.propTypes={fill:f.string,stroke:f.string,step:f.array,className:f.string};var R=s(q),Q=["value"],$=r(),H={x:0,y:0,k:1,transformString:"translate(0 0) scale(1)"},J=function(r){var t=r.value,o=void 0===t?H:t,n=M(r,Q);return e.createElement($.Provider,E({value:o},n))};J.propTypes={x:f.number,y:f.number,k:f.number,transformString:f.string};var V=function(){return n($)};function X(e){var r=e.center,t=e.filterZoomEvent,o=e.onMoveStart,a=e.onMoveEnd,s=e.onMove,l=e.translateExtent,f=void 0===l?[[-1/0,-1/0],[1/0,1/0]]:l,p=e.scaleExtent,m=void 0===p?[1,8]:p,d=e.zoom,g=void 0===d?1:d,h=n(S),b=h.width,j=h.height,E=h.projection,M=k(r,2),N=M[0],w=M[1],O=k(i({x:0,y:0,k:1}),2),x=O[0],P=O[1],T=u({x:0,y:0,k:1}),z=u(),D=u(),C=u(!1),Z=k(f,2),L=Z[0],A=Z[1],B=k(L,2),U=B[0],F=B[1],W=k(A,2),I=W[0],K=W[1],q=k(m,2),R=q[0],Q=q[1];return c((function(){var e=y.select(z.current);var r=v.zoom().filter((function(e){return t?t(e):!!e&&(!e.ctrlKey&&!e.button)})).scaleExtent([R,Q]).translateExtent([[U,F],[I,K]]).on("start",(function(e){o&&!C.current&&o({coordinates:E.invert(G(b,j,e.transform)),zoom:e.transform.k},e)})).on("zoom",(function(e){if(!C.current){var r=e.transform,t=e.sourceEvent;P({x:r.x,y:r.y,k:r.k,dragging:t}),s&&s({x:r.x,y:r.y,zoom:r.k,dragging:t},e)}})).on("end",(function(e){if(C.current)C.current=!1;else{var r=k(E.invert(G(b,j,e.transform)),2),t=r[0],o=r[1];T.current={x:t,y:o,k:e.transform.k},a&&a({coordinates:[t,o],zoom:e.transform.k},e)}}));D.current=r,e.call(r)}),[b,j,U,F,I,K,R,Q,E,o,s,a,t]),c((function(){if(N!==T.current.x||w!==T.current.y||g!==T.current.k){var e=E([N,w]),r=e[0]*g,t=e[1]*g,o=y.select(z.current);C.current=!0,o.call(D.current.transform,v.zoomIdentity.translate(b/2-r,j/2-t).scale(g)),P({x:b/2-r,y:j/2-t,k:g}),T.current={x:N,y:w,k:g}}}),[N,w,g,b,j,E]),{mapRef:z,position:x,transformString:"translate(".concat(x.x," ").concat(x.y,") scale(").concat(x.k,")")}}var Y=["center","zoom","minZoom","maxZoom","translateExtent","filterZoomEvent","onMoveStart","onMove","onMoveEnd","className"],_=a((function(r,t){var o=r.center,a=void 0===o?[0,0]:o,i=r.zoom,c=void 0===i?1:i,s=r.minZoom,u=void 0===s?1:s,l=r.maxZoom,f=void 0===l?8:l,p=r.translateExtent,m=r.filterZoomEvent,d=r.onMoveStart,v=r.onMove,y=r.onMoveEnd,g=r.className,h=M(r,Y),b=n(S),j=b.width,k=b.height,N=X({center:a,filterZoomEvent:m,onMoveStart:d,onMove:v,onMoveEnd:y,scaleExtent:[u,f],translateExtent:p,zoom:c}),w=N.mapRef,O=N.transformString,x=N.position;return e.createElement(J,{value:{x:x.x,y:x.y,k:x.k,transformString:O}},e.createElement("g",{ref:w},e.createElement("rect",{width:j,height:k,fill:"transparent"}),e.createElement("g",E({ref:t,transform:O,className:"rsm-zoomable-group ".concat(g)},h))))}));_.displayName="ZoomableGroup",_.propTypes={center:f.array,zoom:f.number,minZoom:f.number,maxZoom:f.number,translateExtent:f.arrayOf(f.array),onMoveStart:f.func,onMove:f.func,onMoveEnd:f.func,className:f.string};var ee=["id","fill","stroke","strokeWidth","className"],re=a((function(r,o){var a=r.id,i=void 0===a?"rsm-sphere":a,c=r.fill,s=void 0===c?"transparent":c,u=r.stroke,f=void 0===u?"currentcolor":u,p=r.strokeWidth,m=void 0===p?.5:p,d=r.className,v=void 0===d?"":d,y=M(r,ee),g=n(S).path,h=t((function(){return g({type:"Sphere"})}),[g]);return e.createElement(l,null,e.createElement("defs",null,e.createElement("clipPath",{id:i},e.createElement("path",{d:h}))),e.createElement("path",E({ref:o,d:h,fill:s,stroke:f,strokeWidth:m,style:{pointerEvents:"none"},className:"rsm-sphere ".concat(v)},y)))}));re.displayName="Sphere",re.propTypes={id:f.string,fill:f.string,stroke:f.string,strokeWidth:f.number,className:f.string};var te=s(re),oe=["coordinates","children","onMouseEnter","onMouseLeave","onMouseDown","onMouseUp","onFocus","onBlur","style","className"],ne=a((function(r,t){var o=r.coordinates,a=r.children,c=r.onMouseEnter,s=r.onMouseLeave,u=r.onMouseDown,l=r.onMouseUp,f=r.onFocus,p=r.onBlur,m=r.style,d=void 0===m?{}:m,v=r.className,y=void 0===v?"":v,g=M(r,oe),h=n(S).projection,b=k(i(!1),2),j=b[0],N=b[1],w=k(i(!1),2),O=w[0],x=w[1],P=k(h(o),2),T=P[0],z=P[1];return e.createElement("g",E({ref:t,transform:"translate(".concat(T,", ").concat(z,")"),className:"rsm-marker ".concat(y),onMouseEnter:function(e){x(!0),c&&c(e)},onMouseLeave:function(e){x(!1),j&&N(!1),s&&s(e)},onFocus:function(e){x(!0),f&&f(e)},onBlur:function(e){x(!1),j&&N(!1),p&&p(e)},onMouseDown:function(e){N(!0),u&&u(e)},onMouseUp:function(e){N(!1),l&&l(e)},style:d[j||O?j?"pressed":"hover":"default"]},g),a)}));ne.displayName="Marker",ne.propTypes={coordinates:f.array,children:f.oneOfType([f.node,f.arrayOf(f.node)]),onMouseEnter:f.func,onMouseLeave:f.func,onMouseDown:f.func,onMouseUp:f.func,onFocus:f.func,onBlur:f.func,style:f.object,className:f.string};var ae=["from","to","coordinates","stroke","strokeWidth","fill","className"],ie=a((function(r,t){var o=r.from,a=void 0===o?[0,0]:o,i=r.to,c=void 0===i?[0,0]:i,s=r.coordinates,u=r.stroke,l=void 0===u?"currentcolor":u,f=r.strokeWidth,p=void 0===f?3:f,m=r.fill,d=void 0===m?"transparent":m,v=r.className,y=void 0===v?"":v,g=M(r,ae),h=n(S).path,b={type:"LineString",coordinates:s||[a,c]};return e.createElement("path",E({ref:t,d:h(b),className:"rsm-line ".concat(y),stroke:l,strokeWidth:p,fill:d},g))}));ie.displayName="Line",ie.propTypes={from:f.array,to:f.array,coordinates:f.array,stroke:f.string,strokeWidth:f.number,fill:f.string,className:f.string};var ce=["subject","children","connectorProps","dx","dy","curve","className"],se=a((function(r,t){var o=r.subject,a=r.children,i=r.connectorProps,c=r.dx,s=void 0===c?30:c,u=r.dy,l=void 0===u?30:u,f=r.curve,p=void 0===f?0:f,m=r.className,d=void 0===m?"":m,v=M(r,ce),y=k((0,n(S).projection)(o),2),g=y[0],h=y[1],b=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:30,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:30,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.5,o=Array.isArray(t)?t:[t,t],n=e/2*o[0],a=r/2*o[1];return"M".concat(0,",",0," Q",-e/2-n,",").concat(-r/2+a," ").concat(-e,",").concat(-r)}(s,l,p);return e.createElement("g",E({ref:t,transform:"translate(".concat(g+s,", ").concat(h+l,")"),className:"rsm-annotation ".concat(d)},v),e.createElement("path",E({d:b,fill:"transparent",stroke:"#000"},i)),a)}));se.displayName="Annotation",se.propTypes={subject:f.array,children:f.oneOfType([f.node,f.arrayOf(f.node)]),dx:f.number,dy:f.number,curve:f.number,connectorProps:f.object,className:f.string};export{se as Annotation,D as ComposableMap,U as Geographies,I as Geography,R as Graticule,ie as Line,S as MapContext,P as MapProvider,ne as Marker,te as Sphere,$ as ZoomPanContext,J as ZoomPanProvider,_ as ZoomableGroup,A as useGeographies,T as useMapContext,X as useZoomPan,V as useZoomPanContext};

@@ -1,1001 +0,1 @@

'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var d3Geo = require('d3-geo');
var topojsonClient = require('topojson-client');
var d3Zoom = require('d3-zoom');
var d3Select = require('d3-selection');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var d3Geo__namespace = /*#__PURE__*/_interopNamespaceDefault(d3Geo);
var d3Zoom__namespace = /*#__PURE__*/_interopNamespaceDefault(d3Zoom);
var d3Select__namespace = /*#__PURE__*/_interopNamespaceDefault(d3Select);
function _iterableToArrayLimit(arr, i) {
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
if (null != _i) {
var _s,
_e,
_x,
_r,
_arr = [],
_n = !0,
_d = !1;
try {
if (_x = (_i = _i.call(arr)).next, 0 === i) {
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
} catch (err) {
_d = !0, _e = err;
} finally {
try {
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
} finally {
if (_d) throw _e;
}
}
return _arr;
}
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
})), keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
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 _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var _excluded$a = ["width", "height", "projection", "projectionConfig"];
var geoPath = d3Geo__namespace.geoPath,
projections = _objectWithoutProperties(d3Geo__namespace, ["geoPath"]);
var MapContext = React.createContext();
var makeProjection = function makeProjection(_ref) {
var _ref$projectionConfig = _ref.projectionConfig,
projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
_ref$projection = _ref.projection,
projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
_ref$width = _ref.width,
width = _ref$width === void 0 ? 800 : _ref$width,
_ref$height = _ref.height,
height = _ref$height === void 0 ? 600 : _ref$height;
var isFunc = typeof projection === "function";
if (isFunc) return projection;
var proj = projections[projection]().translate([width / 2, height / 2]);
var supported = [proj.center ? "center" : null, proj.rotate ? "rotate" : null, proj.scale ? "scale" : null, proj.parallels ? "parallels" : null];
supported.forEach(function (d) {
if (!d) return;
proj = proj[d](projectionConfig[d] || proj[d]());
});
return proj;
};
var MapProvider = function MapProvider(_ref2) {
var width = _ref2.width,
height = _ref2.height,
projection = _ref2.projection,
projectionConfig = _ref2.projectionConfig,
restProps = _objectWithoutProperties(_ref2, _excluded$a);
var _ref3 = projectionConfig.center || [],
_ref4 = _slicedToArray(_ref3, 2),
cx = _ref4[0],
cy = _ref4[1];
var _ref5 = projectionConfig.rotate || [],
_ref6 = _slicedToArray(_ref5, 3),
rx = _ref6[0],
ry = _ref6[1],
rz = _ref6[2];
var _ref7 = projectionConfig.parallels || [],
_ref8 = _slicedToArray(_ref7, 2),
p1 = _ref8[0],
p2 = _ref8[1];
var s = projectionConfig.scale || null;
var projMemo = React.useMemo(function () {
return makeProjection({
projectionConfig: {
center: cx || cx === 0 || cy || cy === 0 ? [cx, cy] : null,
rotate: rx || rx === 0 || ry || ry === 0 ? [rx, ry, rz] : null,
parallels: p1 || p1 === 0 || p2 || p2 === 0 ? [p1, p2] : null,
scale: s
},
projection: projection,
width: width,
height: height
});
}, [width, height, projection, cx, cy, rx, ry, rz, p1, p2, s]);
var proj = React.useCallback(projMemo, [projMemo]);
var value = React.useMemo(function () {
return {
width: width,
height: height,
projection: proj,
path: geoPath().projection(proj)
};
}, [width, height, proj]);
return /*#__PURE__*/React.createElement(MapContext.Provider, _extends({
value: value
}, restProps));
};
MapProvider.propTypes = {
width: PropTypes.number,
height: PropTypes.number,
projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
projectionConfig: PropTypes.object
};
var useMapContext = function useMapContext() {
return React.useContext(MapContext);
};
var _excluded$9 = ["width", "height", "projection", "projectionConfig", "className"];
var ComposableMap = React.forwardRef(function (_ref, ref) {
var _ref$width = _ref.width,
width = _ref$width === void 0 ? 800 : _ref$width,
_ref$height = _ref.height,
height = _ref$height === void 0 ? 600 : _ref$height,
_ref$projection = _ref.projection,
projection = _ref$projection === void 0 ? "geoEqualEarth" : _ref$projection,
_ref$projectionConfig = _ref.projectionConfig,
projectionConfig = _ref$projectionConfig === void 0 ? {} : _ref$projectionConfig,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$9);
return /*#__PURE__*/React.createElement(MapProvider, {
width: width,
height: height,
projection: projection,
projectionConfig: projectionConfig
}, /*#__PURE__*/React.createElement("svg", _extends({
ref: ref,
viewBox: "0 0 ".concat(width, " ").concat(height),
className: "rsm-svg ".concat(className)
}, restProps)));
});
ComposableMap.displayName = "ComposableMap";
ComposableMap.propTypes = {
width: PropTypes.number,
height: PropTypes.number,
projection: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
projectionConfig: PropTypes.object,
className: PropTypes.string
};
function getCoords(w, h, t) {
var xOffset = (w * t.k - w) / 2;
var yOffset = (h * t.k - h) / 2;
return [w / 2 - (xOffset + t.x) / t.k, h / 2 - (yOffset + t.y) / t.k];
}
function fetchGeographies(url) {
return fetch(url).then(function (res) {
if (!res.ok) {
throw Error(res.statusText);
}
return res.json();
})["catch"](function (error) {
console.log("There was a problem when fetching the data: ", error);
});
}
function getFeatures(geographies, parseGeographies) {
var isTopojson = geographies.type === "Topology";
if (!isTopojson) {
return parseGeographies ? parseGeographies(geographies.features || geographies) : geographies.features || geographies;
}
var feats = topojsonClient.feature(geographies, geographies.objects[Object.keys(geographies.objects)[0]]).features;
return parseGeographies ? parseGeographies(feats) : feats;
}
function getMesh(geographies) {
var isTopojson = geographies.type === "Topology";
if (!isTopojson) return null;
var outline = topojsonClient.mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
return a === b;
});
var borders = topojsonClient.mesh(geographies, geographies.objects[Object.keys(geographies.objects)[0]], function (a, b) {
return a !== b;
});
return {
outline: outline,
borders: borders
};
}
function prepareMesh(outline, borders, path) {
return outline && borders ? {
outline: _objectSpread2(_objectSpread2({}, outline), {}, {
rsmKey: "outline",
svgPath: path(outline)
}),
borders: _objectSpread2(_objectSpread2({}, borders), {}, {
rsmKey: "borders",
svgPath: path(borders)
})
} : {};
}
function prepareFeatures(geographies, path) {
return geographies ? geographies.map(function (d, i) {
return _objectSpread2(_objectSpread2({}, d), {}, {
rsmKey: "geo-".concat(i),
svgPath: path(d)
});
}) : [];
}
function createConnectorPath() {
var dx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 30;
var dy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;
var curve = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.5;
var curvature = Array.isArray(curve) ? curve : [curve, curve];
var curveX = dx / 2 * curvature[0];
var curveY = dy / 2 * curvature[1];
return "M".concat(0, ",", 0, " Q", -dx / 2 - curveX, ",").concat(-dy / 2 + curveY, " ").concat(-dx, ",").concat(-dy);
}
function isString(geo) {
return typeof geo === "string";
}
function useGeographies(_ref) {
var geography = _ref.geography,
parseGeographies = _ref.parseGeographies;
var _useContext = React.useContext(MapContext),
path = _useContext.path;
var _useState = React.useState({}),
_useState2 = _slicedToArray(_useState, 2),
output = _useState2[0],
setOutput = _useState2[1];
React.useEffect(function () {
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "undefined") return;
if (!geography) return;
if (isString(geography)) {
fetchGeographies(geography).then(function (geos) {
if (geos) {
setOutput({
geographies: getFeatures(geos, parseGeographies),
mesh: getMesh(geos)
});
}
});
} else {
setOutput({
geographies: getFeatures(geography, parseGeographies),
mesh: getMesh(geography)
});
}
}, [geography, parseGeographies]);
var _useMemo = React.useMemo(function () {
var mesh = output.mesh || {};
var preparedMesh = prepareMesh(mesh.outline, mesh.borders, path);
return {
geographies: prepareFeatures(output.geographies, path),
outline: preparedMesh.outline,
borders: preparedMesh.borders
};
}, [output, path]),
geographies = _useMemo.geographies,
outline = _useMemo.outline,
borders = _useMemo.borders;
return {
geographies: geographies,
outline: outline,
borders: borders
};
}
var _excluded$8 = ["geography", "children", "parseGeographies", "className"];
var Geographies = React.forwardRef(function (_ref, ref) {
var geography = _ref.geography,
children = _ref.children,
parseGeographies = _ref.parseGeographies,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$8);
var _useContext = React.useContext(MapContext),
path = _useContext.path,
projection = _useContext.projection;
var _useGeographies = useGeographies({
geography: geography,
parseGeographies: parseGeographies
}),
geographies = _useGeographies.geographies,
outline = _useGeographies.outline,
borders = _useGeographies.borders;
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
className: "rsm-geographies ".concat(className)
}, restProps), geographies && geographies.length > 0 && children({
geographies: geographies,
outline: outline,
borders: borders,
path: path,
projection: projection
}));
});
Geographies.displayName = "Geographies";
Geographies.propTypes = {
geography: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array]),
children: PropTypes.func,
parseGeographies: PropTypes.func,
className: PropTypes.string
};
var _excluded$7 = ["geography", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
var Geography = React.forwardRef(function (_ref, ref) {
var geography = _ref.geography,
onMouseEnter = _ref.onMouseEnter,
onMouseLeave = _ref.onMouseLeave,
onMouseDown = _ref.onMouseDown,
onMouseUp = _ref.onMouseUp,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur,
_ref$style = _ref.style,
style = _ref$style === void 0 ? {} : _ref$style,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$7);
var _useState = React.useState(false),
_useState2 = _slicedToArray(_useState, 2),
isPressed = _useState2[0],
setPressed = _useState2[1];
var _useState3 = React.useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isFocused = _useState4[0],
setFocus = _useState4[1];
function handleMouseEnter(evt) {
setFocus(true);
if (onMouseEnter) onMouseEnter(evt);
}
function handleMouseLeave(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onMouseLeave) onMouseLeave(evt);
}
function handleFocus(evt) {
setFocus(true);
if (onFocus) onFocus(evt);
}
function handleBlur(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onBlur) onBlur(evt);
}
function handleMouseDown(evt) {
setPressed(true);
if (onMouseDown) onMouseDown(evt);
}
function handleMouseUp(evt) {
setPressed(false);
if (onMouseUp) onMouseUp(evt);
}
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
tabIndex: "0",
className: "rsm-geography ".concat(className),
d: geography.svgPath,
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onFocus: handleFocus,
onBlur: handleBlur,
onMouseDown: handleMouseDown,
onMouseUp: handleMouseUp,
style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
}, restProps));
});
Geography.displayName = "Geography";
Geography.propTypes = {
geography: PropTypes.object,
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
style: PropTypes.object,
className: PropTypes.string
};
var Geography$1 = React.memo(Geography);
var _excluded$6 = ["fill", "stroke", "step", "className"];
var Graticule = React.forwardRef(function (_ref, ref) {
var _ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$step = _ref.step,
step = _ref$step === void 0 ? [10, 10] : _ref$step,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$6);
var _useContext = React.useContext(MapContext),
path = _useContext.path;
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: path(d3Geo__namespace.geoGraticule().step(step)()),
fill: fill,
stroke: stroke,
className: "rsm-graticule ".concat(className)
}, restProps));
});
Graticule.displayName = "Graticule";
Graticule.propTypes = {
fill: PropTypes.string,
stroke: PropTypes.string,
step: PropTypes.array,
className: PropTypes.string
};
var Graticule$1 = React.memo(Graticule);
var _excluded$5 = ["value"];
var ZoomPanContext = React.createContext();
var defaultValue = {
x: 0,
y: 0,
k: 1,
transformString: "translate(0 0) scale(1)"
};
var ZoomPanProvider = function ZoomPanProvider(_ref) {
var _ref$value = _ref.value,
value = _ref$value === void 0 ? defaultValue : _ref$value,
restProps = _objectWithoutProperties(_ref, _excluded$5);
return /*#__PURE__*/React.createElement(ZoomPanContext.Provider, _extends({
value: value
}, restProps));
};
ZoomPanProvider.propTypes = {
x: PropTypes.number,
y: PropTypes.number,
k: PropTypes.number,
transformString: PropTypes.string
};
var useZoomPanContext = function useZoomPanContext() {
return React.useContext(ZoomPanContext);
};
function useZoomPan(_ref) {
var center = _ref.center,
filterZoomEvent = _ref.filterZoomEvent,
onMoveStart = _ref.onMoveStart,
onMoveEnd = _ref.onMoveEnd,
onMove = _ref.onMove,
_ref$translateExtent = _ref.translateExtent,
translateExtent = _ref$translateExtent === void 0 ? [[-Infinity, -Infinity], [Infinity, Infinity]] : _ref$translateExtent,
_ref$scaleExtent = _ref.scaleExtent,
scaleExtent = _ref$scaleExtent === void 0 ? [1, 8] : _ref$scaleExtent,
_ref$zoom = _ref.zoom,
zoom = _ref$zoom === void 0 ? 1 : _ref$zoom;
var _useContext = React.useContext(MapContext),
width = _useContext.width,
height = _useContext.height,
projection = _useContext.projection;
var _center = _slicedToArray(center, 2),
lon = _center[0],
lat = _center[1];
var _useState = React.useState({
x: 0,
y: 0,
k: 1
}),
_useState2 = _slicedToArray(_useState, 2),
position = _useState2[0],
setPosition = _useState2[1];
var lastPosition = React.useRef({
x: 0,
y: 0,
k: 1
});
var mapRef = React.useRef();
var zoomRef = React.useRef();
var bypassEvents = React.useRef(false);
var _translateExtent = _slicedToArray(translateExtent, 2),
a = _translateExtent[0],
b = _translateExtent[1];
var _a = _slicedToArray(a, 2),
a1 = _a[0],
a2 = _a[1];
var _b = _slicedToArray(b, 2),
b1 = _b[0],
b2 = _b[1];
var _scaleExtent = _slicedToArray(scaleExtent, 2),
minZoom = _scaleExtent[0],
maxZoom = _scaleExtent[1];
React.useEffect(function () {
var svg = d3Select__namespace.select(mapRef.current);
function handleZoomStart(d3Event) {
if (!onMoveStart || bypassEvents.current) return;
onMoveStart({
coordinates: projection.invert(getCoords(width, height, d3Event.transform)),
zoom: d3Event.transform.k
}, d3Event);
}
function handleZoom(d3Event) {
if (bypassEvents.current) return;
var transform = d3Event.transform,
sourceEvent = d3Event.sourceEvent;
setPosition({
x: transform.x,
y: transform.y,
k: transform.k,
dragging: sourceEvent
});
if (!onMove) return;
onMove({
x: transform.x,
y: transform.y,
zoom: transform.k,
dragging: sourceEvent
}, d3Event);
}
function handleZoomEnd(d3Event) {
if (bypassEvents.current) {
bypassEvents.current = false;
return;
}
var _projection$invert = projection.invert(getCoords(width, height, d3Event.transform)),
_projection$invert2 = _slicedToArray(_projection$invert, 2),
x = _projection$invert2[0],
y = _projection$invert2[1];
lastPosition.current = {
x: x,
y: y,
k: d3Event.transform.k
};
if (!onMoveEnd) return;
onMoveEnd({
coordinates: [x, y],
zoom: d3Event.transform.k
}, d3Event);
}
function filterFunc(d3Event) {
if (filterZoomEvent) {
return filterZoomEvent(d3Event);
}
return d3Event ? !d3Event.ctrlKey && !d3Event.button : false;
}
var zoom = d3Zoom__namespace.zoom().filter(filterFunc).scaleExtent([minZoom, maxZoom]).translateExtent([[a1, a2], [b1, b2]]).on("start", handleZoomStart).on("zoom", handleZoom).on("end", handleZoomEnd);
zoomRef.current = zoom;
svg.call(zoom);
}, [width, height, a1, a2, b1, b2, minZoom, maxZoom, projection, onMoveStart, onMove, onMoveEnd, filterZoomEvent]);
React.useEffect(function () {
if (lon === lastPosition.current.x && lat === lastPosition.current.y && zoom === lastPosition.current.k) return;
var coords = projection([lon, lat]);
var x = coords[0] * zoom;
var y = coords[1] * zoom;
var svg = d3Select__namespace.select(mapRef.current);
bypassEvents.current = true;
svg.call(zoomRef.current.transform, d3Zoom__namespace.zoomIdentity.translate(width / 2 - x, height / 2 - y).scale(zoom));
setPosition({
x: width / 2 - x,
y: height / 2 - y,
k: zoom
});
lastPosition.current = {
x: lon,
y: lat,
k: zoom
};
}, [lon, lat, zoom, width, height, projection]);
return {
mapRef: mapRef,
position: position,
transformString: "translate(".concat(position.x, " ").concat(position.y, ") scale(").concat(position.k, ")")
};
}
var _excluded$4 = ["center", "zoom", "minZoom", "maxZoom", "translateExtent", "filterZoomEvent", "onMoveStart", "onMove", "onMoveEnd", "className"];
var ZoomableGroup = React.forwardRef(function (_ref, ref) {
var _ref$center = _ref.center,
center = _ref$center === void 0 ? [0, 0] : _ref$center,
_ref$zoom = _ref.zoom,
zoom = _ref$zoom === void 0 ? 1 : _ref$zoom,
_ref$minZoom = _ref.minZoom,
minZoom = _ref$minZoom === void 0 ? 1 : _ref$minZoom,
_ref$maxZoom = _ref.maxZoom,
maxZoom = _ref$maxZoom === void 0 ? 8 : _ref$maxZoom,
translateExtent = _ref.translateExtent,
filterZoomEvent = _ref.filterZoomEvent,
onMoveStart = _ref.onMoveStart,
onMove = _ref.onMove,
onMoveEnd = _ref.onMoveEnd,
className = _ref.className,
restProps = _objectWithoutProperties(_ref, _excluded$4);
var _useContext = React.useContext(MapContext),
width = _useContext.width,
height = _useContext.height;
var _useZoomPan = useZoomPan({
center: center,
filterZoomEvent: filterZoomEvent,
onMoveStart: onMoveStart,
onMove: onMove,
onMoveEnd: onMoveEnd,
scaleExtent: [minZoom, maxZoom],
translateExtent: translateExtent,
zoom: zoom
}),
mapRef = _useZoomPan.mapRef,
transformString = _useZoomPan.transformString,
position = _useZoomPan.position;
return /*#__PURE__*/React.createElement(ZoomPanProvider, {
value: {
x: position.x,
y: position.y,
k: position.k,
transformString: transformString
}
}, /*#__PURE__*/React.createElement("g", {
ref: mapRef
}, /*#__PURE__*/React.createElement("rect", {
width: width,
height: height,
fill: "transparent"
}), /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: transformString,
className: "rsm-zoomable-group ".concat(className)
}, restProps))));
});
ZoomableGroup.displayName = "ZoomableGroup";
ZoomableGroup.propTypes = {
center: PropTypes.array,
zoom: PropTypes.number,
minZoom: PropTypes.number,
maxZoom: PropTypes.number,
translateExtent: PropTypes.arrayOf(PropTypes.array),
onMoveStart: PropTypes.func,
onMove: PropTypes.func,
onMoveEnd: PropTypes.func,
className: PropTypes.string
};
var _excluded$3 = ["id", "fill", "stroke", "strokeWidth", "className"];
var Sphere = React.forwardRef(function (_ref, ref) {
var _ref$id = _ref.id,
id = _ref$id === void 0 ? "rsm-sphere" : _ref$id,
_ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$strokeWidth = _ref.strokeWidth,
strokeWidth = _ref$strokeWidth === void 0 ? 0.5 : _ref$strokeWidth,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$3);
var _useContext = React.useContext(MapContext),
path = _useContext.path;
var spherePath = React.useMemo(function () {
return path({
type: "Sphere"
});
}, [path]);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("clipPath", {
id: id
}, /*#__PURE__*/React.createElement("path", {
d: spherePath
}))), /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: spherePath,
fill: fill,
stroke: stroke,
strokeWidth: strokeWidth,
style: {
pointerEvents: "none"
},
className: "rsm-sphere ".concat(className)
}, restProps)));
});
Sphere.displayName = "Sphere";
Sphere.propTypes = {
id: PropTypes.string,
fill: PropTypes.string,
stroke: PropTypes.string,
strokeWidth: PropTypes.number,
className: PropTypes.string
};
var Sphere$1 = React.memo(Sphere);
var _excluded$2 = ["coordinates", "children", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "style", "className"];
var Marker = React.forwardRef(function (_ref, ref) {
var coordinates = _ref.coordinates,
children = _ref.children,
onMouseEnter = _ref.onMouseEnter,
onMouseLeave = _ref.onMouseLeave,
onMouseDown = _ref.onMouseDown,
onMouseUp = _ref.onMouseUp,
onFocus = _ref.onFocus,
onBlur = _ref.onBlur,
_ref$style = _ref.style,
style = _ref$style === void 0 ? {} : _ref$style,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$2);
var _useContext = React.useContext(MapContext),
projection = _useContext.projection;
var _useState = React.useState(false),
_useState2 = _slicedToArray(_useState, 2),
isPressed = _useState2[0],
setPressed = _useState2[1];
var _useState3 = React.useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isFocused = _useState4[0],
setFocus = _useState4[1];
var _projection = projection(coordinates),
_projection2 = _slicedToArray(_projection, 2),
x = _projection2[0],
y = _projection2[1];
function handleMouseEnter(evt) {
setFocus(true);
if (onMouseEnter) onMouseEnter(evt);
}
function handleMouseLeave(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onMouseLeave) onMouseLeave(evt);
}
function handleFocus(evt) {
setFocus(true);
if (onFocus) onFocus(evt);
}
function handleBlur(evt) {
setFocus(false);
if (isPressed) setPressed(false);
if (onBlur) onBlur(evt);
}
function handleMouseDown(evt) {
setPressed(true);
if (onMouseDown) onMouseDown(evt);
}
function handleMouseUp(evt) {
setPressed(false);
if (onMouseUp) onMouseUp(evt);
}
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: "translate(".concat(x, ", ").concat(y, ")"),
className: "rsm-marker ".concat(className),
onMouseEnter: handleMouseEnter,
onMouseLeave: handleMouseLeave,
onFocus: handleFocus,
onBlur: handleBlur,
onMouseDown: handleMouseDown,
onMouseUp: handleMouseUp,
style: style[isPressed || isFocused ? isPressed ? "pressed" : "hover" : "default"]
}, restProps), children);
});
Marker.displayName = "Marker";
Marker.propTypes = {
coordinates: PropTypes.array,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
onMouseEnter: PropTypes.func,
onMouseLeave: PropTypes.func,
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
onFocus: PropTypes.func,
onBlur: PropTypes.func,
style: PropTypes.object,
className: PropTypes.string
};
var _excluded$1 = ["from", "to", "coordinates", "stroke", "strokeWidth", "fill", "className"];
var Line = React.forwardRef(function (_ref, ref) {
var _ref$from = _ref.from,
from = _ref$from === void 0 ? [0, 0] : _ref$from,
_ref$to = _ref.to,
to = _ref$to === void 0 ? [0, 0] : _ref$to,
coordinates = _ref.coordinates,
_ref$stroke = _ref.stroke,
stroke = _ref$stroke === void 0 ? "currentcolor" : _ref$stroke,
_ref$strokeWidth = _ref.strokeWidth,
strokeWidth = _ref$strokeWidth === void 0 ? 3 : _ref$strokeWidth,
_ref$fill = _ref.fill,
fill = _ref$fill === void 0 ? "transparent" : _ref$fill,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded$1);
var _useContext = React.useContext(MapContext),
path = _useContext.path;
var lineData = {
type: "LineString",
coordinates: coordinates || [from, to]
};
return /*#__PURE__*/React.createElement("path", _extends({
ref: ref,
d: path(lineData),
className: "rsm-line ".concat(className),
stroke: stroke,
strokeWidth: strokeWidth,
fill: fill
}, restProps));
});
Line.displayName = "Line";
Line.propTypes = {
from: PropTypes.array,
to: PropTypes.array,
coordinates: PropTypes.array,
stroke: PropTypes.string,
strokeWidth: PropTypes.number,
fill: PropTypes.string,
className: PropTypes.string
};
var _excluded = ["subject", "children", "connectorProps", "dx", "dy", "curve", "className"];
var Annotation = React.forwardRef(function (_ref, ref) {
var subject = _ref.subject,
children = _ref.children,
connectorProps = _ref.connectorProps,
_ref$dx = _ref.dx,
dx = _ref$dx === void 0 ? 30 : _ref$dx,
_ref$dy = _ref.dy,
dy = _ref$dy === void 0 ? 30 : _ref$dy,
_ref$curve = _ref.curve,
curve = _ref$curve === void 0 ? 0 : _ref$curve,
_ref$className = _ref.className,
className = _ref$className === void 0 ? "" : _ref$className,
restProps = _objectWithoutProperties(_ref, _excluded);
var _useContext = React.useContext(MapContext),
projection = _useContext.projection;
var _projection = projection(subject),
_projection2 = _slicedToArray(_projection, 2),
x = _projection2[0],
y = _projection2[1];
var connectorPath = createConnectorPath(dx, dy, curve);
return /*#__PURE__*/React.createElement("g", _extends({
ref: ref,
transform: "translate(".concat(x + dx, ", ").concat(y + dy, ")"),
className: "rsm-annotation ".concat(className)
}, restProps), /*#__PURE__*/React.createElement("path", _extends({
d: connectorPath,
fill: "transparent",
stroke: "#000"
}, connectorProps)), children);
});
Annotation.displayName = "Annotation";
Annotation.propTypes = {
subject: PropTypes.array,
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]),
dx: PropTypes.number,
dy: PropTypes.number,
curve: PropTypes.number,
connectorProps: PropTypes.object,
className: PropTypes.string
};
exports.Annotation = Annotation;
exports.ComposableMap = ComposableMap;
exports.Geographies = Geographies;
exports.Geography = Geography$1;
exports.Graticule = Graticule$1;
exports.Line = Line;
exports.MapContext = MapContext;
exports.MapProvider = MapProvider;
exports.Marker = Marker;
exports.Sphere = Sphere$1;
exports.ZoomPanContext = ZoomPanContext;
exports.ZoomPanProvider = ZoomPanProvider;
exports.ZoomableGroup = ZoomableGroup;
exports.useGeographies = useGeographies;
exports.useMapContext = useMapContext;
exports.useZoomPan = useZoomPan;
exports.useZoomPanContext = useZoomPanContext;
"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)};

2

package.json
{
"name": "react-simple-maps",
"version": "4.0.0-beta.2",
"version": "4.0.0-beta.3",
"description": "An svg map chart component built with and for React",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc