@dxos/react-ui-geo 0.7.5-labs.ff2ff30 → 0.7.5-main.b19bfc8

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 (38) hide show
  1. package/dist/lib/browser/index.mjs +146 -81
  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 +123 -58
  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 +146 -81
  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 +5 -5
  11. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  12. package/dist/types/src/components/Globe/Globe.stories.d.ts +9 -10
  13. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  14. package/dist/types/src/components/Map/Map.d.ts +9 -10
  15. package/dist/types/src/components/Map/Map.d.ts.map +1 -1
  16. package/dist/types/src/components/Map/Map.stories.d.ts +6 -2
  17. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
  18. package/dist/types/src/components/Toolbar/Controls.d.ts +2 -3
  19. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
  20. package/dist/types/src/components/types.d.ts +2 -1
  21. package/dist/types/src/components/types.d.ts.map +1 -1
  22. package/dist/types/src/hooks/context.d.ts +2 -2
  23. package/dist/types/src/hooks/context.d.ts.map +1 -1
  24. package/dist/types/src/hooks/useTour.d.ts +8 -3
  25. package/dist/types/src/hooks/useTour.d.ts.map +1 -1
  26. package/dist/types/src/util/debug.d.ts.map +1 -1
  27. package/dist/types/src/util/render.d.ts +2 -2
  28. package/dist/types/src/util/render.d.ts.map +1 -1
  29. package/package.json +12 -10
  30. package/src/components/Globe/Globe.stories.tsx +8 -11
  31. package/src/components/Globe/Globe.tsx +56 -32
  32. package/src/components/Map/Map.stories.tsx +28 -6
  33. package/src/components/Map/Map.tsx +93 -82
  34. package/src/components/types.ts +2 -1
  35. package/src/hooks/useDrag.ts +1 -1
  36. package/src/hooks/useTour.ts +31 -19
  37. package/src/util/debug.ts +1 -0
  38. package/src/util/render.ts +18 -4
@@ -77,11 +77,12 @@ var import_react6 = require("react");
77
77
  var d36 = __toESM(require("d3"));
78
78
  var import_react7 = require("react");
79
79
  var import_versor2 = __toESM(require("versor"));
80
+ var import_log = require("@dxos/log");
80
81
  var import_react8 = __toESM(require("react"));
81
82
  var import_react_ui3 = require("@dxos/react-ui");
82
83
  var import_leaflet = require("leaflet/dist/leaflet.css");
83
- var import_leaflet2 = require("leaflet");
84
- var import_react9 = __toESM(require("react"));
84
+ var import_leaflet2 = __toESM(require("leaflet"));
85
+ var import_react9 = require("react");
85
86
  var import_client = require("react-dom/client");
86
87
  var import_react_leaflet = require("react-leaflet");
87
88
  var import_react_resize_detector2 = require("react-resize-detector");
@@ -407,17 +408,22 @@ var createLayers = (topology, features, styles) => {
407
408
  }
408
409
  return layers;
409
410
  };
410
- var renderLayers = (generator, layers = [], scale) => {
411
+ var renderLayers = (generator, layers = [], scale, styles) => {
411
412
  const context = generator.context();
412
413
  const { canvas: { width, height } } = context;
413
414
  context.reset();
414
- context.clearRect(0, 0, width, height);
415
- layers.forEach(({ path, styles }) => {
415
+ if (styles.background) {
416
+ context.fillStyle = styles.background.fillStyle;
417
+ context.fillRect(0, 0, width, height);
418
+ } else {
419
+ context.clearRect(0, 0, width, height);
420
+ }
421
+ layers.forEach(({ path, styles: styles2 }) => {
416
422
  context.save();
417
423
  let fill = false;
418
424
  let stroke = false;
419
- if (styles) {
420
- Object.entries(styles).forEach(([key, value]) => {
425
+ if (styles2) {
426
+ Object.entries(styles2).forEach(([key, value]) => {
421
427
  if (key === "pointRadius") {
422
428
  generator.pointRadius(value * scale);
423
429
  } else {
@@ -464,7 +470,7 @@ var useDrag = (controller, options = {}) => {
464
470
  };
465
471
  }, [
466
472
  controller,
467
- options
473
+ JSON.stringify(options)
468
474
  ]);
469
475
  };
470
476
  var cancelDrag = (node) => node.on(".drag", null);
@@ -555,11 +561,12 @@ var useSpinner = (controller, options = {}) => {
555
561
  () => setRunning(false)
556
562
  ];
557
563
  };
564
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-geo/src/hooks/useTour.ts";
558
565
  var TRANSITION_NAME = "globe-tour";
559
566
  var defaultDuration = 1500;
560
- var useTour = (controller, features, options = {}) => {
567
+ var useTour = (controller, points, options = {}) => {
561
568
  const selection2 = d36.selection();
562
- const [running, setRunning] = (0, import_react7.useState)(false);
569
+ const [running, setRunning] = (0, import_react7.useState)(options.running ?? false);
563
570
  (0, import_react7.useEffect)(() => {
564
571
  if (!running) {
565
572
  selection2.interrupt(TRANSITION_NAME);
@@ -573,10 +580,16 @@ var useTour = (controller, features, options = {}) => {
573
580
  alpha: false
574
581
  });
575
582
  const path = d36.geoPath(projection, context).pointRadius(2);
576
- const tilt = 0;
583
+ const tilt = options.tilt ?? 0;
577
584
  let last;
578
585
  try {
579
- for (const next of features.points) {
586
+ const p = [
587
+ ...points
588
+ ];
589
+ if (options.loop) {
590
+ p.push(p[0]);
591
+ }
592
+ for (const next of p) {
580
593
  if (!running) {
581
594
  break;
582
595
  }
@@ -614,13 +627,22 @@ var useTour = (controller, features, options = {}) => {
614
627
  context.fill();
615
628
  }
616
629
  context.restore();
617
- projection.rotate(iv(t2));
618
- setRotation(projection.rotate());
630
+ if (options.autoRotate) {
631
+ projection.rotate(iv(t2));
632
+ setRotation(projection.rotate());
633
+ }
619
634
  });
620
635
  await transition2.end();
621
636
  last = next;
622
637
  }
623
638
  } 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
+ } finally {
624
646
  setRunning(false);
625
647
  }
626
648
  });
@@ -631,15 +653,12 @@ var useTour = (controller, features, options = {}) => {
631
653
  }
632
654
  }, [
633
655
  controller,
634
- running
656
+ running,
657
+ JSON.stringify(options)
635
658
  ]);
636
659
  return [
637
- () => {
638
- if (!options.disabled) {
639
- setRunning(true);
640
- }
641
- },
642
- () => setRunning(false)
660
+ running,
661
+ setRunning
643
662
  ];
644
663
  };
645
664
  var controlPositions = {
@@ -697,28 +716,45 @@ var ActionControls = ({ classNames, onAction }) => {
697
716
  }));
698
717
  };
699
718
  var defaultStyles = {
700
- background: {
701
- fillStyle: "#111111"
702
- },
703
- water: {
704
- fillStyle: "#123E6A"
705
- },
706
- hex: {
707
- strokeStyle: "green",
708
- fillStyle: "gray",
709
- pointRadius: 1
710
- },
711
- land: {
712
- fillStyle: "#032153"
713
- },
714
- line: {
715
- strokeStyle: "#111111"
719
+ light: {
720
+ background: {
721
+ fillStyle: "#EEE"
722
+ },
723
+ water: {
724
+ fillStyle: "#555"
725
+ },
726
+ land: {
727
+ fillStyle: "#999"
728
+ },
729
+ line: {
730
+ strokeStyle: "darkred"
731
+ },
732
+ point: {
733
+ fillStyle: "#111111",
734
+ strokeStyle: "#111111",
735
+ strokeWidth: 1,
736
+ pointRadius: 0.5
737
+ }
716
738
  },
717
- point: {
718
- fillStyle: "#111111",
719
- strokeStyle: "#111111",
720
- strokeWidth: 1,
721
- pointRadius: 0.5
739
+ dark: {
740
+ background: {
741
+ fillStyle: "#111111"
742
+ },
743
+ water: {
744
+ fillStyle: "#123E6A"
745
+ },
746
+ land: {
747
+ fillStyle: "#032153"
748
+ },
749
+ line: {
750
+ strokeStyle: "#111111"
751
+ },
752
+ point: {
753
+ fillStyle: "#111111",
754
+ strokeStyle: "#111111",
755
+ strokeWidth: 1,
756
+ pointRadius: 0.5
757
+ }
722
758
  }
723
759
  };
724
760
  var projectionMap = {
@@ -746,7 +782,12 @@ var GlobeRoot = ({ classNames, children, ...props }) => {
746
782
  ...props
747
783
  }, children));
748
784
  };
749
- var GlobeCanvas = /* @__PURE__ */ (0, import_react.forwardRef)(({ projection: _projection, topology, features, styles = defaultStyles }, forwardRef3) => {
785
+ 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
+ ]);
750
791
  const [canvas, setCanvas] = (0, import_react.useState)(null);
751
792
  const canvasRef = (canvas2) => setCanvas(canvas2);
752
793
  const projection = (0, import_react.useMemo)(() => getProjection(_projection), [
@@ -814,7 +855,7 @@ var GlobeCanvas = /* @__PURE__ */ (0, import_react.forwardRef)(({ projection: _p
814
855
  0,
815
856
  0
816
857
  ]);
817
- renderLayers(generator, layers, scale);
858
+ renderLayers(generator, layers, scale, styles);
818
859
  });
819
860
  }
820
861
  }, [
@@ -884,7 +925,7 @@ var defaults = {
884
925
  zoom: 4
885
926
  };
886
927
  var MapRoot = ({ classNames, center = defaults.center, zoom = defaults.zoom, ...props }) => {
887
- return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.MapContainer, {
928
+ return /* @__PURE__ */ React.createElement(import_react_leaflet.MapContainer, {
888
929
  className: (0, import_react_ui_theme2.mx)("relative flex w-full h-full grow bg-baseSurface", classNames),
889
930
  attributionControl: false,
890
931
  // TODO(burdon): Only if attention.
@@ -895,7 +936,7 @@ var MapRoot = ({ classNames, center = defaults.center, zoom = defaults.zoom, ...
895
936
  ...props
896
937
  });
897
938
  };
898
- var MapCanvas = /* @__PURE__ */ (0, import_react9.forwardRef)(({ markers = [], center, zoom, onChange }, forwardedRef) => {
939
+ var MapCanvas = /* @__PURE__ */ (0, import_react9.forwardRef)(({ markers, center, zoom, onChange }, forwardedRef) => {
899
940
  const { ref, width, height } = (0, import_react_resize_detector2.useResizeDetector)({
900
941
  refreshRate: 200
901
942
  });
@@ -955,20 +996,44 @@ var MapCanvas = /* @__PURE__ */ (0, import_react9.forwardRef)(({ markers = [], c
955
996
  }, [
956
997
  markers
957
998
  ]);
958
- return /* @__PURE__ */ import_react9.default.createElement("div", {
999
+ return /* @__PURE__ */ React.createElement("div", {
959
1000
  ref,
960
1001
  className: "flex w-full h-full overflow-hidden bg-baseSurface"
961
- }, /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.TileLayer, {
1002
+ }, /* @__PURE__ */ React.createElement(import_react_leaflet.TileLayer, {
962
1003
  className: "dark:filter dark:grayscale dark:invert",
963
1004
  url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
964
- }), markers.map(({ id, title, location: { lat, lng } }) => {
965
- return /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Marker, {
1005
+ }), markers?.map(({ id, title, location: { lat, lng } }) => {
1006
+ return /* @__PURE__ */ React.createElement(import_react_leaflet.Marker, {
966
1007
  key: id,
967
1008
  position: {
968
1009
  lat,
969
1010
  lng
970
- }
971
- }, title && /* @__PURE__ */ import_react9.default.createElement(import_react_leaflet.Popup, null, title));
1011
+ },
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__ */ React.createElement(import_react_leaflet.Popup, null, title));
972
1037
  }));
973
1038
  });
974
1039
  var CustomControl2 = ({ position, children }) => {
@@ -982,9 +1047,9 @@ var CustomControl2 = ({ position, children }) => {
982
1047
  import_leaflet2.DomEvent.disableClickPropagation(container);
983
1048
  import_leaflet2.DomEvent.disableScrollPropagation(container);
984
1049
  const root = (0, import_client.createRoot)(container);
985
- root.render(/* @__PURE__ */ import_react9.default.createElement(import_react_ui4.ThemeProvider, {
1050
+ root.render(/* @__PURE__ */ React.createElement(import_react_ui4.ThemeProvider, {
986
1051
  tx: import_react_ui_theme2.defaultTx
987
- }, /* @__PURE__ */ import_react9.default.createElement(import_react_ui4.Tooltip.Provider, null, children)));
1052
+ }, /* @__PURE__ */ React.createElement(import_react_ui4.Tooltip.Provider, null, children)));
988
1053
  return container;
989
1054
  };
990
1055
  control.addTo(map);
@@ -1001,16 +1066,16 @@ var CustomControl2 = ({ position, children }) => {
1001
1066
  var Map = {
1002
1067
  Root: MapRoot,
1003
1068
  Canvas: MapCanvas,
1004
- Zoom: ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1069
+ Zoom: ({ onAction, position = "bottomleft", ...props }) => /* @__PURE__ */ React.createElement(CustomControl2, {
1005
1070
  position,
1006
1071
  ...props
1007
- }, /* @__PURE__ */ import_react9.default.createElement(ZoomControls, {
1072
+ }, /* @__PURE__ */ React.createElement(ZoomControls, {
1008
1073
  onAction
1009
1074
  })),
1010
- Action: ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ import_react9.default.createElement(CustomControl2, {
1075
+ Action: ({ onAction, position = "bottomright", ...props }) => /* @__PURE__ */ React.createElement(CustomControl2, {
1011
1076
  position,
1012
1077
  ...props
1013
- }, /* @__PURE__ */ import_react9.default.createElement(ActionControls, {
1078
+ }, /* @__PURE__ */ React.createElement(ActionControls, {
1014
1079
  onAction
1015
1080
  }))
1016
1081
  };