@dxos/solid-ui-geo 0.0.0 → 0.8.4-main.1c7ec43d41

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 (88) hide show
  1. package/dist/lib/browser/chunk-RMZP4JBX.mjs +9 -0
  2. package/dist/lib/browser/chunk-RMZP4JBX.mjs.map +7 -0
  3. package/dist/lib/browser/countries-110m-MXSNZ6PF.mjs +37859 -0
  4. package/dist/lib/browser/countries-110m-MXSNZ6PF.mjs.map +7 -0
  5. package/dist/lib/browser/data.mjs +7 -0
  6. package/dist/lib/browser/data.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +1166 -0
  8. package/dist/lib/browser/index.mjs.map +7 -0
  9. package/dist/lib/browser/meta.json +1 -0
  10. package/dist/lib/browser/translations.mjs +19 -0
  11. package/dist/lib/browser/translations.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-ICM52DKE.mjs +11 -0
  13. package/dist/lib/node-esm/chunk-ICM52DKE.mjs.map +7 -0
  14. package/dist/lib/node-esm/countries-110m-HEHEK3AV.mjs +37861 -0
  15. package/dist/lib/node-esm/countries-110m-HEHEK3AV.mjs.map +7 -0
  16. package/dist/lib/node-esm/data.mjs +8 -0
  17. package/dist/lib/node-esm/data.mjs.map +7 -0
  18. package/dist/lib/node-esm/index.mjs +1167 -0
  19. package/dist/lib/node-esm/index.mjs.map +7 -0
  20. package/dist/lib/node-esm/meta.json +1 -0
  21. package/dist/lib/node-esm/translations.mjs +21 -0
  22. package/dist/lib/node-esm/translations.mjs.map +7 -0
  23. package/dist/types/data/airports.d.ts +18 -0
  24. package/dist/types/data/airports.d.ts.map +1 -0
  25. package/dist/types/data/countries-110m.d.ts +36 -0
  26. package/dist/types/data/countries-110m.d.ts.map +1 -0
  27. package/dist/types/data/countries-dots-3.d.ts +9 -0
  28. package/dist/types/data/countries-dots-3.d.ts.map +1 -0
  29. package/dist/types/src/components/Globe/Globe.d.ts +54 -0
  30. package/dist/types/src/components/Globe/Globe.d.ts.map +1 -0
  31. package/dist/types/src/components/Globe/Globe.solid-stories.d.ts +29 -0
  32. package/dist/types/src/components/Globe/Globe.solid-stories.d.ts.map +1 -0
  33. package/dist/types/src/components/Globe/index.d.ts +2 -0
  34. package/dist/types/src/components/Globe/index.d.ts.map +1 -0
  35. package/dist/types/src/components/Map/Map.d.ts +38 -0
  36. package/dist/types/src/components/Map/Map.d.ts.map +1 -0
  37. package/dist/types/src/components/Map/Map.solid-stories.d.ts +17 -0
  38. package/dist/types/src/components/Map/Map.solid-stories.d.ts.map +1 -0
  39. package/dist/types/src/components/Map/index.d.ts +2 -0
  40. package/dist/types/src/components/Map/index.d.ts.map +1 -0
  41. package/dist/types/src/components/Toolbar/Controls.d.ts +11 -0
  42. package/dist/types/src/components/Toolbar/Controls.d.ts.map +1 -0
  43. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  44. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  45. package/dist/types/src/components/index.d.ts +4 -0
  46. package/dist/types/src/components/index.d.ts.map +1 -0
  47. package/dist/types/src/data.d.ts +3 -0
  48. package/dist/types/src/data.d.ts.map +1 -0
  49. package/dist/types/src/hooks/context.d.ts +33 -0
  50. package/dist/types/src/hooks/context.d.ts.map +1 -0
  51. package/dist/types/src/hooks/index.d.ts +7 -0
  52. package/dist/types/src/hooks/index.d.ts.map +1 -0
  53. package/dist/types/src/hooks/useDrag.d.ts +16 -0
  54. package/dist/types/src/hooks/useDrag.d.ts.map +1 -0
  55. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts +3 -0
  56. package/dist/types/src/hooks/useGlobeZoomHandler.d.ts.map +1 -0
  57. package/dist/types/src/hooks/useMapZoomHandler.d.ts +3 -0
  58. package/dist/types/src/hooks/useMapZoomHandler.d.ts.map +1 -0
  59. package/dist/types/src/hooks/useSpinner.d.ts +14 -0
  60. package/dist/types/src/hooks/useSpinner.d.ts.map +1 -0
  61. package/dist/types/src/hooks/useTour.d.ts +22 -0
  62. package/dist/types/src/hooks/useTour.d.ts.map +1 -0
  63. package/dist/types/src/index.d.ts +6 -0
  64. package/dist/types/src/index.d.ts.map +1 -0
  65. package/dist/types/src/translations.d.ts +12 -0
  66. package/dist/types/src/translations.d.ts.map +1 -0
  67. package/dist/types/src/types.d.ts +8 -0
  68. package/dist/types/src/types.d.ts.map +1 -0
  69. package/dist/types/src/util/debug.d.ts +2 -0
  70. package/dist/types/src/util/debug.d.ts.map +1 -0
  71. package/dist/types/src/util/index.d.ts +5 -0
  72. package/dist/types/src/util/index.d.ts.map +1 -0
  73. package/dist/types/src/util/inertia.d.ts +15 -0
  74. package/dist/types/src/util/inertia.d.ts.map +1 -0
  75. package/dist/types/src/util/path.d.ts +12 -0
  76. package/dist/types/src/util/path.d.ts.map +1 -0
  77. package/dist/types/src/util/render.d.ts +26 -0
  78. package/dist/types/src/util/render.d.ts.map +1 -0
  79. package/dist/types/tsconfig.tsbuildinfo +1 -0
  80. package/package.json +28 -22
  81. package/src/components/Globe/Globe.solid-stories.tsx +2 -3
  82. package/src/components/Globe/Globe.tsx +12 -10
  83. package/src/components/Map/Map.solid-stories.tsx +0 -1
  84. package/src/components/Map/Map.tsx +18 -7
  85. package/src/components/Toolbar/Controls.tsx +4 -4
  86. package/src/hooks/useSpinner.ts +0 -1
  87. package/src/index.ts +0 -1
  88. package/src/util/render.ts +0 -1
@@ -0,0 +1,1167 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ loadTopology
4
+ } from "./chunk-ICM52DKE.mjs";
5
+
6
+ // src/components/Globe/Globe.tsx
7
+ import { jsx as _jsx3 } from "solid-js/jsx-runtime";
8
+ import { createResizeObserver } from "@solid-primitives/resize-observer";
9
+ import { easeLinear, easeSinOut, geoMercator, geoOrthographic, geoPath as geoPath2, geoTransverseMercator, interpolateNumber, transition } from "d3";
10
+ import { Show, createEffect as createEffect5, createMemo, createSignal as createSignal4 } from "solid-js";
11
+ import { mx } from "@dxos/ui-theme";
12
+
13
+ // src/hooks/context.tsx
14
+ import { jsx as _jsx } from "solid-js/jsx-runtime";
15
+ import { createContext, createEffect, createSignal, useContext } from "solid-js";
16
+ import { raise } from "@dxos/debug";
17
+ var defaults = {
18
+ center: {
19
+ lat: 51,
20
+ lng: 0
21
+ },
22
+ zoom: 4
23
+ };
24
+ var GlobeContext = createContext();
25
+ var GlobeContextProvider = (props) => {
26
+ const [size, setSize] = createSignal(props.size ?? {
27
+ width: 0,
28
+ height: 0
29
+ });
30
+ const [center, setCenter] = createSignal(props.center ?? defaults.center);
31
+ const [zoom, setZoom] = createSignal(props.zoom ?? defaults.zoom);
32
+ const [translation, setTranslation] = createSignal(props.translation);
33
+ const [rotation, setRotation] = createSignal(props.rotation);
34
+ createEffect(() => {
35
+ if (props.size) {
36
+ setSize(props.size);
37
+ }
38
+ });
39
+ return /* @__PURE__ */ _jsx(GlobeContext.Provider, {
40
+ value: {
41
+ size,
42
+ center,
43
+ zoom,
44
+ translation,
45
+ rotation,
46
+ setCenter,
47
+ setZoom,
48
+ setTranslation,
49
+ setRotation
50
+ },
51
+ children: props.children
52
+ });
53
+ };
54
+ var useGlobeContext = () => {
55
+ return useContext(GlobeContext) ?? raise(new Error("Missing GlobeContext"));
56
+ };
57
+
58
+ // src/hooks/useDrag.ts
59
+ import { select as select2 } from "d3";
60
+ import { createEffect as createEffect2, onCleanup } from "solid-js";
61
+
62
+ // src/util/debug.ts
63
+ var debug = false;
64
+ var timer = (cb) => {
65
+ const start = Date.now();
66
+ const data = cb();
67
+ const t = Date.now() - start / 1e3;
68
+ if (debug) {
69
+ console.log({
70
+ t,
71
+ data
72
+ });
73
+ }
74
+ return data;
75
+ };
76
+
77
+ // src/util/inertia.ts
78
+ import { drag, select, timer as timer2 } from "d3";
79
+ import versor from "versor";
80
+ var restrictAxis = (axis) => (original, current) => current.map((d, i) => axis[i] ? d : original[i]);
81
+ var geoInertiaDrag = (target, render, projection, options) => {
82
+ if (!options) {
83
+ options = {};
84
+ }
85
+ if (target.node) {
86
+ target = target.node();
87
+ }
88
+ target = select(target);
89
+ const inertia = geoInertiaDragHelper({
90
+ projection,
91
+ render: (rotation) => {
92
+ projection.rotate(rotation);
93
+ render && render();
94
+ },
95
+ axis: restrictAxis(options.xAxis ? [
96
+ true,
97
+ false,
98
+ false
99
+ ] : [
100
+ true,
101
+ true,
102
+ true
103
+ ]),
104
+ start: options.start,
105
+ move: options.move,
106
+ end: options.end,
107
+ stop: options.stop,
108
+ finish: options.finish,
109
+ time: options.time,
110
+ hold: options.hold
111
+ });
112
+ target.call(drag().on("start", inertia.start).on("drag", inertia.move).on("end", inertia.end));
113
+ return inertia;
114
+ };
115
+ var geoInertiaDragHelper = (opt) => {
116
+ const projection = opt.projection;
117
+ let v0;
118
+ let r0;
119
+ let q0;
120
+ let v10;
121
+ let v11;
122
+ let q10;
123
+ const inertia = inertiaHelper({
124
+ axis: opt.axis,
125
+ start: () => {
126
+ v0 = versor.cartesian(projection.invert(inertia.position));
127
+ r0 = projection.rotate();
128
+ q0 = versor(r0);
129
+ opt.start && opt.start();
130
+ },
131
+ move: () => {
132
+ const inv = projection.rotate(r0).invert(inertia.position);
133
+ if (isNaN(inv[0])) {
134
+ return;
135
+ }
136
+ const v1 = versor.cartesian(inv);
137
+ const q1 = versor.multiply(q0, versor.delta(v0, v1));
138
+ const r1 = versor.rotation(q1);
139
+ const r2 = opt.axis(r0, r1);
140
+ opt.render(r2);
141
+ opt.move && opt.move();
142
+ },
143
+ end: () => {
144
+ v10 = versor.cartesian(projection.invert(inertia.position.map((d, i) => d - inertia.velocity[i] / 1e3)));
145
+ q10 = versor(projection.rotate());
146
+ v11 = versor.cartesian(projection.invert(inertia.position));
147
+ opt.end && opt.end();
148
+ },
149
+ stop: opt.stop,
150
+ finish: opt.finish,
151
+ render: (t) => {
152
+ const r1 = versor.rotation(versor.multiply(q10, versor.delta(v10, v11, t * 1e3)));
153
+ const r2 = opt.axis(r0, r1);
154
+ opt.render && opt.render(r2);
155
+ },
156
+ time: opt.time
157
+ });
158
+ return inertia;
159
+ };
160
+ function inertiaHelper(opt) {
161
+ const A = opt.time || 5e3;
162
+ const limit = 1.0001;
163
+ const B = -Math.log(1 - 1 / limit);
164
+ const inertia = {
165
+ position: [
166
+ 0,
167
+ 0
168
+ ],
169
+ velocity: [
170
+ 0,
171
+ 0
172
+ ],
173
+ timer: timer2(() => {
174
+ }),
175
+ time: 0,
176
+ t: 0,
177
+ start: function(ev) {
178
+ const position = [
179
+ ev.x,
180
+ ev.y
181
+ ];
182
+ inertia.position = position;
183
+ inertia.velocity = [
184
+ 0,
185
+ 0
186
+ ];
187
+ inertia.timer.stop();
188
+ this.classList.remove("inertia");
189
+ this.classList.add("dragging");
190
+ opt.start && opt.start.call(this, position);
191
+ },
192
+ move: function(ev) {
193
+ const position = [
194
+ ev.x,
195
+ ev.y
196
+ ];
197
+ const time = performance.now();
198
+ const deltaTime = time - inertia.time;
199
+ const decay = 1 - Math.exp(-deltaTime / 1e3);
200
+ inertia.velocity = inertia.velocity.map((d, i) => {
201
+ const deltaPos = position[i] - inertia.position[i];
202
+ const deltaTime2 = time - inertia.time;
203
+ return 1e3 * (1 - decay) * deltaPos / deltaTime2 + d * decay;
204
+ });
205
+ inertia.velocity = opt.axis([
206
+ 0,
207
+ 0
208
+ ], inertia.velocity);
209
+ inertia.time = time;
210
+ inertia.position = position;
211
+ opt.move && opt.move.call(this, position);
212
+ },
213
+ end: function(ev) {
214
+ this.classList.remove("dragging", "inertia");
215
+ const v = inertia.velocity;
216
+ if (v[0] * v[0] + v[1] * v[1] < 100) {
217
+ inertia.timer.stop();
218
+ return opt.stop && opt.stop();
219
+ }
220
+ const time = performance.now();
221
+ const deltaTime = time - inertia.time;
222
+ if (opt.hold === void 0) {
223
+ opt.hold = 100;
224
+ }
225
+ if (deltaTime >= opt.hold) {
226
+ inertia.timer.stop();
227
+ return opt.stop && opt.stop();
228
+ }
229
+ this.classList.add("inertia");
230
+ opt.end && opt.end();
231
+ const self = this;
232
+ inertia.timer.restart((e) => {
233
+ inertia.t = limit * (1 - Math.exp(-B * e / A));
234
+ opt.render && opt.render(inertia.t);
235
+ if (inertia.t > 1) {
236
+ inertia.timer.stop();
237
+ self.classList.remove("inertia");
238
+ inertia.velocity = [
239
+ 0,
240
+ 0
241
+ ];
242
+ inertia.t = 1;
243
+ opt.finish && opt.finish();
244
+ }
245
+ });
246
+ }
247
+ };
248
+ inertia.timer.stop();
249
+ return inertia;
250
+ }
251
+
252
+ // src/util/path.ts
253
+ import { geoCircle as d3GeoCircle } from "d3";
254
+ var positionToRotation = ([lng, lat], tilt = 0) => [
255
+ -lng,
256
+ tilt - lat,
257
+ 0
258
+ ];
259
+ var geoToPosition = ({ lat, lng }) => [
260
+ lng,
261
+ lat
262
+ ];
263
+ var geoPoint = (point) => ({
264
+ type: "Point",
265
+ coordinates: geoToPosition(point)
266
+ });
267
+ var geoCircle = ({ lat, lng }, radius) => d3GeoCircle().radius(radius).center([
268
+ lng,
269
+ lat
270
+ ])();
271
+ var geoLine = (p1, p2) => ({
272
+ type: "LineString",
273
+ coordinates: [
274
+ [
275
+ p1.lng,
276
+ p1.lat
277
+ ],
278
+ [
279
+ p2.lng,
280
+ p2.lat
281
+ ]
282
+ ]
283
+ });
284
+ var closestPoint = (points, target) => {
285
+ if (points.length === 0) {
286
+ return target;
287
+ }
288
+ let closestPoint2 = points[0];
289
+ let minDistance = getDistance(points[0], target);
290
+ for (const point of points) {
291
+ const distance = getDistance(point, target);
292
+ if (distance < minDistance) {
293
+ minDistance = distance;
294
+ closestPoint2 = point;
295
+ }
296
+ }
297
+ return closestPoint2;
298
+ };
299
+ var getDistance = (point1, point2) => {
300
+ const dx = point1[0] - point2[0];
301
+ const dy = point1[1] - point2[1];
302
+ return Math.sqrt(dx * dx + dy * dy);
303
+ };
304
+
305
+ // src/util/render.ts
306
+ import { geoGraticule } from "d3";
307
+ import { feature, mesh } from "topojson-client";
308
+ var createLayers = (topology, features, styles) => {
309
+ const layers = [];
310
+ if (styles.water) {
311
+ layers.push({
312
+ styles: styles.water,
313
+ path: {
314
+ type: "Sphere"
315
+ }
316
+ });
317
+ }
318
+ if (styles.graticule) {
319
+ layers.push({
320
+ styles: styles.graticule,
321
+ path: geoGraticule().step([
322
+ 6,
323
+ 6
324
+ ])()
325
+ });
326
+ }
327
+ if (topology) {
328
+ if (topology.objects.land && styles.land) {
329
+ layers.push({
330
+ styles: styles.land,
331
+ path: feature(topology, topology.objects.land)
332
+ });
333
+ }
334
+ if (topology.objects.countries && styles.border) {
335
+ layers.push({
336
+ styles: styles.border,
337
+ path: mesh(topology, topology.objects.countries, (a, b) => a !== b)
338
+ });
339
+ }
340
+ if (topology.objects.dots && styles.dots) {
341
+ layers.push({
342
+ styles: styles.dots,
343
+ path: topology.objects.dots
344
+ });
345
+ }
346
+ }
347
+ if (features) {
348
+ const { points, lines } = features;
349
+ if (points && styles.point) {
350
+ layers.push({
351
+ styles: styles.point,
352
+ path: {
353
+ type: "GeometryCollection",
354
+ geometries: points.map((point) => geoPoint(point))
355
+ }
356
+ });
357
+ }
358
+ if (lines && styles.line) {
359
+ layers.push({
360
+ styles: styles.line,
361
+ path: {
362
+ type: "GeometryCollection",
363
+ geometries: lines.map(({ source, target }) => geoLine(source, target))
364
+ }
365
+ });
366
+ }
367
+ }
368
+ return layers;
369
+ };
370
+ var renderLayers = (generator, layers = [], scale, styles) => {
371
+ const context = generator.context();
372
+ const { canvas: { width, height } } = context;
373
+ context.reset();
374
+ if (styles.background) {
375
+ context.fillStyle = styles.background.fillStyle;
376
+ context.fillRect(0, 0, width, height);
377
+ } else {
378
+ context.clearRect(0, 0, width, height);
379
+ }
380
+ layers.forEach(({ path, styles: styles2 }) => {
381
+ context.save();
382
+ let fill = false;
383
+ let stroke = false;
384
+ if (styles2) {
385
+ Object.entries(styles2).forEach(([key, value]) => {
386
+ if (key === "pointRadius") {
387
+ generator.pointRadius(value * scale);
388
+ } else {
389
+ context[key] = value;
390
+ fill ||= key === "fillStyle";
391
+ stroke ||= key === "strokeStyle";
392
+ }
393
+ });
394
+ }
395
+ context.beginPath();
396
+ generator(path);
397
+ fill && context.fill();
398
+ stroke && context.stroke();
399
+ context.restore();
400
+ });
401
+ return context;
402
+ };
403
+
404
+ // src/hooks/useDrag.ts
405
+ var useDrag = (controller, options = {}) => {
406
+ createEffect2(() => {
407
+ const canvas = controller?.canvas;
408
+ if (!canvas || options.disabled) {
409
+ return;
410
+ }
411
+ geoInertiaDrag(select2(canvas), () => {
412
+ controller.setRotation(controller.projection.rotate());
413
+ options.onUpdate?.({
414
+ type: "move",
415
+ controller
416
+ });
417
+ }, controller.projection, {
418
+ xAxis: options.xAxis,
419
+ time: 3e3,
420
+ start: () => options.onUpdate?.({
421
+ type: "start",
422
+ controller
423
+ }),
424
+ finish: () => options.onUpdate?.({
425
+ type: "end",
426
+ controller
427
+ })
428
+ });
429
+ onCleanup(() => {
430
+ cancelDrag(select2(canvas));
431
+ });
432
+ });
433
+ };
434
+ var cancelDrag = (node) => node.on(".drag", null);
435
+
436
+ // src/hooks/useGlobeZoomHandler.ts
437
+ var ZOOM_FACTOR = 0.1;
438
+ var useGlobeZoomHandler = (controller) => {
439
+ return (event) => {
440
+ if (!controller) {
441
+ return;
442
+ }
443
+ switch (event) {
444
+ case "zoom-in": {
445
+ controller.setZoom((zoom) => {
446
+ return zoom * (1 + ZOOM_FACTOR);
447
+ });
448
+ break;
449
+ }
450
+ case "zoom-out": {
451
+ controller.setZoom((zoom) => {
452
+ return zoom * (1 - ZOOM_FACTOR);
453
+ });
454
+ break;
455
+ }
456
+ }
457
+ };
458
+ };
459
+
460
+ // src/hooks/useMapZoomHandler.ts
461
+ var useMapZoomHandler = (controller) => {
462
+ return (event) => {
463
+ if (!controller) {
464
+ return;
465
+ }
466
+ switch (event) {
467
+ case "zoom-in": {
468
+ controller.setZoom((scale) => scale + 1);
469
+ break;
470
+ }
471
+ case "zoom-out": {
472
+ controller.setZoom((scale) => scale - 1);
473
+ break;
474
+ }
475
+ }
476
+ };
477
+ };
478
+
479
+ // src/hooks/useSpinner.ts
480
+ import { timer as d3Timer } from "d3";
481
+ import { createEffect as createEffect3, createSignal as createSignal2, onCleanup as onCleanup2 } from "solid-js";
482
+ var useSpinner = (controller, options = {}) => {
483
+ const [running, setRunning] = createSignal2(false);
484
+ createEffect3(() => {
485
+ let timer3;
486
+ const start = () => {
487
+ const delta = options.delta ?? [
488
+ 1e-3,
489
+ 0,
490
+ 0
491
+ ];
492
+ let t = 0;
493
+ let lastRotation = controller.projection.rotate();
494
+ timer3 = d3Timer((elapsed) => {
495
+ const dt = elapsed - t;
496
+ t = elapsed;
497
+ const rotation = [
498
+ lastRotation[0] + delta[0] * dt,
499
+ lastRotation[1] + delta[1] * dt,
500
+ lastRotation[2] + delta[2] * dt
501
+ ];
502
+ lastRotation = rotation;
503
+ controller.setRotation(rotation);
504
+ });
505
+ };
506
+ const stop = () => {
507
+ if (timer3) {
508
+ timer3.stop();
509
+ timer3 = void 0;
510
+ }
511
+ };
512
+ if (controller && running()) {
513
+ start();
514
+ } else {
515
+ stop();
516
+ }
517
+ onCleanup2(() => stop());
518
+ });
519
+ return {
520
+ start: () => {
521
+ if (!options.disabled) {
522
+ setRunning(true);
523
+ }
524
+ },
525
+ stop: () => setRunning(false)
526
+ };
527
+ };
528
+
529
+ // src/hooks/useTour.ts
530
+ import { selection as d3Selection, geoDistance, geoInterpolate, geoPath } from "d3";
531
+ import { createEffect as createEffect4, createSignal as createSignal3, onCleanup as onCleanup3 } from "solid-js";
532
+ import versor2 from "versor";
533
+ var TRANSITION_NAME = "globe-tour";
534
+ var defaultDuration = 1500;
535
+ var useTour = (controller, points, options = {}) => {
536
+ const selection = d3Selection();
537
+ const [running, setRunning] = createSignal3(options.running ?? false);
538
+ createEffect4(() => {
539
+ if (!running()) {
540
+ selection.interrupt(TRANSITION_NAME);
541
+ return;
542
+ }
543
+ let t;
544
+ if (controller && running()) {
545
+ t = setTimeout(async () => {
546
+ const { canvas, projection, setRotation } = controller;
547
+ const context = canvas.getContext("2d", {
548
+ alpha: false
549
+ });
550
+ const path = geoPath(projection, context).pointRadius(2);
551
+ const tilt = options.tilt ?? 0;
552
+ let last;
553
+ try {
554
+ const p = [
555
+ ...points ?? []
556
+ ];
557
+ if (options.loop) {
558
+ p.push(p[0]);
559
+ }
560
+ for (const next of p) {
561
+ if (!running()) {
562
+ break;
563
+ }
564
+ const p1 = last ? geoToPosition(last) : void 0;
565
+ const p2 = geoToPosition(next);
566
+ const ip = geoInterpolate(p1 || p2, p2);
567
+ const distance = geoDistance(p1 || p2, p2);
568
+ const r1 = p1 ? positionToRotation(p1, tilt) : controller.projection.rotate();
569
+ const r2 = positionToRotation(p2, tilt);
570
+ const iv = versor2.interpolate(r1, r2);
571
+ const transition2 = selection.transition(TRANSITION_NAME).duration(Math.max(options.duration ?? defaultDuration, distance * 2e3)).tween("render", () => (t2) => {
572
+ const t1 = Math.max(0, Math.min(1, t2 * 2 - 1));
573
+ const t22 = Math.min(1, t2 * 2);
574
+ context.save();
575
+ {
576
+ context.beginPath();
577
+ context.strokeStyle = options?.styles?.arc?.strokeStyle ?? "yellow";
578
+ context.lineWidth = (options?.styles?.arc?.lineWidth ?? 1.5) * (controller?.zoom ?? 1);
579
+ context.setLineDash(options?.styles?.arc?.lineDash ?? []);
580
+ path({
581
+ type: "LineString",
582
+ coordinates: [
583
+ ip(t1),
584
+ ip(t22)
585
+ ]
586
+ });
587
+ context.stroke();
588
+ context.beginPath();
589
+ context.fillStyle = options?.styles?.cursor?.fillStyle ?? "orange";
590
+ path.pointRadius((options?.styles?.cursor?.pointRadius ?? 2) * (controller?.zoom ?? 1));
591
+ path({
592
+ type: "Point",
593
+ coordinates: ip(t22)
594
+ });
595
+ context.fill();
596
+ }
597
+ context.restore();
598
+ projection.rotate(iv(t2));
599
+ setRotation(projection.rotate());
600
+ });
601
+ await transition2.end();
602
+ last = next;
603
+ }
604
+ } catch {
605
+ } finally {
606
+ setRunning(false);
607
+ }
608
+ });
609
+ onCleanup3(() => {
610
+ clearTimeout(t);
611
+ selection.interrupt(TRANSITION_NAME);
612
+ });
613
+ }
614
+ });
615
+ return {
616
+ running,
617
+ setRunning
618
+ };
619
+ };
620
+
621
+ // src/components/Toolbar/Controls.tsx
622
+ import { jsx as _jsx2, jsxs as _jsxs } from "solid-js/jsx-runtime";
623
+ var controlPositions = {
624
+ topleft: "top-2 left-2",
625
+ topright: "top-2 right-2",
626
+ bottomleft: "bottom-2 left-2",
627
+ bottomright: "bottom-2 right-2"
628
+ };
629
+ var ZoomControls = (props) => {
630
+ return /* @__PURE__ */ _jsxs("div", {
631
+ class: `flex flex-row gap-2 ${props.class ?? ""}`,
632
+ children: [
633
+ /* @__PURE__ */ _jsx2("button", {
634
+ type: "button",
635
+ class: "dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center",
636
+ onClick: () => props.onAction?.("zoom-in"),
637
+ title: "Zoom in",
638
+ children: /* @__PURE__ */ _jsx2("span", {
639
+ class: "text-xl",
640
+ children: "+"
641
+ })
642
+ }),
643
+ /* @__PURE__ */ _jsx2("button", {
644
+ type: "button",
645
+ class: "dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center",
646
+ onClick: () => props.onAction?.("zoom-out"),
647
+ title: "Zoom out",
648
+ children: /* @__PURE__ */ _jsx2("span", {
649
+ class: "text-xl",
650
+ children: "\u2212"
651
+ })
652
+ })
653
+ ]
654
+ });
655
+ };
656
+ var ActionControls = (props) => {
657
+ return /* @__PURE__ */ _jsxs("div", {
658
+ class: `flex flex-row gap-2 ${props.class ?? ""}`,
659
+ children: [
660
+ /* @__PURE__ */ _jsx2("button", {
661
+ type: "button",
662
+ class: "dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center",
663
+ onClick: () => props.onAction?.("start"),
664
+ title: "Start",
665
+ children: /* @__PURE__ */ _jsx2("span", {
666
+ class: "text-xl",
667
+ children: "\u25B6"
668
+ })
669
+ }),
670
+ /* @__PURE__ */ _jsx2("button", {
671
+ type: "button",
672
+ class: "dx-button dx-focus-ring w-10 h-10 min-h-[2.5rem] px-3 rounded-xs flex items-center justify-center",
673
+ onClick: () => props.onAction?.("toggle"),
674
+ title: "Toggle",
675
+ children: /* @__PURE__ */ _jsx2("span", {
676
+ class: "text-xl",
677
+ children: "\u{1F30D}"
678
+ })
679
+ })
680
+ ]
681
+ });
682
+ };
683
+
684
+ // src/components/Globe/Globe.tsx
685
+ var defaultStyles = {
686
+ light: {
687
+ background: {
688
+ fillStyle: "#EEE"
689
+ },
690
+ water: {
691
+ fillStyle: "#555"
692
+ },
693
+ land: {
694
+ fillStyle: "#999"
695
+ },
696
+ line: {
697
+ strokeStyle: "darkred"
698
+ },
699
+ point: {
700
+ fillStyle: "#111111",
701
+ strokeStyle: "#111111",
702
+ strokeWidth: 1,
703
+ pointRadius: 0.5
704
+ }
705
+ },
706
+ dark: {
707
+ background: {
708
+ fillStyle: "#111111"
709
+ },
710
+ water: {
711
+ fillStyle: "#123E6A"
712
+ },
713
+ land: {
714
+ fillStyle: "#032153"
715
+ },
716
+ line: {
717
+ strokeStyle: "#111111"
718
+ },
719
+ point: {
720
+ fillStyle: "#111111",
721
+ strokeStyle: "#111111",
722
+ strokeWidth: 1,
723
+ pointRadius: 0.5
724
+ }
725
+ }
726
+ };
727
+ var projectionMap = {
728
+ orthographic: geoOrthographic,
729
+ mercator: geoMercator,
730
+ "transverse-mercator": geoTransverseMercator
731
+ };
732
+ var getProjection = (type = "orthographic") => {
733
+ if (typeof type === "string") {
734
+ const constructor = projectionMap[type] ?? geoOrthographic;
735
+ return constructor();
736
+ }
737
+ return type ?? geoOrthographic();
738
+ };
739
+ var GlobeRoot = (props) => {
740
+ let containerRef;
741
+ const [size, setSize] = createSignal4({
742
+ width: 0,
743
+ height: 0
744
+ });
745
+ createResizeObserver(() => containerRef, ({ width, height }) => {
746
+ setSize({
747
+ width,
748
+ height
749
+ });
750
+ });
751
+ return /* @__PURE__ */ _jsx3(GlobeContextProvider, {
752
+ size: size(),
753
+ ...props,
754
+ children: /* @__PURE__ */ _jsx3("div", {
755
+ ref: containerRef,
756
+ class: mx("relative dx-container"),
757
+ ...props,
758
+ children: props.children
759
+ })
760
+ });
761
+ };
762
+ var GlobeCanvas = (props) => {
763
+ const themeMode = "dark";
764
+ const styles = createMemo(() => props.styles ?? defaultStyles[themeMode]);
765
+ const [canvas, setCanvas] = createSignal4(null);
766
+ const projection = createMemo(() => getProjection(props.projection));
767
+ const layers = createMemo(() => {
768
+ return timer(() => createLayers(props.topology, props.features, styles()));
769
+ });
770
+ const { size, center, zoom, translation, rotation, setCenter, setZoom, setTranslation, setRotation } = useGlobeContext();
771
+ let zoomValue = zoom();
772
+ let zooming = false;
773
+ createEffect5(() => {
774
+ });
775
+ createEffect5(() => {
776
+ const c = center();
777
+ if (c) {
778
+ setZoom(1);
779
+ setRotation(positionToRotation(geoToPosition(c)));
780
+ }
781
+ });
782
+ createEffect5(() => {
783
+ const canvasEl = canvas();
784
+ if (canvasEl && props.ref) {
785
+ const controller = {
786
+ canvas: canvasEl,
787
+ projection: projection(),
788
+ get zoom() {
789
+ return zoomValue;
790
+ },
791
+ translation,
792
+ rotation,
793
+ setZoom: (state) => {
794
+ if (typeof state === "function") {
795
+ const is = interpolateNumber(zoomValue, state(zoomValue));
796
+ transition().ease(zooming ? easeLinear : easeSinOut).duration(200).tween("scale", () => (t) => {
797
+ const newZoom = is(t);
798
+ zoomValue = newZoom;
799
+ setZoom(newZoom);
800
+ }).on("end", () => {
801
+ zooming = false;
802
+ });
803
+ } else {
804
+ zoomValue = state;
805
+ setZoom(state);
806
+ }
807
+ },
808
+ setTranslation,
809
+ setRotation
810
+ };
811
+ props.ref(controller);
812
+ }
813
+ });
814
+ const generator = createMemo(() => {
815
+ const canvasEl = canvas();
816
+ const proj = projection();
817
+ return canvasEl && proj && geoPath2(proj, canvasEl.getContext("2d", {
818
+ alpha: false
819
+ }));
820
+ });
821
+ createEffect5(() => {
822
+ const canvasEl = canvas();
823
+ const proj = projection();
824
+ const gen = generator();
825
+ const z = zoom();
826
+ const t = translation();
827
+ const r = rotation();
828
+ const s = size();
829
+ if (canvasEl && proj && gen) {
830
+ timer(() => {
831
+ proj.scale(Math.min(s.width, s.height) / 2 * z).translate([
832
+ s.width / 2 + (t?.x ?? 0),
833
+ s.height / 2 + (t?.y ?? 0)
834
+ ]).rotate(r ?? [
835
+ 0,
836
+ 0,
837
+ 0
838
+ ]);
839
+ renderLayers(gen, layers(), z, styles());
840
+ });
841
+ }
842
+ });
843
+ return /* @__PURE__ */ _jsx3(Show, {
844
+ when: size().width > 0 && size().height > 0,
845
+ children: /* @__PURE__ */ _jsx3("canvas", {
846
+ ref: setCanvas,
847
+ width: size().width,
848
+ height: size().height
849
+ })
850
+ });
851
+ };
852
+ var GlobeDebug = (props) => {
853
+ const { size, zoom, translation, rotation } = useGlobeContext();
854
+ return /* @__PURE__ */ _jsx3("div", {
855
+ class: `z-10 absolute w-96 p-2 overflow-hidden border border-green-700 rounded-sm ${controlPositions[props.position ?? "topleft"]}`,
856
+ children: /* @__PURE__ */ _jsx3("pre", {
857
+ class: "font-mono text-xs text-green-700",
858
+ children: JSON.stringify({
859
+ size,
860
+ zoom: zoom(),
861
+ translation: translation(),
862
+ rotation: rotation()
863
+ }, null, 2)
864
+ })
865
+ });
866
+ };
867
+ var GlobePanel = (props) => {
868
+ return /* @__PURE__ */ _jsx3("div", {
869
+ class: `z-10 absolute overflow-hidden ${controlPositions[props.position ?? "topleft"]} ${props.class ?? ""}`,
870
+ children: props.children
871
+ });
872
+ };
873
+ var CustomControl = (props) => {
874
+ return /* @__PURE__ */ _jsx3("div", {
875
+ class: `z-10 absolute overflow-hidden ${controlPositions[props.position]}`,
876
+ children: props.children
877
+ });
878
+ };
879
+ var GlobeZoom = (props) => /* @__PURE__ */ _jsx3(CustomControl, {
880
+ position: props.position ?? "bottomleft",
881
+ children: /* @__PURE__ */ _jsx3(ZoomControls, {
882
+ onAction: props.onAction
883
+ })
884
+ });
885
+ var GlobeAction = (props) => /* @__PURE__ */ _jsx3(CustomControl, {
886
+ position: props.position ?? "bottomright",
887
+ children: /* @__PURE__ */ _jsx3(ActionControls, {
888
+ onAction: props.onAction
889
+ })
890
+ });
891
+ var Globe = {
892
+ Root: GlobeRoot,
893
+ Canvas: GlobeCanvas,
894
+ Zoom: GlobeZoom,
895
+ Action: GlobeAction,
896
+ Debug: GlobeDebug,
897
+ Panel: GlobePanel
898
+ };
899
+
900
+ // src/components/Map/Map.tsx
901
+ import { jsx as _jsx4, jsxs as _jsxs2 } from "solid-js/jsx-runtime";
902
+ import "leaflet/dist/leaflet.css";
903
+ import L, { latLngBounds } from "leaflet";
904
+ import { Show as Show2, createContext as createContext2, createEffect as createEffect6, createSignal as createSignal5, onCleanup as onCleanup4, onMount, useContext as useContext2 } from "solid-js";
905
+ var defaults2 = {
906
+ center: {
907
+ lat: 51,
908
+ lng: 0
909
+ },
910
+ zoom: 4
911
+ };
912
+ var MapContext = createContext2();
913
+ var useMapContext = (displayName) => {
914
+ const context = useContext2(MapContext);
915
+ if (!context) {
916
+ throw new Error(`${displayName} must be used within Map.Root`);
917
+ }
918
+ return context;
919
+ };
920
+ var MapRoot = (props) => {
921
+ let mapContainer;
922
+ const [map, setMap] = createSignal5(null);
923
+ const [attention, setAttention] = createSignal5(false);
924
+ onMount(() => {
925
+ if (!mapContainer) {
926
+ return;
927
+ }
928
+ const leafletMap = L.map(mapContainer, {
929
+ center: props.center ?? defaults2.center,
930
+ zoom: props.zoom ?? defaults2.zoom,
931
+ attributionControl: false,
932
+ zoomControl: false,
933
+ scrollWheelZoom: props.scrollWheelZoom ?? true,
934
+ doubleClickZoom: props.doubleClickZoom ?? true,
935
+ touchZoom: props.touchZoom ?? true
936
+ });
937
+ setMap(leafletMap);
938
+ if (props.ref) {
939
+ props.ref({
940
+ setCenter: (center, zoom) => {
941
+ leafletMap.setView(center, zoom);
942
+ },
943
+ setZoom: (cb) => {
944
+ leafletMap.setZoom(cb(leafletMap.getZoom()));
945
+ }
946
+ });
947
+ }
948
+ onCleanup4(() => {
949
+ leafletMap.remove();
950
+ });
951
+ });
952
+ createEffect6(() => {
953
+ const leafletMap = map();
954
+ if (!leafletMap) {
955
+ return;
956
+ }
957
+ if (attention()) {
958
+ leafletMap.scrollWheelZoom.enable();
959
+ } else {
960
+ leafletMap.scrollWheelZoom.disable();
961
+ }
962
+ });
963
+ return /* @__PURE__ */ _jsxs2(MapContext.Provider, {
964
+ value: {
965
+ map,
966
+ attention,
967
+ setAttention,
968
+ onChange: props.onChange
969
+ },
970
+ children: [
971
+ /* @__PURE__ */ _jsx4("div", {
972
+ ref: mapContainer,
973
+ class: `group relative grid h-full w-full bg-gray-100 dark:bg-gray-900 ${props.class ?? ""}`,
974
+ style: {
975
+ "z-index": "0"
976
+ }
977
+ }),
978
+ /* @__PURE__ */ _jsx4(Show2, {
979
+ when: map(),
980
+ children: props.children
981
+ })
982
+ ]
983
+ });
984
+ };
985
+ var MapTiles = () => {
986
+ const { map, onChange, attention } = useMapContext(MapTiles.name);
987
+ let tileLayer = null;
988
+ createEffect6(() => {
989
+ const leafletMap = map();
990
+ if (!leafletMap) {
991
+ return;
992
+ }
993
+ const att = attention();
994
+ tileLayer = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
995
+ detectRetina: true,
996
+ keepBuffer: 4,
997
+ className: `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`
998
+ });
999
+ tileLayer.addTo(leafletMap);
1000
+ leafletMap.on("zoomstart", (ev) => {
1001
+ onChange?.({
1002
+ center: ev.target.getCenter(),
1003
+ zoom: ev.target.getZoom()
1004
+ });
1005
+ });
1006
+ onCleanup4(() => {
1007
+ if (tileLayer) {
1008
+ tileLayer.remove();
1009
+ tileLayer = null;
1010
+ }
1011
+ });
1012
+ });
1013
+ createEffect6(() => {
1014
+ const att = attention();
1015
+ if (tileLayer) {
1016
+ const container = tileLayer.getContainer();
1017
+ if (container) {
1018
+ container.className = `dark:grayscale dark:invert ${att ? "" : "opacity-80"}`;
1019
+ }
1020
+ }
1021
+ });
1022
+ return null;
1023
+ };
1024
+ var MapMarkers = (props) => {
1025
+ const { map } = useMapContext(MapMarkers.name);
1026
+ const leafletMarkers = [];
1027
+ let lastMarkerIds = /* @__PURE__ */ new Set();
1028
+ onCleanup4(() => {
1029
+ leafletMarkers.forEach((marker) => marker.remove());
1030
+ leafletMarkers.length = 0;
1031
+ });
1032
+ createEffect6(() => {
1033
+ const leafletMap = map();
1034
+ if (!leafletMap) {
1035
+ return;
1036
+ }
1037
+ const markerList = props.markers?.() ?? [];
1038
+ const currentIds = new Set(markerList.map((m) => m.id));
1039
+ if (currentIds.size === lastMarkerIds.size && [
1040
+ ...currentIds
1041
+ ].every((id) => lastMarkerIds.has(id)) && leafletMarkers.length > 0) {
1042
+ return;
1043
+ }
1044
+ leafletMarkers.forEach((marker) => marker.remove());
1045
+ leafletMarkers.length = 0;
1046
+ lastMarkerIds = currentIds;
1047
+ if (markerList.length > 0) {
1048
+ const bounds = latLngBounds(markerList.map((marker) => marker.location));
1049
+ leafletMap.fitBounds(bounds);
1050
+ markerList.forEach(({ title, location }) => {
1051
+ const marker = L.marker(location, {
1052
+ icon: new L.Icon({
1053
+ iconUrl: "https://dxos.network/marker-icon.png",
1054
+ iconRetinaUrl: "https://dxos.network/marker-icon-2x.png",
1055
+ shadowUrl: "https://dxos.network/marker-shadow.png",
1056
+ iconSize: [
1057
+ 25,
1058
+ 41
1059
+ ],
1060
+ iconAnchor: [
1061
+ 12,
1062
+ 41
1063
+ ],
1064
+ popupAnchor: [
1065
+ 1,
1066
+ -34
1067
+ ],
1068
+ shadowSize: [
1069
+ 41,
1070
+ 41
1071
+ ]
1072
+ })
1073
+ });
1074
+ if (title) {
1075
+ marker.bindPopup(title);
1076
+ }
1077
+ marker.addTo(leafletMap);
1078
+ leafletMarkers.push(marker);
1079
+ });
1080
+ } else {
1081
+ leafletMap.setView(defaults2.center, defaults2.zoom);
1082
+ }
1083
+ });
1084
+ return null;
1085
+ };
1086
+ var CustomControl2 = (props) => {
1087
+ const { map: mapAccessor } = useMapContext(CustomControl2.name);
1088
+ let controlContainer;
1089
+ createEffect6(() => {
1090
+ const map = mapAccessor();
1091
+ if (!map || !controlContainer) {
1092
+ return;
1093
+ }
1094
+ const Control = L.Control.extend({
1095
+ onAdd: () => {
1096
+ const container = L.DomUtil.create("div", `${controlPositions[props.position]} m-0!`);
1097
+ L.DomEvent.disableClickPropagation(container);
1098
+ L.DomEvent.disableScrollPropagation(container);
1099
+ if (controlContainer) {
1100
+ container.appendChild(controlContainer);
1101
+ }
1102
+ return container;
1103
+ }
1104
+ });
1105
+ const control = new Control({
1106
+ position: props.position
1107
+ });
1108
+ control.addTo(map);
1109
+ onCleanup4(() => {
1110
+ control.remove();
1111
+ });
1112
+ });
1113
+ return /* @__PURE__ */ _jsx4("div", {
1114
+ ref: controlContainer,
1115
+ style: {
1116
+ display: "contents"
1117
+ },
1118
+ children: props.children
1119
+ });
1120
+ };
1121
+ var MapZoom = (props) => /* @__PURE__ */ _jsx4(CustomControl2, {
1122
+ position: props.position ?? "bottomleft",
1123
+ children: /* @__PURE__ */ _jsx4(ZoomControls, {
1124
+ onAction: props.onAction
1125
+ })
1126
+ });
1127
+ var MapAction = (props) => /* @__PURE__ */ _jsx4(CustomControl2, {
1128
+ position: props.position ?? "bottomright",
1129
+ children: /* @__PURE__ */ _jsx4(ActionControls, {
1130
+ onAction: props.onAction
1131
+ })
1132
+ });
1133
+ var Map = {
1134
+ Root: MapRoot,
1135
+ Tiles: MapTiles,
1136
+ Markers: MapMarkers,
1137
+ Zoom: MapZoom,
1138
+ Action: MapAction
1139
+ };
1140
+ export {
1141
+ ActionControls,
1142
+ Globe,
1143
+ GlobeContextProvider,
1144
+ Map,
1145
+ ZoomControls,
1146
+ closestPoint,
1147
+ controlPositions,
1148
+ createLayers,
1149
+ geoCircle,
1150
+ geoInertiaDrag,
1151
+ geoLine,
1152
+ geoPoint,
1153
+ geoToPosition,
1154
+ getDistance,
1155
+ loadTopology,
1156
+ positionToRotation,
1157
+ renderLayers,
1158
+ restrictAxis,
1159
+ timer,
1160
+ useDrag,
1161
+ useGlobeContext,
1162
+ useGlobeZoomHandler,
1163
+ useMapZoomHandler,
1164
+ useSpinner,
1165
+ useTour
1166
+ };
1167
+ //# sourceMappingURL=index.mjs.map