@dxos/react-ui-geo 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc

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 (85) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs → countries-110m-RE5RNRQG.mjs} +1 -1
  3. package/dist/lib/browser/data.mjs +4 -3
  4. package/dist/lib/browser/data.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +381 -451
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/translations.mjs +19 -0
  9. package/dist/lib/browser/translations.mjs.map +7 -0
  10. package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs → countries-110m-4EDBXSFJ.mjs} +1 -1
  11. package/dist/lib/node-esm/data.mjs +5 -3
  12. package/dist/lib/node-esm/data.mjs.map +4 -4
  13. package/dist/lib/node-esm/index.mjs +381 -450
  14. package/dist/lib/node-esm/index.mjs.map +3 -3
  15. package/dist/lib/node-esm/meta.json +1 -1
  16. package/dist/lib/node-esm/translations.mjs +21 -0
  17. package/dist/lib/node-esm/translations.mjs.map +7 -0
  18. package/dist/types/data/airports.d.ts +4 -4
  19. package/dist/types/data/airports.d.ts.map +1 -1
  20. package/dist/types/data/cities.d.ts.map +1 -1
  21. package/dist/types/data/countries-110m.d.ts.map +1 -1
  22. package/dist/types/data/countries-dots-3.d.ts.map +1 -1
  23. package/dist/types/data/countries-dots-4.d.ts.map +1 -1
  24. package/dist/types/src/components/Globe/Globe.d.ts +6 -4
  25. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -1
  26. package/dist/types/src/components/Globe/Globe.stories.d.ts +27 -9
  27. package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
  28. package/dist/types/src/components/Map/Map.d.ts +42 -18
  29. package/dist/types/src/components/Map/Map.d.ts.map +1 -1
  30. package/dist/types/src/components/Map/Map.stories.d.ts +14 -8
  31. package/dist/types/src/components/Map/Map.stories.d.ts.map +1 -1
  32. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -1
  33. package/dist/types/src/components/index.d.ts +0 -1
  34. package/dist/types/src/components/index.d.ts.map +1 -1
  35. package/dist/types/src/hooks/context.d.ts +6 -8
  36. package/dist/types/src/hooks/context.d.ts.map +1 -1
  37. package/dist/types/src/hooks/useDrag.d.ts.map +1 -1
  38. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +2 -2
  39. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -1
  40. package/dist/types/src/hooks/useMapZoomHandler.d.ts +2 -2
  41. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -1
  42. package/dist/types/src/hooks/useSpinner.d.ts +1 -1
  43. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -1
  44. package/dist/types/src/hooks/useTour.d.ts +4 -3
  45. package/dist/types/src/hooks/useTour.d.ts.map +1 -1
  46. package/dist/types/src/index.d.ts +0 -1
  47. package/dist/types/src/index.d.ts.map +1 -1
  48. package/dist/types/src/translations.d.ts +12 -0
  49. package/dist/types/src/translations.d.ts.map +1 -0
  50. package/dist/types/src/types.d.ts +2 -1
  51. package/dist/types/src/types.d.ts.map +1 -1
  52. package/dist/types/src/util/debug.d.ts.map +1 -1
  53. package/dist/types/src/util/inertia.d.ts.map +1 -1
  54. package/dist/types/src/util/path.d.ts +5 -8
  55. package/dist/types/src/util/path.d.ts.map +1 -1
  56. package/dist/types/src/util/render.d.ts +4 -4
  57. package/dist/types/src/util/render.d.ts.map +1 -1
  58. package/dist/types/tsconfig.tsbuildinfo +1 -1
  59. package/package.json +44 -35
  60. package/src/components/Globe/Globe.stories.tsx +82 -35
  61. package/src/components/Globe/Globe.tsx +101 -54
  62. package/src/components/Map/Map.stories.tsx +27 -15
  63. package/src/components/Map/Map.tsx +220 -94
  64. package/src/components/Toolbar/Controls.tsx +14 -20
  65. package/src/components/index.ts +0 -2
  66. package/src/hooks/context.tsx +11 -34
  67. package/src/hooks/useGlobeZoomHandler.ts +9 -3
  68. package/src/hooks/useMapZoomHandler.ts +1 -1
  69. package/src/hooks/useSpinner.ts +1 -1
  70. package/src/hooks/useTour.ts +10 -8
  71. package/src/index.ts +0 -1
  72. package/src/translations.ts +20 -0
  73. package/src/types.ts +3 -1
  74. package/src/util/inertia.ts +1 -1
  75. package/src/util/path.ts +5 -6
  76. package/src/util/render.ts +4 -3
  77. package/dist/lib/browser/chunk-GMWLKTLN.mjs +0 -9
  78. package/dist/lib/browser/chunk-GMWLKTLN.mjs.map +0 -7
  79. package/dist/lib/node-esm/chunk-JODBF4CC.mjs +0 -11
  80. package/dist/lib/node-esm/chunk-JODBF4CC.mjs.map +0 -7
  81. package/dist/types/src/components/types.d.ts +0 -15
  82. package/dist/types/src/components/types.d.ts.map +0 -1
  83. package/src/components/types.ts +0 -19
  84. /package/dist/lib/browser/{countries-110m-ZM3ZIEFS.mjs.map → countries-110m-RE5RNRQG.mjs.map} +0 -0
  85. /package/dist/lib/node-esm/{countries-110m-3SFASWVD.mjs.map → countries-110m-4EDBXSFJ.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
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  export * from './components';
6
- export * from './data';
7
6
  export * from './hooks';
8
7
  export type * from './types';
9
8
  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,8 @@ 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
+ import { geoLine, geoPoint } from './path';
10
11
 
11
12
  export type Styles = Record<string, any>;
12
13
 
@@ -25,8 +26,8 @@ export type Style =
25
26
  export type StyleSet = Partial<Record<Style, Styles>>;
26
27
 
27
28
  export type Features = {
28
- points?: LatLng[];
29
- lines?: { source: LatLng; target: LatLng }[];
29
+ points?: LatLngLiteral[];
30
+ lines?: { source: LatLngLiteral; target: LatLngLiteral }[];
30
31
  };
31
32
 
32
33
  export type Layer = {
@@ -1,9 +0,0 @@
1
- // src/data.ts
2
- var loadTopology = async () => {
3
- return (await import("./countries-110m-ZM3ZIEFS.mjs")).default;
4
- };
5
-
6
- export {
7
- loadTopology
8
- };
9
- //# sourceMappingURL=chunk-GMWLKTLN.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/data.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Topology } from 'topojson-specification';\n\nexport const loadTopology = async (): Promise<Topology> => {\n return (await import('../data/countries-110m.ts')).default;\n};\n"],
5
- "mappings": ";AAMO,IAAMA,eAAe,YAAA;AAC1B,UAAQ,MAAM,OAAO,+BAAA,GAA8BC;AACrD;",
6
- "names": ["loadTopology", "default"]
7
- }
@@ -1,11 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/data.ts
4
- var loadTopology = async () => {
5
- return (await import("./countries-110m-3SFASWVD.mjs")).default;
6
- };
7
-
8
- export {
9
- loadTopology
10
- };
11
- //# sourceMappingURL=chunk-JODBF4CC.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/data.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Topology } from 'topojson-specification';\n\nexport const loadTopology = async (): Promise<Topology> => {\n return (await import('../data/countries-110m.ts')).default;\n};\n"],
5
- "mappings": ";;;AAMO,IAAMA,eAAe,YAAA;AAC1B,UAAQ,MAAM,OAAO,+BAAA,GAA8BC;AACrD;",
6
- "names": ["loadTopology", "default"]
7
- }
@@ -1,15 +0,0 @@
1
- import { type LatLngLiteral } from 'leaflet';
2
- import { type ThemedClassName } from '@dxos/react-ui';
3
- import { type MapMarker } from '../types';
4
- export { type LatLngLiteral };
5
- export type MapCanvasProps = ThemedClassName<{
6
- markers?: MapMarker[];
7
- selected?: string[];
8
- zoom?: number;
9
- center?: LatLngLiteral;
10
- onChange?: (ev: {
11
- center: LatLngLiteral;
12
- zoom: number;
13
- }) => void;
14
- }>;
15
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/components/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,KAAK,aAAa,EAAE,CAAC;AAE9B,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC;IAC3C,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAClE,CAAC,CAAC"}
@@ -1,19 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type LatLngLiteral } from 'leaflet';
6
-
7
- import { type ThemedClassName } from '@dxos/react-ui';
8
-
9
- import { type MapMarker } from '../types';
10
-
11
- export { type LatLngLiteral };
12
-
13
- export type MapCanvasProps = ThemedClassName<{
14
- markers?: MapMarker[];
15
- selected?: string[];
16
- zoom?: number;
17
- center?: LatLngLiteral;
18
- onChange?: (ev: { center: LatLngLiteral; zoom: number }) => void;
19
- }>;