@dxos/react-ui-geo 0.8.1 → 0.8.2-main.10c050d

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.
Files changed (36) hide show
  1. package/dist/lib/browser/index.mjs +457 -380
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node/index.cjs +455 -378
  5. package/dist/lib/node/index.cjs.map +3 -3
  6. package/dist/lib/node/meta.json +1 -1
  7. package/dist/lib/node-esm/index.mjs +457 -380
  8. package/dist/lib/node-esm/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  11. package/dist/types/src/components/Map/Map.stories.d.ts +5 -4
  12. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
  13. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
  14. package/dist/types/src/hooks/context.d.ts.map +1 -1
  15. package/dist/types/src/hooks/useDrag.d.ts.map +1 -1
  16. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
  17. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
  18. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
  19. package/dist/types/src/hooks/useTour.d.ts +1 -1
  20. package/dist/types/src/hooks/useTour.d.ts.map +1 -1
  21. package/dist/types/src/util/debug.d.ts.map +1 -1
  22. package/dist/types/src/util/inertia.d.ts +1 -2
  23. package/dist/types/src/util/inertia.d.ts.map +1 -1
  24. package/dist/types/src/util/path.d.ts.map +1 -1
  25. package/dist/types/src/util/render.d.ts.map +1 -1
  26. package/dist/types/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +12 -11
  28. package/src/components/Globe/Globe.stories.tsx +1 -1
  29. package/src/components/Globe/Globe.tsx +20 -11
  30. package/src/components/Map/Map.stories.tsx +5 -5
  31. package/src/hooks/useDrag.ts +3 -3
  32. package/src/hooks/useSpinner.ts +2 -2
  33. package/src/hooks/useTour.ts +9 -13
  34. package/src/util/inertia.ts +4 -5
  35. package/src/util/path.ts +2 -5
  36. package/src/util/render.ts +5 -6
@@ -35,7 +35,7 @@ __export(node_exports, {
35
35
  closestPoint: () => closestPoint,
36
36
  controlPositions: () => controlPositions,
37
37
  createLayers: () => createLayers,
38
- geoCircle: () => geoCircle2,
38
+ geoCircle: () => geoCircle,
39
39
  geoInertiaDrag: () => geoInertiaDrag,
40
40
  geoLine: () => geoLine,
41
41
  geoPoint: () => geoPoint,
@@ -55,31 +55,34 @@ __export(node_exports, {
55
55
  });
56
56
  module.exports = __toCommonJS(node_exports);
57
57
  var import_chunk_LAICG6L2 = require("./chunk-LAICG6L2.cjs");
58
- var d37 = __toESM(require("d3"));
58
+ var import_tracking = require("@preact-signals/safe-react/tracking");
59
+ var import_d3 = require("d3");
59
60
  var import_react = __toESM(require("react"));
60
61
  var import_react_resize_detector = require("react-resize-detector");
61
62
  var import_react_ui = require("@dxos/react-ui");
62
63
  var import_react_ui_theme = require("@dxos/react-ui-theme");
64
+ var import_tracking2 = require("@preact-signals/safe-react/tracking");
63
65
  var import_react2 = __toESM(require("react"));
64
66
  var import_debug = require("@dxos/debug");
65
67
  var import_react_ui2 = require("@dxos/react-ui");
66
- var d34 = __toESM(require("d3"));
68
+ var import_d32 = require("d3");
67
69
  var import_react3 = require("react");
68
- var d3 = __toESM(require("d3"));
70
+ var import_d33 = require("d3");
69
71
  var import_versor = __toESM(require("versor"));
70
- var d32 = __toESM(require("d3"));
71
- var d33 = __toESM(require("d3"));
72
- var topojson = __toESM(require("topojson-client"));
72
+ var import_d34 = require("d3");
73
+ var import_d35 = require("d3");
74
+ var import_topojson_client = require("topojson-client");
73
75
  var import_react4 = require("react");
74
76
  var import_react5 = require("react");
75
- var d35 = __toESM(require("d3"));
77
+ var import_d36 = require("d3");
76
78
  var import_react6 = require("react");
77
- var d36 = __toESM(require("d3"));
79
+ var import_d37 = require("d3");
78
80
  var import_react7 = require("react");
79
81
  var import_versor2 = __toESM(require("versor"));
80
- var import_log = require("@dxos/log");
82
+ var import_tracking3 = require("@preact-signals/safe-react/tracking");
81
83
  var import_react8 = __toESM(require("react"));
82
84
  var import_react_ui3 = require("@dxos/react-ui");
85
+ var import_tracking4 = require("@preact-signals/safe-react/tracking");
83
86
  var import_leaflet = require("leaflet/dist/leaflet.css");
84
87
  var import_leaflet2 = __toESM(require("leaflet"));
85
88
  var import_react9 = __toESM(require("react"));
@@ -91,23 +94,28 @@ var import_react_ui4 = require("@dxos/react-ui");
91
94
  var import_react_ui_theme2 = require("@dxos/react-ui-theme");
92
95
  var GlobeContext = /* @__PURE__ */ (0, import_react2.createContext)(void 0);
93
96
  var GlobeContextProvider = ({ children, size, center: _center, scale: _scale, translation: _translation, rotation: _rotation }) => {
94
- const [center, setCenter] = (0, import_react_ui2.useControlledState)(_center);
95
- const [scale, setScale] = (0, import_react_ui2.useControlledState)(_scale);
96
- const [translation, setTranslation] = (0, import_react_ui2.useControlledState)(_translation);
97
- const [rotation, setRotation] = (0, import_react_ui2.useControlledState)(_rotation);
98
- return /* @__PURE__ */ import_react2.default.createElement(GlobeContext.Provider, {
99
- value: {
100
- size,
101
- center,
102
- scale,
103
- translation,
104
- rotation,
105
- setCenter,
106
- setScale,
107
- setTranslation,
108
- setRotation
109
- }
110
- }, children);
97
+ var _effect = (0, import_tracking2.useSignals)();
98
+ try {
99
+ const [center, setCenter] = (0, import_react_ui2.useControlledState)(_center);
100
+ const [scale, setScale] = (0, import_react_ui2.useControlledState)(_scale);
101
+ const [translation, setTranslation] = (0, import_react_ui2.useControlledState)(_translation);
102
+ const [rotation, setRotation] = (0, import_react_ui2.useControlledState)(_rotation);
103
+ return /* @__PURE__ */ import_react2.default.createElement(GlobeContext.Provider, {
104
+ value: {
105
+ size,
106
+ center,
107
+ scale,
108
+ translation,
109
+ rotation,
110
+ setCenter,
111
+ setScale,
112
+ setTranslation,
113
+ setRotation
114
+ }
115
+ }, children);
116
+ } finally {
117
+ _effect.f();
118
+ }
111
119
  };
112
120
  var useGlobeContext = () => {
113
121
  return (0, import_react2.useContext)(GlobeContext) ?? (0, import_debug.raise)(new Error("Missing GlobeContext"));
@@ -133,7 +141,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
133
141
  if (target.node) {
134
142
  target = target.node();
135
143
  }
136
- target = d3.select(target);
144
+ target = (0, import_d33.select)(target);
137
145
  const inertia = geoInertiaDragHelper({
138
146
  projection,
139
147
  render: (rotation) => {
@@ -157,7 +165,7 @@ var geoInertiaDrag = (target, render, projection, options) => {
157
165
  time: options.time,
158
166
  hold: options.hold
159
167
  });
160
- target.call(d3.drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
168
+ target.call((0, import_d33.drag)().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
161
169
  return inertia;
162
170
  };
163
171
  var geoInertiaDragHelper = (opt) => {
@@ -218,7 +226,7 @@ function inertiaHelper(opt) {
218
226
  0,
219
227
  0
220
228
  ],
221
- timer: d3.timer(() => {
229
+ timer: (0, import_d33.timer)(() => {
222
230
  }),
223
231
  time: 0,
224
232
  t: 0,
@@ -309,7 +317,7 @@ var geoPoint = (point) => ({
309
317
  type: "Point",
310
318
  coordinates: geoToPosition(point)
311
319
  });
312
- var geoCircle2 = ({ lat, lng }, radius) => d32.geoCircle().radius(radius).center([
320
+ var geoCircle = ({ lat, lng }, radius) => (0, import_d34.geoCircle)().radius(radius).center([
313
321
  lng,
314
322
  lat
315
323
  ])();
@@ -359,7 +367,7 @@ var createLayers = (topology, features, styles) => {
359
367
  if (styles.graticule) {
360
368
  layers.push({
361
369
  styles: styles.graticule,
362
- path: d33.geoGraticule().step([
370
+ path: (0, import_d35.geoGraticule)().step([
363
371
  6,
364
372
  6
365
373
  ])()
@@ -369,13 +377,13 @@ var createLayers = (topology, features, styles) => {
369
377
  if (topology.objects.land && styles.land) {
370
378
  layers.push({
371
379
  styles: styles.land,
372
- path: topojson.feature(topology, topology.objects.land)
380
+ path: (0, import_topojson_client.feature)(topology, topology.objects.land)
373
381
  });
374
382
  }
375
383
  if (topology.objects.countries && styles.border) {
376
384
  layers.push({
377
385
  styles: styles.border,
378
- path: topojson.mesh(topology, topology.objects.countries, (a, b) => a !== b)
386
+ path: (0, import_topojson_client.mesh)(topology, topology.objects.countries, (a, b) => a !== b)
379
387
  });
380
388
  }
381
389
  if (topology.objects.dots && styles.dots) {
@@ -447,7 +455,7 @@ var useDrag = (controller, options = {}) => {
447
455
  if (!canvas || options.disabled) {
448
456
  return;
449
457
  }
450
- geoInertiaDrag(d34.select(canvas), () => {
458
+ geoInertiaDrag((0, import_d32.select)(canvas), () => {
451
459
  controller.setRotation(controller.projection.rotate());
452
460
  options.onUpdate?.({
453
461
  type: "move",
@@ -466,7 +474,7 @@ var useDrag = (controller, options = {}) => {
466
474
  })
467
475
  });
468
476
  return () => {
469
- cancelDrag(d34.select(canvas));
477
+ cancelDrag((0, import_d32.select)(canvas));
470
478
  };
471
479
  }, [
472
480
  controller,
@@ -515,7 +523,7 @@ var useMapZoomHandler = (controller) => {
515
523
  var useSpinner = (controller, options = {}) => {
516
524
  const [running, setRunning] = (0, import_react6.useState)(false);
517
525
  (0, import_react6.useEffect)(() => {
518
- let timer4;
526
+ let timer3;
519
527
  const start = () => {
520
528
  const delta = options.delta ?? [
521
529
  1e-3,
@@ -524,7 +532,7 @@ var useSpinner = (controller, options = {}) => {
524
532
  ];
525
533
  let t = 0;
526
534
  let lastRotation = controller.projection.rotate();
527
- timer4 = d35.timer((elapsed) => {
535
+ timer3 = (0, import_d36.timer)((elapsed) => {
528
536
  const dt = elapsed - t;
529
537
  t = elapsed;
530
538
  const rotation = [
@@ -537,9 +545,9 @@ var useSpinner = (controller, options = {}) => {
537
545
  });
538
546
  };
539
547
  const stop = () => {
540
- if (timer4) {
541
- timer4.stop();
542
- timer4 = void 0;
548
+ if (timer3) {
549
+ timer3.stop();
550
+ timer3 = void 0;
543
551
  }
544
552
  };
545
553
  if (controller && running) {
@@ -561,15 +569,14 @@ var useSpinner = (controller, options = {}) => {
561
569
  () => setRunning(false)
562
570
  ];
563
571
  };
564
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-geo/src/hooks/useTour.ts";
565
572
  var TRANSITION_NAME = "globe-tour";
566
573
  var defaultDuration = 1500;
567
574
  var useTour = (controller, points, options = {}) => {
568
- const selection2 = d36.selection();
575
+ const selection = (0, import_react7.useMemo)(() => (0, import_d37.selection)(), []);
569
576
  const [running, setRunning] = (0, import_react7.useState)(options.running ?? false);
570
577
  (0, import_react7.useEffect)(() => {
571
578
  if (!running) {
572
- selection2.interrupt(TRANSITION_NAME);
579
+ selection.interrupt(TRANSITION_NAME);
573
580
  return;
574
581
  }
575
582
  let t;
@@ -579,7 +586,7 @@ var useTour = (controller, points, options = {}) => {
579
586
  const context = canvas.getContext("2d", {
580
587
  alpha: false
581
588
  });
582
- const path = d36.geoPath(projection, context).pointRadius(2);
589
+ const path = (0, import_d37.geoPath)(projection, context).pointRadius(2);
583
590
  const tilt = options.tilt ?? 0;
584
591
  let last;
585
592
  try {
@@ -595,12 +602,12 @@ var useTour = (controller, points, options = {}) => {
595
602
  }
596
603
  const p1 = last ? geoToPosition(last) : void 0;
597
604
  const p2 = geoToPosition(next);
598
- const ip = d36.geoInterpolate(p1 || p2, p2);
599
- const distance = d36.geoDistance(p1 || p2, p2);
605
+ const ip = (0, import_d37.geoInterpolate)(p1 || p2, p2);
606
+ const distance = (0, import_d37.geoDistance)(p1 || p2, p2);
600
607
  const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
601
608
  const r2 = positionToRotation(p2, tilt);
602
609
  const iv = import_versor2.default.interpolate(r1, r2);
603
- const transition2 = selection2.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
610
+ const transition2 = selection.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
604
611
  const t1 = Math.max(0, Math.min(1, t2 * 2 - 1));
605
612
  const t22 = Math.min(1, t2 * 2);
606
613
  context.save();
@@ -627,28 +634,20 @@ var useTour = (controller, points, options = {}) => {
627
634
  context.fill();
628
635
  }
629
636
  context.restore();
630
- if (options.autoRotate) {
631
- projection.rotate(iv(t2));
632
- setRotation(projection.rotate());
633
- }
637
+ projection.rotate(iv(t2));
638
+ setRotation(projection.rotate());
634
639
  });
635
640
  await transition2.end();
636
641
  last = next;
637
642
  }
638
643
  } catch (err) {
639
- import_log.log.catch(err, void 0, {
640
- F: __dxlog_file,
641
- L: 112,
642
- S: void 0,
643
- C: (f, a) => f(...a)
644
- });
645
644
  } finally {
646
645
  setRunning(false);
647
646
  }
648
647
  });
649
648
  return () => {
650
649
  clearTimeout(t);
651
- selection2.interrupt(TRANSITION_NAME);
650
+ selection.interrupt(TRANSITION_NAME);
652
651
  };
653
652
  }
654
653
  }, [
@@ -668,52 +667,62 @@ var controlPositions = {
668
667
  bottomright: "bottom-2 right-2"
669
668
  };
670
669
  var ZoomControls = ({ classNames, onAction }) => {
671
- return /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.Toolbar.Root, {
672
- classNames: [
673
- "gap-1",
674
- classNames
675
- ]
676
- }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
677
- //
678
- icon: "ph--plus--regular",
679
- label: "zoom in",
680
- iconOnly: true,
681
- size: 5,
682
- classNames: "px-0 aspect-square",
683
- onClick: () => onAction?.("zoom-in")
684
- }), /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
685
- //
686
- icon: "ph--minus--regular",
687
- label: "zoom out",
688
- iconOnly: true,
689
- size: 5,
690
- classNames: "px-0 aspect-square",
691
- onClick: () => onAction?.("zoom-out")
692
- }));
670
+ var _effect = (0, import_tracking3.useSignals)();
671
+ try {
672
+ return /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.Toolbar.Root, {
673
+ classNames: [
674
+ "gap-1",
675
+ classNames
676
+ ]
677
+ }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
678
+ //
679
+ icon: "ph--plus--regular",
680
+ label: "zoom in",
681
+ iconOnly: true,
682
+ size: 5,
683
+ classNames: "px-0 aspect-square",
684
+ onClick: () => onAction?.("zoom-in")
685
+ }), /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
686
+ //
687
+ icon: "ph--minus--regular",
688
+ label: "zoom out",
689
+ iconOnly: true,
690
+ size: 5,
691
+ classNames: "px-0 aspect-square",
692
+ onClick: () => onAction?.("zoom-out")
693
+ }));
694
+ } finally {
695
+ _effect.f();
696
+ }
693
697
  };
694
698
  var ActionControls = ({ classNames, onAction }) => {
695
- return /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.Toolbar.Root, {
696
- classNames: [
697
- "gap-1",
698
- classNames
699
- ]
700
- }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
701
- //
702
- icon: "ph--play--regular",
703
- label: "start",
704
- iconOnly: true,
705
- size: 5,
706
- classNames: "px-0 aspect-square",
707
- onClick: () => onAction?.("start")
708
- }), /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
709
- //
710
- icon: "ph--globe-hemisphere-west--regular",
711
- label: "toggle",
712
- iconOnly: true,
713
- size: 5,
714
- classNames: "px-0 aspect-square",
715
- onClick: () => onAction?.("toggle")
716
- }));
699
+ var _effect = (0, import_tracking3.useSignals)();
700
+ try {
701
+ return /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.Toolbar.Root, {
702
+ classNames: [
703
+ "gap-1",
704
+ classNames
705
+ ]
706
+ }, /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
707
+ //
708
+ icon: "ph--play--regular",
709
+ label: "start",
710
+ iconOnly: true,
711
+ size: 5,
712
+ classNames: "px-0 aspect-square",
713
+ onClick: () => onAction?.("start")
714
+ }), /* @__PURE__ */ import_react8.default.createElement(import_react_ui3.IconButton, {
715
+ //
716
+ icon: "ph--globe-hemisphere-west--regular",
717
+ label: "toggle",
718
+ iconOnly: true,
719
+ size: 5,
720
+ classNames: "px-0 aspect-square",
721
+ onClick: () => onAction?.("toggle")
722
+ }));
723
+ } finally {
724
+ _effect.f();
725
+ }
717
726
  };
718
727
  var defaultStyles = {
719
728
  light: {
@@ -758,161 +767,200 @@ var defaultStyles = {
758
767
  }
759
768
  };
760
769
  var projectionMap = {
761
- orthographic: d37.geoOrthographic,
762
- mercator: d37.geoMercator,
763
- "transverse-mercator": d37.geoTransverseMercator
770
+ orthographic: import_d3.geoOrthographic,
771
+ mercator: import_d3.geoMercator,
772
+ "transverse-mercator": import_d3.geoTransverseMercator
764
773
  };
765
774
  var getProjection = (type = "orthographic") => {
766
775
  if (typeof type === "string") {
767
- const constructor = projectionMap[type] ?? d37.geoOrthographic;
776
+ const constructor = projectionMap[type] ?? import_d3.geoOrthographic;
768
777
  return constructor();
769
778
  }
770
- return type ?? d37.geoOrthographic();
779
+ return type ?? (0, import_d3.geoOrthographic)();
771
780
  };
772
781
  var GlobeRoot = ({ classNames, children, ...props }) => {
773
- const { ref, width, height } = (0, import_react_resize_detector.useResizeDetector)();
774
- return /* @__PURE__ */ import_react.default.createElement("div", {
775
- ref,
776
- className: (0, import_react_ui_theme.mx)("relative flex grow overflow-hidden", classNames)
777
- }, /* @__PURE__ */ import_react.default.createElement(GlobeContextProvider, {
778
- size: {
779
- width,
780
- height
781
- },
782
- ...props
783
- }, children));
782
+ var _effect = (0, import_tracking.useSignals)();
783
+ try {
784
+ const { ref, width, height } = (0, import_react_resize_detector.useResizeDetector)();
785
+ return /* @__PURE__ */ import_react.default.createElement("div", {
786
+ ref,
787
+ className: (0, import_react_ui_theme.mx)("relative flex grow overflow-hidden", classNames)
788
+ }, /* @__PURE__ */ import_react.default.createElement(GlobeContextProvider, {
789
+ size: {
790
+ width,
791
+ height
792
+ },
793
+ ...props
794
+ }, children));
795
+ } finally {
796
+ _effect.f();
797
+ }
784
798
  };
785
799
  var GlobeCanvas = /* @__PURE__ */ (0, import_react.forwardRef)(({ projection: _projection, topology, features, styles: _styles }, forwardRef3) => {
786
- const { themeMode } = (0, import_react_ui.useThemeContext)();
787
- const styles = (0, import_react.useMemo)(() => _styles ?? defaultStyles[themeMode], [
788
- _styles,
789
- themeMode
790
- ]);
791
- const [canvas, setCanvas] = (0, import_react.useState)(null);
792
- const canvasRef = (canvas2) => setCanvas(canvas2);
793
- const projection = (0, import_react.useMemo)(() => getProjection(_projection), [
794
- _projection
795
- ]);
796
- const layers = (0, import_react.useMemo)(() => {
797
- return timer(() => createLayers(topology, features, styles));
798
- }, [
799
- topology,
800
- features,
801
- styles
802
- ]);
803
- const { size, center, scale, translation, rotation, setCenter, setScale, setTranslation, setRotation } = useGlobeContext();
804
- const scaleRef = (0, import_react_ui.useDynamicRef)(scale);
805
- (0, import_react.useEffect)(() => {
806
- if (center) {
807
- setScale(1);
808
- setRotation(positionToRotation(geoToPosition(center)));
809
- }
810
- }, [
811
- center
812
- ]);
813
- const zooming = (0, import_react.useRef)(false);
814
- (0, import_react.useImperativeHandle)(forwardRef3, () => {
815
- return {
800
+ var _effect = (0, import_tracking.useSignals)();
801
+ try {
802
+ const { themeMode } = (0, import_react_ui.useThemeContext)();
803
+ const styles = (0, import_react.useMemo)(() => _styles ?? defaultStyles[themeMode], [
804
+ _styles,
805
+ themeMode
806
+ ]);
807
+ const [canvas, setCanvas] = (0, import_react.useState)(null);
808
+ const canvasRef = (canvas2) => setCanvas(canvas2);
809
+ const projection = (0, import_react.useMemo)(() => getProjection(_projection), [
810
+ _projection
811
+ ]);
812
+ const layers = (0, import_react.useMemo)(() => {
813
+ return timer(() => createLayers(topology, features, styles));
814
+ }, [
815
+ topology,
816
+ features,
817
+ styles
818
+ ]);
819
+ const { size, center, scale, translation, rotation, setCenter, setScale, setTranslation, setRotation } = useGlobeContext();
820
+ const scaleRef = (0, import_react_ui.useDynamicRef)(scale);
821
+ (0, import_react.useEffect)(() => {
822
+ if (center) {
823
+ setScale(1);
824
+ setRotation(positionToRotation(geoToPosition(center)));
825
+ }
826
+ }, [
827
+ center
828
+ ]);
829
+ const zooming = (0, import_react.useRef)(false);
830
+ (0, import_react.useImperativeHandle)(forwardRef3, () => {
831
+ return {
832
+ canvas,
833
+ projection,
834
+ center,
835
+ get scale() {
836
+ return scaleRef.current;
837
+ },
838
+ translation,
839
+ rotation,
840
+ setCenter,
841
+ setScale: (s) => {
842
+ if (typeof s === "function") {
843
+ const is = (0, import_d3.interpolateNumber)(scaleRef.current, s(scaleRef.current));
844
+ (0, import_d3.transition)().ease(zooming.current ? import_d3.easeLinear : import_d3.easeSinOut).duration(200).tween("scale", () => (t) => setScale(is(t))).on("end", () => {
845
+ zooming.current = false;
846
+ });
847
+ } else {
848
+ setScale(s);
849
+ }
850
+ },
851
+ setTranslation,
852
+ setRotation
853
+ };
854
+ }, [
855
+ canvas
856
+ ]);
857
+ const generator = (0, import_react.useMemo)(() => canvas && projection && (0, import_d3.geoPath)(projection, canvas.getContext("2d", {
858
+ alpha: false
859
+ })), [
816
860
  canvas,
817
- projection,
818
- center,
819
- get scale() {
820
- return scaleRef.current;
821
- },
861
+ projection
862
+ ]);
863
+ (0, import_react.useEffect)(() => {
864
+ if (canvas && projection) {
865
+ timer(() => {
866
+ projection.scale(Math.min(size.width, size.height) / 2 * scale).translate([
867
+ size.width / 2 + (translation?.x ?? 0),
868
+ size.height / 2 + (translation?.y ?? 0)
869
+ ]).rotate(rotation ?? [
870
+ 0,
871
+ 0,
872
+ 0
873
+ ]);
874
+ renderLayers(generator, layers, scale, styles);
875
+ });
876
+ }
877
+ }, [
878
+ generator,
879
+ size,
880
+ scale,
822
881
  translation,
823
882
  rotation,
824
- setCenter,
825
- setScale: (s) => {
826
- if (typeof s === "function") {
827
- const is = d37.interpolateNumber(scaleRef.current, s(scaleRef.current));
828
- d37.transition().ease(zooming.current ? d37.easeLinear : d37.easeSinOut).duration(200).tween("scale", () => (t) => setScale(is(t))).on("end", () => {
829
- zooming.current = false;
830
- });
831
- } else {
832
- setScale(s);
833
- }
834
- },
835
- setTranslation,
836
- setRotation
837
- };
838
- }, [
839
- canvas
840
- ]);
841
- const generator = (0, import_react.useMemo)(() => canvas && projection && d37.geoPath(projection, canvas.getContext("2d", {
842
- alpha: false
843
- })), [
844
- canvas,
845
- projection
846
- ]);
847
- (0, import_react.useEffect)(() => {
848
- if (canvas && projection) {
849
- timer(() => {
850
- projection.scale(Math.min(size.width, size.height) / 2 * scale).translate([
851
- size.width / 2 + (translation?.x ?? 0),
852
- size.height / 2 + (translation?.y ?? 0)
853
- ]).rotate(rotation ?? [
854
- 0,
855
- 0,
856
- 0
857
- ]);
858
- renderLayers(generator, layers, scale, styles);
859
- });
883
+ layers
884
+ ]);
885
+ if (!size.width || !size.height) {
886
+ return null;
860
887
  }
861
- }, [
862
- generator,
863
- size,
864
- scale,
865
- translation,
866
- rotation,
867
- layers
868
- ]);
869
- if (!size.width || !size.height) {
870
- return null;
888
+ return /* @__PURE__ */ import_react.default.createElement("canvas", {
889
+ ref: canvasRef,
890
+ width: size.width,
891
+ height: size.height
892
+ });
893
+ } finally {
894
+ _effect.f();
871
895
  }
872
- return /* @__PURE__ */ import_react.default.createElement("canvas", {
873
- ref: canvasRef,
874
- width: size.width,
875
- height: size.height
876
- });
877
896
  });
878
897
  var GlobeDebug = ({ position = "topleft" }) => {
879
- const { size, scale, translation, rotation } = useGlobeContext();
880
- return /* @__PURE__ */ import_react.default.createElement("div", {
881
- className: (0, import_react_ui_theme.mx)("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded", controlPositions[position])
882
- }, /* @__PURE__ */ import_react.default.createElement("pre", {
883
- className: "font-mono text-xs text-green-700"
884
- }, JSON.stringify({
885
- size,
886
- scale,
887
- translation,
888
- rotation
889
- }, null, 2)));
898
+ var _effect = (0, import_tracking.useSignals)();
899
+ try {
900
+ const { size, scale, translation, rotation } = useGlobeContext();
901
+ return /* @__PURE__ */ import_react.default.createElement("div", {
902
+ className: (0, import_react_ui_theme.mx)("z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded", controlPositions[position])
903
+ }, /* @__PURE__ */ import_react.default.createElement("pre", {
904
+ className: "font-mono text-xs text-green-700"
905
+ }, JSON.stringify({
906
+ size,
907
+ scale,
908
+ translation,
909
+ rotation
910
+ }, null, 2)));
911
+ } finally {
912
+ _effect.f();
913
+ }
890
914
  };
891
915
  var GlobePanel = ({ position, classNames, children }) => {
892
- return /* @__PURE__ */ import_react.default.createElement("div", {
893
- className: (0, import_react_ui_theme.mx)("z-10 absolute overflow-hidden", controlPositions[position], classNames)
894
- }, children);
916
+ var _effect = (0, import_tracking.useSignals)();
917
+ try {
918
+ return /* @__PURE__ */ import_react.default.createElement("div", {
919
+ className: (0, import_react_ui_theme.mx)("z-10 absolute overflow-hidden", controlPositions[position], classNames)
920
+ }, children);
921
+ } finally {
922
+ _effect.f();
923
+ }
895
924
  };
896
925
  var CustomControl = ({ position, children }) => {
897
- return /* @__PURE__ */ import_react.default.createElement("div", {
898
- className: (0, import_react_ui_theme.mx)("z-10 absolute overflow-hidden", controlPositions[position])
899
- }, children);
926
+ var _effect = (0, import_tracking.useSignals)();
927
+ try {
928
+ return /* @__PURE__ */ import_react.default.createElement("div", {
929
+ className: (0, import_react_ui_theme.mx)("z-10 absolute overflow-hidden", controlPositions[position])
930
+ }, children);
931
+ } finally {
932
+ _effect.f();
933
+ }
900
934
  };
901
935
  var Globe = {
902
936
  Root: GlobeRoot,
903
937
  Canvas: GlobeCanvas,
904
- Zoom: ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ import_react.default.createElement(CustomControl, {
905
- position,
906
- ...props
907
- }, /* @__PURE__ */ import_react.default.createElement(ZoomControls, {
908
- onAction
909
- })),
910
- Action: ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ import_react.default.createElement(CustomControl, {
911
- position,
912
- ...props
913
- }, /* @__PURE__ */ import_react.default.createElement(ActionControls, {
914
- onAction
915
- })),
938
+ Zoom: ({ onAction, position = "bottomleft", ...props }) => {
939
+ var _effect = (0, import_tracking.useSignals)();
940
+ try {
941
+ return /* @__PURE__ */ import_react.default.createElement(CustomControl, {
942
+ position,
943
+ ...props
944
+ }, /* @__PURE__ */ import_react.default.createElement(ZoomControls, {
945
+ onAction
946
+ }));
947
+ } finally {
948
+ _effect.f();
949
+ }
950
+ },
951
+ Action: ({ onAction, position = "bottomright", ...props }) => {
952
+ var _effect = (0, import_tracking.useSignals)();
953
+ try {
954
+ return /* @__PURE__ */ import_react.default.createElement(CustomControl, {
955
+ position,
956
+ ...props
957
+ }, /* @__PURE__ */ import_react.default.createElement(ActionControls, {
958
+ onAction
959
+ }));
960
+ } finally {
961
+ _effect.f();
962
+ }
963
+ },
916
964
  Debug: GlobeDebug,
917
965
  Panel: GlobePanel
918
966
  };
@@ -925,159 +973,188 @@ var defaults = {
925
973
  zoom: 4
926
974
  };
927
975
  var MapRoot = ({ classNames, center = defaults.center, zoom = defaults.zoom, ...props }) => {
928
- return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.MapContainer, {
929
- className: (0, import_react_ui_theme2.mx)("relative flex w-full h-full grow bg-baseSurface", classNames),
930
- attributionControl: false,
931
- // TODO(burdon): Only if attention.
932
- scrollWheelZoom: true,
933
- zoomControl: false,
934
- center,
935
- zoom,
936
- ...props
937
- });
976
+ var _effect = (0, import_tracking4.useSignals)();
977
+ try {
978
+ return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.MapContainer, {
979
+ className: (0, import_react_ui_theme2.mx)("relative flex w-full h-full grow bg-baseSurface", classNames),
980
+ attributionControl: false,
981
+ // TODO(burdon): Only if attention.
982
+ scrollWheelZoom: true,
983
+ zoomControl: false,
984
+ center,
985
+ zoom,
986
+ ...props
987
+ });
988
+ } finally {
989
+ _effect.f();
990
+ }
938
991
  };
939
992
  var MapCanvas = /* @__PURE__ */ (0, import_react9.forwardRef)(({ markers, center, zoom, onChange }, forwardedRef) => {
940
- const { ref, width, height } = (0, import_react_resize_detector2.useResizeDetector)({
941
- refreshRate: 200
942
- });
943
- const map = (0, import_react_leaflet.useMap)();
944
- (0, import_react9.useImperativeHandle)(forwardedRef, () => ({
945
- setCenter: (center2, zoom2) => {
946
- map.setView(center2, zoom2);
947
- },
948
- setZoom: (cb) => {
949
- map.setZoom(cb(map.getZoom()));
950
- }
951
- }), [
952
- map
953
- ]);
954
- (0, import_react9.useEffect)(() => {
955
- if (width && height) {
956
- map.invalidateSize();
957
- }
958
- }, [
959
- width,
960
- height
961
- ]);
962
- (0, import_react9.useEffect)(() => {
963
- if (center) {
964
- map.setView(center, zoom);
965
- } else if (zoom !== void 0) {
966
- map.setZoom(zoom);
967
- }
968
- }, [
969
- center,
970
- zoom
971
- ]);
972
- (0, import_react9.useEffect)(() => {
973
- const handler = (0, import_async.debounce)(() => {
974
- onChange?.({
975
- center: map.getCenter(),
976
- zoom: map.getZoom()
977
- });
978
- }, 100);
979
- map.on("move", handler);
980
- map.on("zoom", handler);
981
- return () => {
982
- map.off("move", handler);
983
- map.off("zoom", handler);
984
- };
985
- }, [
986
- map,
987
- onChange
988
- ]);
989
- (0, import_react9.useEffect)(() => {
990
- if (markers.length > 0) {
991
- const bounds = (0, import_leaflet2.latLngBounds)(markers.map((marker) => marker.location));
992
- map.fitBounds(bounds);
993
- } else {
994
- map.setView(defaults.center, defaults.zoom);
995
- }
996
- }, [
997
- markers
998
- ]);
999
- return /* @__PURE__ */ import_react9.default.createElement("div", {
1000
- ref,
1001
- className: "flex w-full h-full overflow-hidden bg-baseSurface"
1002
- }, /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.TileLayer, {
1003
- className: "dark:filter dark:grayscale dark:invert",
1004
- url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
1005
- }), markers?.map(({ id, title, location: { lat, lng } }) => {
1006
- return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Marker, {
1007
- key: id,
1008
- position: {
1009
- lat,
1010
- lng
993
+ var _effect = (0, import_tracking4.useSignals)();
994
+ try {
995
+ const { ref, width, height } = (0, import_react_resize_detector2.useResizeDetector)({
996
+ refreshRate: 200
997
+ });
998
+ const map = (0, import_react_leaflet.useMap)();
999
+ (0, import_react9.useImperativeHandle)(forwardedRef, () => ({
1000
+ setCenter: (center2, zoom2) => {
1001
+ map.setView(center2, zoom2);
1011
1002
  },
1012
- icon: (
1013
- // TODO(burdon): Create custom icon from bundled assets.
1014
- new import_leaflet2.default.Icon({
1015
- iconUrl: "https://dxos.network/marker-icon.png",
1016
- iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
1017
- shadowUrl: "https://dxos.network/marker-shadow.png",
1018
- iconSize: [
1019
- 25,
1020
- 41
1021
- ],
1022
- iconAnchor: [
1023
- 12,
1024
- 41
1025
- ],
1026
- popupAnchor: [
1027
- 1,
1028
- -34
1029
- ],
1030
- shadowSize: [
1031
- 41,
1032
- 41
1033
- ]
1034
- })
1035
- )
1036
- }, title && /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Popup, null, title));
1037
- }));
1003
+ setZoom: (cb) => {
1004
+ map.setZoom(cb(map.getZoom()));
1005
+ }
1006
+ }), [
1007
+ map
1008
+ ]);
1009
+ (0, import_react9.useEffect)(() => {
1010
+ if (width && height) {
1011
+ map.invalidateSize();
1012
+ }
1013
+ }, [
1014
+ width,
1015
+ height
1016
+ ]);
1017
+ (0, import_react9.useEffect)(() => {
1018
+ if (center) {
1019
+ map.setView(center, zoom);
1020
+ } else if (zoom !== void 0) {
1021
+ map.setZoom(zoom);
1022
+ }
1023
+ }, [
1024
+ center,
1025
+ zoom
1026
+ ]);
1027
+ (0, import_react9.useEffect)(() => {
1028
+ const handler = (0, import_async.debounce)(() => {
1029
+ onChange?.({
1030
+ center: map.getCenter(),
1031
+ zoom: map.getZoom()
1032
+ });
1033
+ }, 100);
1034
+ map.on("move", handler);
1035
+ map.on("zoom", handler);
1036
+ return () => {
1037
+ map.off("move", handler);
1038
+ map.off("zoom", handler);
1039
+ };
1040
+ }, [
1041
+ map,
1042
+ onChange
1043
+ ]);
1044
+ (0, import_react9.useEffect)(() => {
1045
+ if (markers.length > 0) {
1046
+ const bounds = (0, import_leaflet2.latLngBounds)(markers.map((marker) => marker.location));
1047
+ map.fitBounds(bounds);
1048
+ } else {
1049
+ map.setView(defaults.center, defaults.zoom);
1050
+ }
1051
+ }, [
1052
+ markers
1053
+ ]);
1054
+ return /* @__PURE__ */ import_react9.default.createElement("div", {
1055
+ ref,
1056
+ className: "flex w-full h-full overflow-hidden bg-baseSurface"
1057
+ }, /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.TileLayer, {
1058
+ className: "dark:filter dark:grayscale dark:invert",
1059
+ url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
1060
+ }), markers?.map(({ id, title, location: { lat, lng } }) => {
1061
+ return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Marker, {
1062
+ key: id,
1063
+ position: {
1064
+ lat,
1065
+ lng
1066
+ },
1067
+ icon: (
1068
+ // TODO(burdon): Create custom icon from bundled assets.
1069
+ new import_leaflet2.default.Icon({
1070
+ iconUrl: "https://dxos.network/marker-icon.png",
1071
+ iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
1072
+ shadowUrl: "https://dxos.network/marker-shadow.png",
1073
+ iconSize: [
1074
+ 25,
1075
+ 41
1076
+ ],
1077
+ iconAnchor: [
1078
+ 12,
1079
+ 41
1080
+ ],
1081
+ popupAnchor: [
1082
+ 1,
1083
+ -34
1084
+ ],
1085
+ shadowSize: [
1086
+ 41,
1087
+ 41
1088
+ ]
1089
+ })
1090
+ )
1091
+ }, title && /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Popup, null, title));
1092
+ }));
1093
+ } finally {
1094
+ _effect.f();
1095
+ }
1038
1096
  });
1039
1097
  var CustomControl2 = ({ position, children }) => {
1040
- const map = (0, import_react_leaflet.useMap)();
1041
- (0, import_react9.useEffect)(() => {
1042
- const control = new import_leaflet2.Control({
1043
- position
1044
- });
1045
- control.onAdd = () => {
1046
- const container = import_leaflet2.DomUtil.create("div", (0, import_react_ui_theme2.mx)("!m-0", controlPositions[position]));
1047
- import_leaflet2.DomEvent.disableClickPropagation(container);
1048
- import_leaflet2.DomEvent.disableScrollPropagation(container);
1049
- const root = (0, import_client.createRoot)(container);
1050
- root.render(/* @__PURE__ */ import_react9.default.createElement(import_react_ui4.ThemeProvider, {
1051
- tx: import_react_ui_theme2.defaultTx
1052
- }, /* @__PURE__ */ import_react9.default.createElement(import_react_ui4.Tooltip.Provider, null, children)));
1053
- return container;
1054
- };
1055
- control.addTo(map);
1056
- return () => {
1057
- control.remove();
1058
- };
1059
- }, [
1060
- map,
1061
- position,
1062
- children
1063
- ]);
1064
- return null;
1098
+ var _effect = (0, import_tracking4.useSignals)();
1099
+ try {
1100
+ const map = (0, import_react_leaflet.useMap)();
1101
+ (0, import_react9.useEffect)(() => {
1102
+ const control = new import_leaflet2.Control({
1103
+ position
1104
+ });
1105
+ control.onAdd = () => {
1106
+ const container = import_leaflet2.DomUtil.create("div", (0, import_react_ui_theme2.mx)("!m-0", controlPositions[position]));
1107
+ import_leaflet2.DomEvent.disableClickPropagation(container);
1108
+ import_leaflet2.DomEvent.disableScrollPropagation(container);
1109
+ const root = (0, import_client.createRoot)(container);
1110
+ root.render(/* @__PURE__ */ import_react9.default.createElement(import_react_ui4.ThemeProvider, {
1111
+ tx: import_react_ui_theme2.defaultTx
1112
+ }, /* @__PURE__ */ import_react9.default.createElement(import_react_ui4.Tooltip.Provider, null, children)));
1113
+ return container;
1114
+ };
1115
+ control.addTo(map);
1116
+ return () => {
1117
+ control.remove();
1118
+ };
1119
+ }, [
1120
+ map,
1121
+ position,
1122
+ children
1123
+ ]);
1124
+ return null;
1125
+ } finally {
1126
+ _effect.f();
1127
+ }
1065
1128
  };
1066
1129
  var Map = {
1067
1130
  Root: MapRoot,
1068
1131
  Canvas: MapCanvas,
1069
- Zoom: ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1070
- position,
1071
- ...props
1072
- }, /* @__PURE__ */ import_react9.default.createElement(ZoomControls, {
1073
- onAction
1074
- })),
1075
- Action: ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1076
- position,
1077
- ...props
1078
- }, /* @__PURE__ */ import_react9.default.createElement(ActionControls, {
1079
- onAction
1080
- }))
1132
+ Zoom: ({ onAction, position = "bottomleft", ...props }) => {
1133
+ var _effect = (0, import_tracking4.useSignals)();
1134
+ try {
1135
+ return /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1136
+ position,
1137
+ ...props
1138
+ }, /* @__PURE__ */ import_react9.default.createElement(ZoomControls, {
1139
+ onAction
1140
+ }));
1141
+ } finally {
1142
+ _effect.f();
1143
+ }
1144
+ },
1145
+ Action: ({ onAction, position = "bottomright", ...props }) => {
1146
+ var _effect = (0, import_tracking4.useSignals)();
1147
+ try {
1148
+ return /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1149
+ position,
1150
+ ...props
1151
+ }, /* @__PURE__ */ import_react9.default.createElement(ActionControls, {
1152
+ onAction
1153
+ }));
1154
+ } finally {
1155
+ _effect.f();
1156
+ }
1157
+ }
1081
1158
  };
1082
1159
  // Annotate the CommonJS export names for ESM import in node:
1083
1160
  0 && (module.exports = {