@dxos/solid-ui-geo 0.10.0 → 0.11.1

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