@dxos/react-ui-geo 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +55 -45
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +50 -40
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +55 -45
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
- package/dist/types/src/components/Map/Map.stories.d.ts +4 -5
- package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
- package/dist/types/src/hooks/context.d.ts.map +1 -1
- package/dist/types/src/hooks/useDrag.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
- package/dist/types/src/hooks/useTour.d.ts +1 -1
- package/dist/types/src/hooks/useTour.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/inertia.d.ts +2 -1
- package/dist/types/src/util/inertia.d.ts.map +1 -1
- package/dist/types/src/util/path.d.ts.map +1 -1
- package/dist/types/src/util/render.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/src/components/Globe/Globe.stories.tsx +1 -1
- package/src/components/Globe/Globe.tsx +11 -20
- package/src/components/Map/Map.stories.tsx +5 -5
- package/src/hooks/useDrag.ts +3 -3
- package/src/hooks/useSpinner.ts +2 -2
- package/src/hooks/useTour.ts +13 -9
- package/src/util/inertia.ts +5 -4
- package/src/util/path.ts +5 -2
- package/src/util/render.ts +6 -5
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "./chunk-ENCWOTYX.mjs";
|
|
4
4
|
|
|
5
5
|
// packages/ui/react-ui-geo/src/components/Globe/Globe.tsx
|
|
6
|
-
import
|
|
7
|
-
import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo
|
|
6
|
+
import * as d37 from "d3";
|
|
7
|
+
import React3, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo, useRef, useState as useState3 } from "react";
|
|
8
8
|
import { useResizeDetector } from "react-resize-detector";
|
|
9
9
|
import { useDynamicRef, useThemeContext } from "@dxos/react-ui";
|
|
10
10
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -38,7 +38,7 @@ var useGlobeContext = () => {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
// packages/ui/react-ui-geo/src/hooks/useDrag.ts
|
|
41
|
-
import
|
|
41
|
+
import * as d34 from "d3";
|
|
42
42
|
import { useEffect } from "react";
|
|
43
43
|
|
|
44
44
|
// packages/ui/react-ui-geo/src/util/debug.ts
|
|
@@ -57,7 +57,7 @@ var timer = (cb) => {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// packages/ui/react-ui-geo/src/util/inertia.ts
|
|
60
|
-
import
|
|
60
|
+
import * as d3 from "d3";
|
|
61
61
|
import versor from "versor";
|
|
62
62
|
var restrictAxis = (axis) => (original, current) => current.map((d, i) => axis[i] ? d : original[i]);
|
|
63
63
|
var geoInertiaDrag = (target, render, projection, options) => {
|
|
@@ -67,7 +67,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
|
|
|
67
67
|
if (target.node) {
|
|
68
68
|
target = target.node();
|
|
69
69
|
}
|
|
70
|
-
target = select(target);
|
|
70
|
+
target = d3.select(target);
|
|
71
71
|
const inertia = geoInertiaDragHelper({
|
|
72
72
|
projection,
|
|
73
73
|
render: (rotation) => {
|
|
@@ -91,7 +91,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
|
|
|
91
91
|
time: options.time,
|
|
92
92
|
hold: options.hold
|
|
93
93
|
});
|
|
94
|
-
target.call(drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
|
|
94
|
+
target.call(d3.drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
|
|
95
95
|
return inertia;
|
|
96
96
|
};
|
|
97
97
|
var geoInertiaDragHelper = (opt) => {
|
|
@@ -152,7 +152,7 @@ function inertiaHelper(opt) {
|
|
|
152
152
|
0,
|
|
153
153
|
0
|
|
154
154
|
],
|
|
155
|
-
timer:
|
|
155
|
+
timer: d3.timer(() => {
|
|
156
156
|
}),
|
|
157
157
|
time: 0,
|
|
158
158
|
t: 0,
|
|
@@ -232,7 +232,7 @@ function inertiaHelper(opt) {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
// packages/ui/react-ui-geo/src/util/path.ts
|
|
235
|
-
import
|
|
235
|
+
import * as d32 from "d3";
|
|
236
236
|
var positionToRotation = ([lng, lat], tilt = 0) => [
|
|
237
237
|
-lng,
|
|
238
238
|
tilt - lat,
|
|
@@ -246,7 +246,7 @@ var geoPoint = (point) => ({
|
|
|
246
246
|
type: "Point",
|
|
247
247
|
coordinates: geoToPosition(point)
|
|
248
248
|
});
|
|
249
|
-
var
|
|
249
|
+
var geoCircle2 = ({ lat, lng }, radius) => d32.geoCircle().radius(radius).center([
|
|
250
250
|
lng,
|
|
251
251
|
lat
|
|
252
252
|
])();
|
|
@@ -285,8 +285,8 @@ var getDistance = (point1, point2) => {
|
|
|
285
285
|
};
|
|
286
286
|
|
|
287
287
|
// packages/ui/react-ui-geo/src/util/render.ts
|
|
288
|
-
import
|
|
289
|
-
import
|
|
288
|
+
import * as d33 from "d3";
|
|
289
|
+
import * as topojson from "topojson-client";
|
|
290
290
|
var createLayers = (topology, features, styles) => {
|
|
291
291
|
const layers = [];
|
|
292
292
|
if (styles.water) {
|
|
@@ -300,7 +300,7 @@ var createLayers = (topology, features, styles) => {
|
|
|
300
300
|
if (styles.graticule) {
|
|
301
301
|
layers.push({
|
|
302
302
|
styles: styles.graticule,
|
|
303
|
-
path: geoGraticule().step([
|
|
303
|
+
path: d33.geoGraticule().step([
|
|
304
304
|
6,
|
|
305
305
|
6
|
|
306
306
|
])()
|
|
@@ -310,13 +310,13 @@ var createLayers = (topology, features, styles) => {
|
|
|
310
310
|
if (topology.objects.land && styles.land) {
|
|
311
311
|
layers.push({
|
|
312
312
|
styles: styles.land,
|
|
313
|
-
path: feature(topology, topology.objects.land)
|
|
313
|
+
path: topojson.feature(topology, topology.objects.land)
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
if (topology.objects.countries && styles.border) {
|
|
317
317
|
layers.push({
|
|
318
318
|
styles: styles.border,
|
|
319
|
-
path: mesh(topology, topology.objects.countries, (a, b) => a !== b)
|
|
319
|
+
path: topojson.mesh(topology, topology.objects.countries, (a, b) => a !== b)
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
322
|
if (topology.objects.dots && styles.dots) {
|
|
@@ -390,7 +390,7 @@ var useDrag = (controller, options = {}) => {
|
|
|
390
390
|
if (!canvas || options.disabled) {
|
|
391
391
|
return;
|
|
392
392
|
}
|
|
393
|
-
geoInertiaDrag(
|
|
393
|
+
geoInertiaDrag(d34.select(canvas), () => {
|
|
394
394
|
controller.setRotation(controller.projection.rotate());
|
|
395
395
|
options.onUpdate?.({
|
|
396
396
|
type: "move",
|
|
@@ -409,7 +409,7 @@ var useDrag = (controller, options = {}) => {
|
|
|
409
409
|
})
|
|
410
410
|
});
|
|
411
411
|
return () => {
|
|
412
|
-
cancelDrag(
|
|
412
|
+
cancelDrag(d34.select(canvas));
|
|
413
413
|
};
|
|
414
414
|
}, [
|
|
415
415
|
controller,
|
|
@@ -463,12 +463,12 @@ var useMapZoomHandler = (controller) => {
|
|
|
463
463
|
};
|
|
464
464
|
|
|
465
465
|
// packages/ui/react-ui-geo/src/hooks/useSpinner.ts
|
|
466
|
-
import
|
|
466
|
+
import * as d35 from "d3";
|
|
467
467
|
import { useEffect as useEffect2, useState } from "react";
|
|
468
468
|
var useSpinner = (controller, options = {}) => {
|
|
469
469
|
const [running, setRunning] = useState(false);
|
|
470
470
|
useEffect2(() => {
|
|
471
|
-
let
|
|
471
|
+
let timer4;
|
|
472
472
|
const start = () => {
|
|
473
473
|
const delta = options.delta ?? [
|
|
474
474
|
1e-3,
|
|
@@ -477,7 +477,7 @@ var useSpinner = (controller, options = {}) => {
|
|
|
477
477
|
];
|
|
478
478
|
let t = 0;
|
|
479
479
|
let lastRotation = controller.projection.rotate();
|
|
480
|
-
|
|
480
|
+
timer4 = d35.timer((elapsed) => {
|
|
481
481
|
const dt = elapsed - t;
|
|
482
482
|
t = elapsed;
|
|
483
483
|
const rotation = [
|
|
@@ -490,9 +490,9 @@ var useSpinner = (controller, options = {}) => {
|
|
|
490
490
|
});
|
|
491
491
|
};
|
|
492
492
|
const stop = () => {
|
|
493
|
-
if (
|
|
494
|
-
|
|
495
|
-
|
|
493
|
+
if (timer4) {
|
|
494
|
+
timer4.stop();
|
|
495
|
+
timer4 = void 0;
|
|
496
496
|
}
|
|
497
497
|
};
|
|
498
498
|
if (controller && running) {
|
|
@@ -516,17 +516,19 @@ var useSpinner = (controller, options = {}) => {
|
|
|
516
516
|
};
|
|
517
517
|
|
|
518
518
|
// packages/ui/react-ui-geo/src/hooks/useTour.ts
|
|
519
|
-
import
|
|
520
|
-
import { useEffect as useEffect3, useState as useState2
|
|
519
|
+
import * as d36 from "d3";
|
|
520
|
+
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
521
521
|
import versor2 from "versor";
|
|
522
|
+
import { log } from "@dxos/log";
|
|
523
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-geo/src/hooks/useTour.ts";
|
|
522
524
|
var TRANSITION_NAME = "globe-tour";
|
|
523
525
|
var defaultDuration = 1500;
|
|
524
526
|
var useTour = (controller, points, options = {}) => {
|
|
525
|
-
const
|
|
527
|
+
const selection2 = d36.selection();
|
|
526
528
|
const [running, setRunning] = useState2(options.running ?? false);
|
|
527
529
|
useEffect3(() => {
|
|
528
530
|
if (!running) {
|
|
529
|
-
|
|
531
|
+
selection2.interrupt(TRANSITION_NAME);
|
|
530
532
|
return;
|
|
531
533
|
}
|
|
532
534
|
let t;
|
|
@@ -536,7 +538,7 @@ var useTour = (controller, points, options = {}) => {
|
|
|
536
538
|
const context = canvas.getContext("2d", {
|
|
537
539
|
alpha: false
|
|
538
540
|
});
|
|
539
|
-
const path = geoPath(projection, context).pointRadius(2);
|
|
541
|
+
const path = d36.geoPath(projection, context).pointRadius(2);
|
|
540
542
|
const tilt = options.tilt ?? 0;
|
|
541
543
|
let last;
|
|
542
544
|
try {
|
|
@@ -552,12 +554,12 @@ var useTour = (controller, points, options = {}) => {
|
|
|
552
554
|
}
|
|
553
555
|
const p1 = last ? geoToPosition(last) : void 0;
|
|
554
556
|
const p2 = geoToPosition(next);
|
|
555
|
-
const ip = geoInterpolate(p1 || p2, p2);
|
|
556
|
-
const distance = geoDistance(p1 || p2, p2);
|
|
557
|
+
const ip = d36.geoInterpolate(p1 || p2, p2);
|
|
558
|
+
const distance = d36.geoDistance(p1 || p2, p2);
|
|
557
559
|
const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
|
|
558
560
|
const r2 = positionToRotation(p2, tilt);
|
|
559
561
|
const iv = versor2.interpolate(r1, r2);
|
|
560
|
-
const transition2 =
|
|
562
|
+
const transition2 = selection2.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
|
|
561
563
|
const t1 = Math.max(0, Math.min(1, t2 * 2 - 1));
|
|
562
564
|
const t22 = Math.min(1, t2 * 2);
|
|
563
565
|
context.save();
|
|
@@ -584,20 +586,28 @@ var useTour = (controller, points, options = {}) => {
|
|
|
584
586
|
context.fill();
|
|
585
587
|
}
|
|
586
588
|
context.restore();
|
|
587
|
-
|
|
588
|
-
|
|
589
|
+
if (options.autoRotate) {
|
|
590
|
+
projection.rotate(iv(t2));
|
|
591
|
+
setRotation(projection.rotate());
|
|
592
|
+
}
|
|
589
593
|
});
|
|
590
594
|
await transition2.end();
|
|
591
595
|
last = next;
|
|
592
596
|
}
|
|
593
597
|
} catch (err) {
|
|
598
|
+
log.catch(err, void 0, {
|
|
599
|
+
F: __dxlog_file,
|
|
600
|
+
L: 112,
|
|
601
|
+
S: void 0,
|
|
602
|
+
C: (f, a) => f(...a)
|
|
603
|
+
});
|
|
594
604
|
} finally {
|
|
595
605
|
setRunning(false);
|
|
596
606
|
}
|
|
597
607
|
});
|
|
598
608
|
return () => {
|
|
599
609
|
clearTimeout(t);
|
|
600
|
-
|
|
610
|
+
selection2.interrupt(TRANSITION_NAME);
|
|
601
611
|
};
|
|
602
612
|
}
|
|
603
613
|
}, [
|
|
@@ -713,16 +723,16 @@ var defaultStyles = {
|
|
|
713
723
|
}
|
|
714
724
|
};
|
|
715
725
|
var projectionMap = {
|
|
716
|
-
orthographic: geoOrthographic,
|
|
717
|
-
mercator: geoMercator,
|
|
718
|
-
"transverse-mercator": geoTransverseMercator
|
|
726
|
+
orthographic: d37.geoOrthographic,
|
|
727
|
+
mercator: d37.geoMercator,
|
|
728
|
+
"transverse-mercator": d37.geoTransverseMercator
|
|
719
729
|
};
|
|
720
730
|
var getProjection = (type = "orthographic") => {
|
|
721
731
|
if (typeof type === "string") {
|
|
722
|
-
const constructor = projectionMap[type] ?? geoOrthographic;
|
|
732
|
+
const constructor = projectionMap[type] ?? d37.geoOrthographic;
|
|
723
733
|
return constructor();
|
|
724
734
|
}
|
|
725
|
-
return type ?? geoOrthographic();
|
|
735
|
+
return type ?? d37.geoOrthographic();
|
|
726
736
|
};
|
|
727
737
|
var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
728
738
|
const { ref, width, height } = useResizeDetector();
|
|
@@ -739,16 +749,16 @@ var GlobeRoot = ({ classNames, children, ...props }) => {
|
|
|
739
749
|
};
|
|
740
750
|
var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topology, features, styles: _styles }, forwardRef3) => {
|
|
741
751
|
const { themeMode } = useThemeContext();
|
|
742
|
-
const styles =
|
|
752
|
+
const styles = useMemo(() => _styles ?? defaultStyles[themeMode], [
|
|
743
753
|
_styles,
|
|
744
754
|
themeMode
|
|
745
755
|
]);
|
|
746
756
|
const [canvas, setCanvas] = useState3(null);
|
|
747
757
|
const canvasRef = (canvas2) => setCanvas(canvas2);
|
|
748
|
-
const projection =
|
|
758
|
+
const projection = useMemo(() => getProjection(_projection), [
|
|
749
759
|
_projection
|
|
750
760
|
]);
|
|
751
|
-
const layers =
|
|
761
|
+
const layers = useMemo(() => {
|
|
752
762
|
return timer(() => createLayers(topology, features, styles));
|
|
753
763
|
}, [
|
|
754
764
|
topology,
|
|
@@ -779,8 +789,8 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topolog
|
|
|
779
789
|
setCenter,
|
|
780
790
|
setScale: (s) => {
|
|
781
791
|
if (typeof s === "function") {
|
|
782
|
-
const is = interpolateNumber(scaleRef.current, s(scaleRef.current));
|
|
783
|
-
transition().ease(zooming.current ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => setScale(is(t))).on("end", () => {
|
|
792
|
+
const is = d37.interpolateNumber(scaleRef.current, s(scaleRef.current));
|
|
793
|
+
d37.transition().ease(zooming.current ? d37.easeLinear : d37.easeSinOut).duration(200).tween("scale", () => (t) => setScale(is(t))).on("end", () => {
|
|
784
794
|
zooming.current = false;
|
|
785
795
|
});
|
|
786
796
|
} else {
|
|
@@ -793,7 +803,7 @@ var GlobeCanvas = /* @__PURE__ */ forwardRef(({ projection: _projection, topolog
|
|
|
793
803
|
}, [
|
|
794
804
|
canvas
|
|
795
805
|
]);
|
|
796
|
-
const generator =
|
|
806
|
+
const generator = useMemo(() => canvas && projection && d37.geoPath(projection, canvas.getContext("2d", {
|
|
797
807
|
alpha: false
|
|
798
808
|
})), [
|
|
799
809
|
canvas,
|
|
@@ -1054,7 +1064,7 @@ export {
|
|
|
1054
1064
|
closestPoint,
|
|
1055
1065
|
controlPositions,
|
|
1056
1066
|
createLayers,
|
|
1057
|
-
geoCircle,
|
|
1067
|
+
geoCircle2 as geoCircle,
|
|
1058
1068
|
geoInertiaDrag,
|
|
1059
1069
|
geoLine,
|
|
1060
1070
|
geoPoint,
|