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

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