@dxos/react-ui-geo 0.8.3 → 0.8.4-main.1068cf700f

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 (86) hide show
  1. package/data/airports.ts +1 -1
  2. package/data/cities.ts +1 -1
  3. package/data/countries-110m.ts +1 -1
  4. package/data/countries-dots-3.ts +1 -1
  5. package/data/countries-dots-4.ts +1 -1
  6. package/dist/lib/browser/chunk-GMWLKTLN.mjs +9 -0
  7. package/dist/lib/browser/{countries-110m-WI4PCLDF.mjs → countries-110m-ZM3ZIEFS.mjs} +2 -2
  8. package/dist/lib/browser/countries-110m-ZM3ZIEFS.mjs.map +7 -0
  9. package/dist/lib/browser/data.mjs +1 -1
  10. package/dist/lib/browser/index.mjs +404 -458
  11. package/dist/lib/browser/index.mjs.map +4 -4
  12. package/dist/lib/browser/meta.json +1 -1
  13. package/dist/lib/node-esm/{chunk-PIIEDZEU.mjs → chunk-JODBF4CC.mjs} +3 -3
  14. package/dist/lib/node-esm/{countries-110m-DQ4XRC4B.mjs → countries-110m-3SFASWVD.mjs} +2 -2
  15. package/dist/lib/node-esm/countries-110m-3SFASWVD.mjs.map +7 -0
  16. package/dist/lib/node-esm/data.mjs +1 -1
  17. package/dist/lib/node-esm/index.mjs +404 -458
  18. package/dist/lib/node-esm/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/types/src/components/Globe/Globe.d.ts +1 -1
  21. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  22. package/dist/types/src/components/Globe/Globe.stories.d.ts +25 -9
  23. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  24. package/dist/types/src/components/Map/Map.d.ts +28 -18
  25. package/dist/types/src/components/Map/Map.d.ts.map +1 -1
  26. package/dist/types/src/components/Map/Map.stories.d.ts +14 -8
  27. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
  29. package/dist/types/src/components/index.d.ts +0 -1
  30. package/dist/types/src/components/index.d.ts.map +1 -1
  31. package/dist/types/src/hooks/context.d.ts +7 -7
  32. package/dist/types/src/hooks/context.d.ts.map +1 -1
  33. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +1 -1
  34. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
  35. package/dist/types/src/hooks/useMapZoomHandler.d.ts +1 -1
  36. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
  37. package/dist/types/src/hooks/useSpinner.d.ts +1 -1
  38. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
  39. package/dist/types/src/hooks/useTour.d.ts +4 -3
  40. package/dist/types/src/hooks/useTour.d.ts.map +1 -1
  41. package/dist/types/src/index.d.ts +2 -1
  42. package/dist/types/src/index.d.ts.map +1 -1
  43. package/dist/types/src/translations.d.ts +12 -0
  44. package/dist/types/src/translations.d.ts.map +1 -0
  45. package/dist/types/src/types.d.ts +2 -1
  46. package/dist/types/src/types.d.ts.map +1 -1
  47. package/dist/types/src/util/path.d.ts +5 -8
  48. package/dist/types/src/util/path.d.ts.map +1 -1
  49. package/dist/types/src/util/render.d.ts +4 -4
  50. package/dist/types/src/util/render.d.ts.map +1 -1
  51. package/dist/types/tsconfig.tsbuildinfo +1 -1
  52. package/package.json +29 -23
  53. package/src/components/Globe/Globe.stories.tsx +85 -37
  54. package/src/components/Globe/Globe.tsx +80 -63
  55. package/src/components/Map/Map.stories.tsx +25 -14
  56. package/src/components/Map/Map.tsx +183 -96
  57. package/src/components/Toolbar/Controls.tsx +14 -20
  58. package/src/components/index.ts +0 -2
  59. package/src/hooks/context.tsx +22 -16
  60. package/src/hooks/useGlobeZoomHandler.ts +9 -3
  61. package/src/hooks/useMapZoomHandler.ts +1 -1
  62. package/src/hooks/useSpinner.ts +2 -1
  63. package/src/hooks/useTour.ts +10 -8
  64. package/src/index.ts +2 -1
  65. package/src/translations.ts +20 -0
  66. package/src/types.ts +3 -1
  67. package/src/util/inertia.ts +1 -1
  68. package/src/util/path.ts +5 -6
  69. package/src/util/render.ts +5 -3
  70. package/dist/lib/browser/chunk-ENCWOTYX.mjs +0 -9
  71. package/dist/lib/browser/countries-110m-WI4PCLDF.mjs.map +0 -7
  72. package/dist/lib/node/chunk-LAICG6L2.cjs +0 -40
  73. package/dist/lib/node/chunk-LAICG6L2.cjs.map +0 -7
  74. package/dist/lib/node/countries-110m-KQ5WAB2O.cjs +0 -37877
  75. package/dist/lib/node/countries-110m-KQ5WAB2O.cjs.map +0 -7
  76. package/dist/lib/node/data.cjs +0 -28
  77. package/dist/lib/node/data.cjs.map +0 -7
  78. package/dist/lib/node/index.cjs +0 -1187
  79. package/dist/lib/node/index.cjs.map +0 -7
  80. package/dist/lib/node/meta.json +0 -1
  81. package/dist/lib/node-esm/countries-110m-DQ4XRC4B.mjs.map +0 -7
  82. package/dist/types/src/components/types.d.ts +0 -15
  83. package/dist/types/src/components/types.d.ts.map +0 -1
  84. package/src/components/types.ts +0 -19
  85. /package/dist/lib/browser/{chunk-ENCWOTYX.mjs.map → chunk-GMWLKTLN.mjs.map} +0 -0
  86. /package/dist/lib/node-esm/{chunk-PIIEDZEU.mjs.map → chunk-JODBF4CC.mjs.map} +0 -0
@@ -2,12 +2,13 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { geoPath, geoInterpolate, geoDistance, selection as d3Selection } from 'd3';
6
- import { type SetStateAction, type Dispatch, useEffect, useState, useMemo } from 'react';
5
+ import { selection as d3Selection, geoDistance, geoInterpolate, geoPath } from 'd3';
6
+ import { type Dispatch, type SetStateAction, useEffect, useMemo, useState } from 'react';
7
7
  import versor from 'versor';
8
8
 
9
9
  import type { GlobeController } from '../components';
10
- import { geoToPosition, type LatLng, positionToRotation, type StyleSet } from '../util';
10
+ import { type LatLngLiteral } from '../types';
11
+ import { type StyleSet, geoToPosition, positionToRotation } from '../util';
11
12
 
12
13
  const TRANSITION_NAME = 'globe-tour';
13
14
 
@@ -29,10 +30,11 @@ export type TourOptions = {
29
30
  */
30
31
  export const useTour = (
31
32
  controller?: GlobeController | null,
32
- points?: LatLng[],
33
+ points?: LatLngLiteral[],
33
34
  options: TourOptions = {},
34
35
  ): [boolean, Dispatch<SetStateAction<boolean>>] => {
35
36
  const selection = useMemo(() => d3Selection(), []);
37
+ // TODO(burdon): Redo controlled state.
36
38
  const [running, setRunning] = useState(options.running ?? false);
37
39
  useEffect(() => {
38
40
  if (!running) {
@@ -48,7 +50,7 @@ export const useTour = (
48
50
  const path = geoPath(projection, context).pointRadius(2);
49
51
 
50
52
  const tilt = options.tilt ?? 0;
51
- let last: LatLng;
53
+ let last: LatLngLiteral;
52
54
  try {
53
55
  const p = [...points];
54
56
  if (options.loop) {
@@ -82,14 +84,14 @@ export const useTour = (
82
84
  {
83
85
  context.beginPath();
84
86
  context.strokeStyle = options?.styles?.arc?.strokeStyle ?? 'yellow';
85
- context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.scale ?? 1);
87
+ context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.zoom ?? 1);
86
88
  context.setLineDash(options?.styles?.arc?.lineDash ?? []);
87
89
  path({ type: 'LineString', coordinates: [ip(t1), ip(t2)] });
88
90
  context.stroke();
89
91
 
90
92
  context.beginPath();
91
93
  context.fillStyle = options?.styles?.cursor?.fillStyle ?? 'orange';
92
- path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.scale ?? 1));
94
+ path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.zoom ?? 1));
93
95
  path({ type: 'Point', coordinates: ip(t2) });
94
96
  context.fill();
95
97
  }
@@ -104,7 +106,7 @@ export const useTour = (
104
106
  await transition.end();
105
107
  last = next;
106
108
  }
107
- } catch (err) {
109
+ } catch {
108
110
  // Ignore.
109
111
  } finally {
110
112
  setRunning(false);
package/src/index.ts CHANGED
@@ -5,5 +5,6 @@
5
5
  export * from './components';
6
6
  export * from './data';
7
7
  export * from './hooks';
8
- export * from './types';
8
+ export * from './translations';
9
+ export type * from './types';
9
10
  export * from './util';
@@ -0,0 +1,20 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { type Resource } from '@dxos/react-ui';
6
+
7
+ export const translationKey = '@dxos/react-ui-geo';
8
+
9
+ export const translations = [
10
+ {
11
+ 'en-US': {
12
+ [translationKey]: {
13
+ 'zoom in icon button': 'Zoom in',
14
+ 'zoom out icon button': 'Zoom out',
15
+ 'start icon button': 'Start',
16
+ 'toggle icon button': 'Toggle',
17
+ },
18
+ },
19
+ },
20
+ ] as const satisfies Resource[];
package/src/types.ts CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  import { type LatLngLiteral } from 'leaflet';
6
6
 
7
- export type MapMarker = {
7
+ export { type LatLngLiteral };
8
+
9
+ export type GeoMarker = {
8
10
  id: string;
9
11
  title?: string;
10
12
  location: LatLngLiteral;
@@ -4,7 +4,7 @@
4
4
  // https://github.com/Fil/d3-inertia
5
5
  //
6
6
 
7
- import { select, drag, timer } from 'd3';
7
+ import { drag, select, timer } from 'd3';
8
8
  import versor from 'versor';
9
9
 
10
10
  export const restrictAxis =
package/src/util/path.ts CHANGED
@@ -4,22 +4,21 @@
4
4
 
5
5
  import { type GeoGeometryObjects, geoCircle as d3GeoCircle } from 'd3';
6
6
  import { type Point, type Polygon, type Position } from 'geojson';
7
+ import { type LatLngLiteral } from 'leaflet';
7
8
 
8
9
  import type { Vector } from '../hooks';
9
10
 
10
- export type LatLng = { lat: number; lng: number };
11
-
12
11
  export const positionToRotation = ([lng, lat]: [number, number], tilt = 0): Vector => [-lng, tilt - lat, 0];
13
12
 
14
- export const geoToPosition = ({ lat, lng }: LatLng): [number, number] => [lng, lat];
13
+ export const geoToPosition = ({ lat, lng }: LatLngLiteral): [number, number] => [lng, lat];
15
14
 
16
- export const geoPoint = (point: LatLng): Point => ({ type: 'Point', coordinates: geoToPosition(point) });
15
+ export const geoPoint = (point: LatLngLiteral): Point => ({ type: 'Point', coordinates: geoToPosition(point) });
17
16
 
18
17
  // https://github.com/d3/d3-geo#geoCircle
19
- export const geoCircle = ({ lat, lng }: LatLng, radius: number): Polygon =>
18
+ export const geoCircle = ({ lat, lng }: LatLngLiteral, radius: number): Polygon =>
20
19
  d3GeoCircle().radius(radius).center([lng, lat])();
21
20
 
22
- export const geoLine = (p1: LatLng, p2: LatLng): GeoGeometryObjects => ({
21
+ export const geoLine = (p1: LatLngLiteral, p2: LatLngLiteral): GeoGeometryObjects => ({
23
22
  type: 'LineString',
24
23
  coordinates: [
25
24
  [p1.lng, p1.lat],
@@ -6,7 +6,9 @@ import { type GeoPath, type GeoPermissibleObjects, geoGraticule } from 'd3';
6
6
  import { feature, mesh } from 'topojson-client';
7
7
  import { type Topology } from 'topojson-specification';
8
8
 
9
- import { type LatLng, geoLine, geoPoint } from './path';
9
+ import { type LatLngLiteral } from '../types';
10
+
11
+ import { geoLine, geoPoint } from './path';
10
12
 
11
13
  export type Styles = Record<string, any>;
12
14
 
@@ -25,8 +27,8 @@ export type Style =
25
27
  export type StyleSet = Partial<Record<Style, Styles>>;
26
28
 
27
29
  export type Features = {
28
- points?: LatLng[];
29
- lines?: { source: LatLng; target: LatLng }[];
30
+ points?: LatLngLiteral[];
31
+ lines?: { source: LatLngLiteral; target: LatLngLiteral }[];
30
32
  };
31
33
 
32
34
  export type Layer = {
@@ -1,9 +0,0 @@
1
- // packages/ui/react-ui-geo/src/data.ts
2
- var loadTopology = async () => {
3
- return (await import("./countries-110m-WI4PCLDF.mjs")).default;
4
- };
5
-
6
- export {
7
- loadTopology
8
- };
9
- //# sourceMappingURL=chunk-ENCWOTYX.mjs.map