@wodira/browser 1.1.0 → 1.2.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 (43) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/README.md +106 -1
  3. package/dist/index.cjs +36 -0
  4. package/dist/index.d.ts +90 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +36 -0
  7. package/dist/types.d.ts +3 -0
  8. package/dist/types.d.ts.map +1 -1
  9. package/dist/ui/boxes/cdn.js +15 -15
  10. package/dist/ui/components.d.ts +18 -1
  11. package/dist/ui/components.d.ts.map +1 -1
  12. package/dist/ui/events.d.ts +1 -1
  13. package/dist/ui/events.d.ts.map +1 -1
  14. package/dist/ui/i18n.d.ts +1 -1
  15. package/dist/ui/i18n.d.ts.map +1 -1
  16. package/dist/ui/{index-tfej862z.js → index-1zshfsk6.js} +45 -1563
  17. package/dist/ui/index-3qe91gk8.js +1625 -0
  18. package/dist/ui/index-bjb0t7yn.js +1624 -0
  19. package/dist/ui/index.d.ts +1 -0
  20. package/dist/ui/index.d.ts.map +1 -1
  21. package/dist/ui/index.js +290 -125
  22. package/dist/ui/map-view-rn3jgtqn.js +28737 -0
  23. package/dist/ui/maplibre-gl-worker.mjs +10 -0
  24. package/dist/ui/route-3d/cdn.d.ts +2 -0
  25. package/dist/ui/route-3d/cdn.d.ts.map +1 -0
  26. package/dist/ui/route-3d/cdn.js +1527 -0
  27. package/dist/ui/route-3d/gpx.d.ts +14 -0
  28. package/dist/ui/route-3d/gpx.d.ts.map +1 -0
  29. package/dist/ui/route-3d/index.d.ts +12 -0
  30. package/dist/ui/route-3d/index.d.ts.map +1 -0
  31. package/dist/ui/route-3d/index.js +16 -0
  32. package/dist/ui/route-3d/map-view.d.ts +73 -0
  33. package/dist/ui/route-3d/map-view.d.ts.map +1 -0
  34. package/dist/ui/route-3d/maplibre-gl-worker.mjs +10 -0
  35. package/dist/ui/route-3d/route-3d.d.ts +168 -0
  36. package/dist/ui/route-3d/route-3d.d.ts.map +1 -0
  37. package/dist/ui/route-3d/route-geo.d.ts +77 -0
  38. package/dist/ui/route-3d/route-geo.d.ts.map +1 -0
  39. package/dist/ui/shirt-sponsors/cdn.js +29 -27
  40. package/dist/ui/shirt-sponsors/index.js +5 -3
  41. package/dist/ui/shirt-sponsors/shirt-auction.d.ts +19 -0
  42. package/dist/ui/shirt-sponsors/shirt-auction.d.ts.map +1 -1
  43. package/package.json +15 -6
@@ -0,0 +1,1625 @@
1
+ import {
2
+ __preload,
3
+ __chunks,
4
+ css,
5
+ html,
6
+ svg,
7
+ noChange,
8
+ nothing,
9
+ LitElement,
10
+ PartType,
11
+ directive,
12
+ Directive,
13
+ createWodiraBrowserClient
14
+ } from "./index-1zshfsk6.js";
15
+
16
+ // ../../node_modules/.pnpm/lit-html@3.3.3/node_modules/lit-html/development/directives/style-map.js
17
+ var important = "important";
18
+ var importantFlag = " !" + important;
19
+ var flagTrim = 0 - importantFlag.length;
20
+
21
+ class StyleMapDirective extends Directive {
22
+ constructor(partInfo) {
23
+ super(partInfo);
24
+ if (partInfo.type !== PartType.ATTRIBUTE || partInfo.name !== "style" || partInfo.strings?.length > 2) {
25
+ throw new Error("The `styleMap` directive must be used in the `style` attribute " + "and must be the only part in the attribute.");
26
+ }
27
+ }
28
+ render(styleInfo) {
29
+ return Object.keys(styleInfo).reduce((style, prop) => {
30
+ const value = styleInfo[prop];
31
+ if (value == null) {
32
+ return style;
33
+ }
34
+ prop = prop.includes("-") ? prop : prop.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, "-$&").toLowerCase();
35
+ return style + `${prop}:${value};`;
36
+ }, "");
37
+ }
38
+ update(part, [styleInfo]) {
39
+ const { style } = part.element;
40
+ if (this._previousStyleProperties === undefined) {
41
+ this._previousStyleProperties = new Set(Object.keys(styleInfo));
42
+ return this.render(styleInfo);
43
+ }
44
+ for (const name of this._previousStyleProperties) {
45
+ if (styleInfo[name] == null) {
46
+ this._previousStyleProperties.delete(name);
47
+ if (name.includes("-")) {
48
+ style.removeProperty(name);
49
+ } else {
50
+ style[name] = null;
51
+ }
52
+ }
53
+ }
54
+ for (const name in styleInfo) {
55
+ const value = styleInfo[name];
56
+ if (value != null) {
57
+ this._previousStyleProperties.add(name);
58
+ const isImportant = typeof value === "string" && value.endsWith(importantFlag);
59
+ if (name.includes("-") || isImportant) {
60
+ style.setProperty(name, isImportant ? value.slice(0, flagTrim) : value, isImportant ? important : "");
61
+ } else {
62
+ style[name] = value;
63
+ }
64
+ }
65
+ }
66
+ return noChange;
67
+ }
68
+ }
69
+ var styleMap = directive(StyleMapDirective);
70
+ // src/ui/route-3d/gpx.ts
71
+ var MAX_POINTS = 50000;
72
+ function number(value) {
73
+ if (value === null || value === undefined || value.trim() === "")
74
+ return null;
75
+ const parsed = Number(value);
76
+ return Number.isFinite(parsed) ? parsed : null;
77
+ }
78
+ function elements(root, name) {
79
+ return Array.from(root.getElementsByTagName("*")).filter((element) => element.localName === name);
80
+ }
81
+ function childText(element, name) {
82
+ for (const child of Array.from(element.childNodes))
83
+ if (child.localName === name)
84
+ return child.textContent?.trim() || null;
85
+ return null;
86
+ }
87
+ function readPoint(element) {
88
+ const lat = number(element.getAttribute("lat"));
89
+ const lon = number(element.getAttribute("lon"));
90
+ if (lat === null || lon === null || Math.abs(lat) > 90 || Math.abs(lon) > 180)
91
+ return null;
92
+ const ele = number(childText(element, "ele"));
93
+ return ele === null ? { lat, lon } : { lat, lon, ele };
94
+ }
95
+ function waypointType(label) {
96
+ const text = label.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase();
97
+ if (/\b(start|salida|saida|partida|inicio)\b/.test(text))
98
+ return "START";
99
+ if (/\b(finish|meta|chegada|llegada|fin)\b/.test(text))
100
+ return "FINISH";
101
+ if (/(medic|first aid|botiquin|cruz roja|ambul)/.test(text))
102
+ return "MEDICAL";
103
+ if (/(food|comida|comer|alimento|restaurant)/.test(text))
104
+ return "FOOD";
105
+ if (/(aid|avituall|abastec|refresh|cp\d|checkpoint|control)/.test(text))
106
+ return "AID";
107
+ if (/(water|agua|agua|fuente|font|drink)/.test(text))
108
+ return "WATER";
109
+ if (/^(km|kilometr)/.test(text))
110
+ return "KM";
111
+ return "OTHER";
112
+ }
113
+ function parseGpx2(text) {
114
+ const document2 = new DOMParser().parseFromString(text, "application/xml");
115
+ const root = document2.documentElement;
116
+ if (!root || root.localName !== "gpx" || elements(document2, "parsererror").length)
117
+ throw new Error("Not a GPX document");
118
+ const collect = (name) => {
119
+ const points = [];
120
+ for (const element of elements(document2, name)) {
121
+ const point = readPoint(element);
122
+ if (point)
123
+ points.push(point);
124
+ if (points.length >= MAX_POINTS)
125
+ break;
126
+ }
127
+ return points;
128
+ };
129
+ let points = collect("trkpt");
130
+ if (points.length < 2)
131
+ points = collect("rtept");
132
+ const waypoints = [];
133
+ for (const element of elements(document2, "wpt")) {
134
+ const point = readPoint(element);
135
+ if (!point)
136
+ continue;
137
+ const name = childText(element, "name");
138
+ const label = [childText(element, "type"), childText(element, "sym"), name].filter(Boolean).join(" ");
139
+ waypoints.push({ ...point, type: waypointType(label), ...name ? { name } : {} });
140
+ }
141
+ const track = elements(document2, "trk")[0];
142
+ const meta = elements(document2, "metadata")[0];
143
+ const name = track && childText(track, "name") || meta && childText(meta, "name") || null;
144
+ return { name, points, waypoints };
145
+ }
146
+
147
+ // src/ui/route-3d/route-geo.ts
148
+ var EARTH_RADIUS_M = 6371008.8;
149
+ var ASCENT_THRESHOLD_M = 3;
150
+ var rad = (degrees) => degrees * Math.PI / 180;
151
+ function haversine(a, b) {
152
+ const dLat = rad(b.lat - a.lat);
153
+ const dLon = rad(b.lon - a.lon);
154
+ const h = Math.sin(dLat / 2) ** 2 + Math.cos(rad(a.lat)) * Math.cos(rad(b.lat)) * Math.sin(dLon / 2) ** 2;
155
+ return 2 * EARTH_RADIUS_M * Math.asin(Math.min(1, Math.sqrt(h)));
156
+ }
157
+ function measureRoute2(points) {
158
+ const distances = [];
159
+ const elevations = [];
160
+ let total = 0;
161
+ let ascent = 0;
162
+ let descent = 0;
163
+ let reference = null;
164
+ let min = null;
165
+ let max = null;
166
+ for (let index = 0;index < points.length; index++) {
167
+ const point = points[index];
168
+ if (index > 0)
169
+ total += haversine(points[index - 1], point);
170
+ distances.push(total);
171
+ const ele = typeof point.ele === "number" && Number.isFinite(point.ele) ? point.ele : null;
172
+ elevations.push(ele);
173
+ if (ele === null)
174
+ continue;
175
+ min = min === null ? ele : Math.min(min, ele);
176
+ max = max === null ? ele : Math.max(max, ele);
177
+ if (reference === null)
178
+ reference = ele;
179
+ else if (ele - reference >= ASCENT_THRESHOLD_M) {
180
+ ascent += ele - reference;
181
+ reference = ele;
182
+ } else if (reference - ele >= ASCENT_THRESHOLD_M) {
183
+ descent += reference - ele;
184
+ reference = ele;
185
+ }
186
+ }
187
+ return {
188
+ distances,
189
+ elevations,
190
+ distanceM: total,
191
+ ascentM: ascent,
192
+ descentM: descent,
193
+ minEleM: min,
194
+ maxEleM: max,
195
+ hasElevation: min !== null
196
+ };
197
+ }
198
+ function segmentAt(distances, distance) {
199
+ let low = 0;
200
+ let high = distances.length - 1;
201
+ while (low < high) {
202
+ const middle = low + high + 1 >> 1;
203
+ if (distances[middle] <= distance)
204
+ low = middle;
205
+ else
206
+ high = middle - 1;
207
+ }
208
+ return low;
209
+ }
210
+ function pointAtDistance(points, profile, distance) {
211
+ if (!points.length)
212
+ return null;
213
+ const clamped = Math.max(0, Math.min(profile.distanceM, distance));
214
+ const index = Math.min(segmentAt(profile.distances, clamped), points.length - 1);
215
+ const next = Math.min(index + 1, points.length - 1);
216
+ const a = points[index];
217
+ const b = points[next];
218
+ const span = profile.distances[next] - profile.distances[index];
219
+ const t = span > 0 ? (clamped - profile.distances[index]) / span : 0;
220
+ const eleA = profile.elevations[index];
221
+ const eleB = profile.elevations[next];
222
+ const ele = eleA !== null && eleA !== undefined && eleB !== null && eleB !== undefined ? eleA + (eleB - eleA) * t : eleA ?? eleB ?? null;
223
+ return {
224
+ lat: a.lat + (b.lat - a.lat) * t,
225
+ lon: a.lon + (b.lon - a.lon) * t,
226
+ ele,
227
+ bearing: bearing(a, next === index ? a : b),
228
+ index
229
+ };
230
+ }
231
+ function bearing(a, b) {
232
+ const y = Math.sin(rad(b.lon - a.lon)) * Math.cos(rad(b.lat));
233
+ const x = Math.cos(rad(a.lat)) * Math.sin(rad(b.lat)) - Math.sin(rad(a.lat)) * Math.cos(rad(b.lat)) * Math.cos(rad(b.lon - a.lon));
234
+ return (Math.atan2(y, x) * 180 / Math.PI + 360) % 360;
235
+ }
236
+ function distanceAtNearest(points, profile, target) {
237
+ let best = Infinity;
238
+ let bestDistance = 0;
239
+ const scale = Math.cos(rad(target.lat));
240
+ for (let index = 0;index < points.length - 1; index++) {
241
+ const a = points[index];
242
+ const b = points[index + 1];
243
+ const ax = (a.lon - target.lon) * scale;
244
+ const ay = a.lat - target.lat;
245
+ const dx = (b.lon - a.lon) * scale;
246
+ const dy = b.lat - a.lat;
247
+ const length = dx * dx + dy * dy;
248
+ const t = length > 0 ? Math.max(0, Math.min(1, -(ax * dx + ay * dy) / length)) : 0;
249
+ const px = ax + dx * t;
250
+ const py = ay + dy * t;
251
+ const gap = px * px + py * py;
252
+ if (gap < best) {
253
+ best = gap;
254
+ bestDistance = profile.distances[index] + (profile.distances[index + 1] - profile.distances[index]) * t;
255
+ }
256
+ }
257
+ return bestDistance;
258
+ }
259
+ function kilometreStep(distanceM, target = 10) {
260
+ const raw = distanceM / 1000 / target;
261
+ for (const step of [1, 2, 5, 10, 20, 25, 50, 100])
262
+ if (raw <= step)
263
+ return step;
264
+ return 200;
265
+ }
266
+ function sampleProfile(points, profile, samples = 400) {
267
+ if (!profile.hasElevation || profile.distanceM <= 0)
268
+ return [];
269
+ const out = [];
270
+ for (let step = 0;step <= samples; step++) {
271
+ const distance = profile.distanceM * step / samples;
272
+ const point = pointAtDistance(points, profile, distance);
273
+ if (point?.ele !== null && point?.ele !== undefined)
274
+ out.push({ distance, ele: point.ele });
275
+ }
276
+ return out;
277
+ }
278
+ function routeBounds(points) {
279
+ let west = Infinity;
280
+ let south = Infinity;
281
+ let east = -Infinity;
282
+ let north = -Infinity;
283
+ for (const point of points) {
284
+ west = Math.min(west, point.lon);
285
+ east = Math.max(east, point.lon);
286
+ south = Math.min(south, point.lat);
287
+ north = Math.max(north, point.lat);
288
+ }
289
+ return [west, south, east, north];
290
+ }
291
+ function isLoop(points) {
292
+ return points.length > 2 && haversine(points[0], points[points.length - 1]) < 250;
293
+ }
294
+
295
+ // src/ui/route-3d/route-3d.ts
296
+ var copy = {
297
+ es: {
298
+ label: "Mapa 3D del recorrido",
299
+ loading: "Cargando el recorrido…",
300
+ error: "No se ha podido cargar el recorrido.",
301
+ invalid: "Indica un archivo GPX o un evento y una clave publicable.",
302
+ empty: "Este evento todavía no tiene recorrido publicado.",
303
+ retry: "Reintentar",
304
+ noMap: "El mapa 3D no está disponible en este dispositivo.",
305
+ distance: "Distancia",
306
+ ascent: "Desnivel +",
307
+ descent: "Desnivel −",
308
+ highest: "Altitud máx.",
309
+ routes: "Recorridos",
310
+ download: "Descargar GPX",
311
+ zoomIn: "Acercar",
312
+ zoomOut: "Alejar",
313
+ north: "Orientar al norte",
314
+ view3d: "Vista 3D",
315
+ view2d: "Vista 2D",
316
+ fullscreen: "Pantalla completa",
317
+ exitFullscreen: "Salir de pantalla completa",
318
+ frame: "Ver todo el recorrido",
319
+ fly: "Vuela el recorrido",
320
+ stop: "Detener",
321
+ profile: "Perfil de altitud. Usa las flechas para recorrerlo.",
322
+ startFinish: "Salida / Meta",
323
+ start: "Salida",
324
+ finish: "Meta",
325
+ km: "km",
326
+ slope: "pendiente",
327
+ cooperativeDesktop: "Usa Ctrl + rueda para hacer zoom",
328
+ cooperativeMac: "Usa ⌘ + rueda para hacer zoom",
329
+ cooperativeMobile: "Usa dos dedos para mover el mapa",
330
+ waypoints: {
331
+ START: "Salida",
332
+ FINISH: "Meta",
333
+ AID: "Avituallamiento",
334
+ FOOD: "Comida",
335
+ WATER: "Agua",
336
+ MEDICAL: "Asistencia médica",
337
+ KM: "Kilómetro",
338
+ OTHER: "Punto de interés"
339
+ }
340
+ },
341
+ en: {
342
+ label: "3D course map",
343
+ loading: "Loading the course…",
344
+ error: "The course could not be loaded.",
345
+ invalid: "Set a GPX file, or an event and a publishable key.",
346
+ empty: "This event has no published course yet.",
347
+ retry: "Retry",
348
+ noMap: "The 3D map is not available on this device.",
349
+ distance: "Distance",
350
+ ascent: "Elevation gain",
351
+ descent: "Elevation loss",
352
+ highest: "Highest point",
353
+ routes: "Courses",
354
+ download: "Download GPX",
355
+ zoomIn: "Zoom in",
356
+ zoomOut: "Zoom out",
357
+ north: "Face north",
358
+ view3d: "3D view",
359
+ view2d: "2D view",
360
+ fullscreen: "Full screen",
361
+ exitFullscreen: "Exit full screen",
362
+ frame: "Show the whole course",
363
+ fly: "Fly the course",
364
+ stop: "Stop",
365
+ profile: "Elevation profile. Use the arrow keys to move along it.",
366
+ startFinish: "Start / Finish",
367
+ start: "Start",
368
+ finish: "Finish",
369
+ km: "km",
370
+ slope: "grade",
371
+ cooperativeDesktop: "Use Ctrl + scroll to zoom the map",
372
+ cooperativeMac: "Use ⌘ + scroll to zoom the map",
373
+ cooperativeMobile: "Use two fingers to move the map",
374
+ waypoints: {
375
+ START: "Start",
376
+ FINISH: "Finish",
377
+ AID: "Aid station",
378
+ FOOD: "Food",
379
+ WATER: "Water",
380
+ MEDICAL: "Medical point",
381
+ KM: "Kilometre",
382
+ OTHER: "Point of interest"
383
+ }
384
+ },
385
+ pt: {
386
+ label: "Mapa 3D do percurso",
387
+ loading: "A carregar o percurso…",
388
+ error: "Não foi possível carregar o percurso.",
389
+ invalid: "Indica um ficheiro GPX ou um evento e uma chave publicável.",
390
+ empty: "Este evento ainda não tem percurso publicado.",
391
+ retry: "Tentar novamente",
392
+ noMap: "O mapa 3D não está disponível neste dispositivo.",
393
+ distance: "Distância",
394
+ ascent: "Desnível +",
395
+ descent: "Desnível −",
396
+ highest: "Altitude máx.",
397
+ routes: "Percursos",
398
+ download: "Descarregar GPX",
399
+ zoomIn: "Aproximar",
400
+ zoomOut: "Afastar",
401
+ north: "Orientar a norte",
402
+ view3d: "Vista 3D",
403
+ view2d: "Vista 2D",
404
+ fullscreen: "Ecrã inteiro",
405
+ exitFullscreen: "Sair do ecrã inteiro",
406
+ frame: "Ver o percurso inteiro",
407
+ fly: "Voa o percurso",
408
+ stop: "Parar",
409
+ profile: "Perfil de altitude. Usa as setas para o percorrer.",
410
+ startFinish: "Partida / Meta",
411
+ start: "Partida",
412
+ finish: "Meta",
413
+ km: "km",
414
+ slope: "inclinação",
415
+ cooperativeDesktop: "Usa Ctrl + roda para fazer zoom",
416
+ cooperativeMac: "Usa ⌘ + roda para fazer zoom",
417
+ cooperativeMobile: "Usa dois dedos para mover o mapa",
418
+ waypoints: {
419
+ START: "Partida",
420
+ FINISH: "Meta",
421
+ AID: "Abastecimento",
422
+ FOOD: "Comida",
423
+ WATER: "Água",
424
+ MEDICAL: "Posto médico",
425
+ KM: "Quilómetro",
426
+ OTHER: "Ponto de interesse"
427
+ }
428
+ }
429
+ };
430
+ var DEFAULT_ROUTE_COLOR = "#ff7a1a";
431
+ var PROFILE_WIDTH = 1000;
432
+ var PROFILE_HEIGHT = 140;
433
+ function safeHttpUrl(value) {
434
+ try {
435
+ const url = new URL(value, document.baseURI);
436
+ const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
437
+ if (url.username || url.password)
438
+ return null;
439
+ return url.protocol === "https:" || local && url.protocol === "http:" ? url : null;
440
+ } catch {
441
+ return null;
442
+ }
443
+ }
444
+ function fromWodira(route, gpxUrl) {
445
+ return {
446
+ id: route.id,
447
+ name: route.name,
448
+ points: route.points,
449
+ waypoints: route.waypoints,
450
+ color: route.color,
451
+ gpxUrl,
452
+ distanceM: route.distanceM,
453
+ ascentM: route.ascentM,
454
+ descentM: route.descentM
455
+ };
456
+ }
457
+
458
+ class WodiraRoute3d2 extends LitElement {
459
+ static properties = {
460
+ eventId: { type: String, attribute: "event-id" },
461
+ publishableKey: { type: String, attribute: "publishable-key" },
462
+ baseUrl: { type: String, attribute: "base-url" },
463
+ routeId: { type: String, attribute: "route-id" },
464
+ gpxUrl: { type: String, attribute: "gpx-url" },
465
+ label: { type: String },
466
+ locale: { type: String },
467
+ workerUrl: { type: String, attribute: "worker-url" },
468
+ freeGestures: { type: Boolean, attribute: "free-gestures" },
469
+ gpx: { attribute: false },
470
+ tracks: { attribute: false },
471
+ loaded: { state: true },
472
+ loading: { state: true },
473
+ failed: { state: true },
474
+ activeIndex: { state: true },
475
+ hoverDistance: { state: true },
476
+ flightDistance: { state: true },
477
+ flying: { state: true },
478
+ threeD: { state: true },
479
+ fullscreen: { state: true },
480
+ mapFailed: { state: true },
481
+ mapLoading: { state: true },
482
+ bearing: { state: true }
483
+ };
484
+ static styles = css`
485
+ :host {
486
+ --_route: var(--wodira-route-color, #ff7a1a);
487
+ --_profile-height: clamp(7rem, 22cqi, 9.5rem);
488
+ --_panel: var(--wodira-route-panel-background, rgb(8 12 20 / 0.72));
489
+ --_panel-text: var(--wodira-route-panel-text, #f4f6fa);
490
+ --_panel-muted: var(--wodira-route-panel-muted, #aab4c3);
491
+ --_panel-border: var(--wodira-route-panel-border, rgb(255 255 255 / 0.12));
492
+ --_radius: var(--wodira-radius, 1rem);
493
+ --_radius-sm: var(--wodira-radius-sm, 0.625rem);
494
+ box-sizing: border-box;
495
+ color: var(--_panel-text);
496
+ container-type: inline-size;
497
+ display: block;
498
+ font-family: var(--wodira-font-family, inherit);
499
+ font-size: var(--wodira-font-size, 1rem);
500
+ line-height: 1.4;
501
+ }
502
+
503
+ *,
504
+ *::before,
505
+ *::after {
506
+ box-sizing: inherit;
507
+ }
508
+
509
+ [part~='container'] {
510
+ background: radial-gradient(120% 90% at 30% 20%, #1c3247 0%, #0b1724 60%, #060c14 100%);
511
+ border-radius: var(--_radius);
512
+ box-shadow: var(--wodira-shadow, 0 24px 60px rgb(5 10 20 / 0.35));
513
+ height: var(--wodira-route-height, clamp(28rem, 72vh, 46rem));
514
+ isolation: isolate;
515
+ overflow: hidden;
516
+ position: relative;
517
+ width: 100%;
518
+ }
519
+
520
+ [part~='container'].is-fullscreen {
521
+ border-radius: 0;
522
+ height: 100%;
523
+ }
524
+
525
+ [part~='container'].is-pseudo-fullscreen {
526
+ border-radius: 0;
527
+ height: 100dvh;
528
+ inset: 0;
529
+ position: fixed;
530
+ width: 100vw;
531
+ z-index: 2147483000;
532
+ }
533
+
534
+ [part~='map'] {
535
+ inset: 0;
536
+ position: absolute;
537
+ }
538
+
539
+ .glass {
540
+ backdrop-filter: blur(14px) saturate(140%);
541
+ -webkit-backdrop-filter: blur(14px) saturate(140%);
542
+ background: var(--_panel);
543
+ border: 1px solid var(--_panel-border);
544
+ color: var(--_panel-text);
545
+ }
546
+
547
+ [part~='header'] {
548
+ border-radius: var(--_radius);
549
+ display: grid;
550
+ gap: 0.5rem;
551
+ left: 0.75rem;
552
+ max-width: min(30rem, calc(100% - 5.5rem));
553
+ padding: 0.85rem 1rem;
554
+ position: absolute;
555
+ top: 0.75rem;
556
+ z-index: 2;
557
+ }
558
+
559
+ [part~='title'] {
560
+ font-size: clamp(1.15rem, 3.4cqi, 1.75rem);
561
+ font-weight: 800;
562
+ letter-spacing: -0.01em;
563
+ line-height: 1.05;
564
+ margin: 0;
565
+ text-transform: var(--wodira-route-title-transform, uppercase);
566
+ }
567
+
568
+ [part~='stats'] {
569
+ display: flex;
570
+ flex-wrap: wrap;
571
+ gap: 0.25rem 1.1rem;
572
+ margin: 0;
573
+ }
574
+
575
+ [part~='stat'] {
576
+ display: grid;
577
+ margin: 0;
578
+ }
579
+
580
+ [part~='stat'] dt {
581
+ color: var(--_panel-muted);
582
+ font-size: 0.7rem;
583
+ font-weight: 600;
584
+ letter-spacing: 0.08em;
585
+ text-transform: uppercase;
586
+ }
587
+
588
+ [part~='stat'] dd {
589
+ font-size: clamp(1rem, 2.6cqi, 1.35rem);
590
+ font-variant-numeric: tabular-nums;
591
+ font-weight: 800;
592
+ margin: 0;
593
+ }
594
+
595
+ [part~='stat-primary'] dd {
596
+ color: var(--_route);
597
+ }
598
+
599
+ [part~='route-tabs'] {
600
+ display: flex;
601
+ flex-wrap: wrap;
602
+ gap: 0.35rem;
603
+ }
604
+
605
+ [part~='route-tab'],
606
+ [part~='control'],
607
+ [part~='play'],
608
+ [part~='download'] {
609
+ align-items: center;
610
+ border: 1px solid var(--_panel-border);
611
+ color: var(--_panel-text);
612
+ cursor: pointer;
613
+ display: inline-flex;
614
+ font: inherit;
615
+ justify-content: center;
616
+ text-decoration: none;
617
+ transition:
618
+ background-color 0.15s ease,
619
+ border-color 0.15s ease;
620
+ }
621
+
622
+ [part~='route-tab'] {
623
+ background: rgb(255 255 255 / 0.06);
624
+ border-radius: 999px;
625
+ font-size: 0.8125rem;
626
+ font-weight: 600;
627
+ min-height: 2rem;
628
+ padding: 0.25rem 0.8rem;
629
+ }
630
+
631
+ [part~='route-tab-active'] {
632
+ background: var(--_route);
633
+ border-color: var(--_route);
634
+ color: var(--wodira-route-color-contrast, #160a02);
635
+ }
636
+
637
+ [part~='download'] {
638
+ background: none;
639
+ border: 0;
640
+ color: var(--_panel-muted);
641
+ font-size: 0.8125rem;
642
+ gap: 0.35rem;
643
+ justify-self: start;
644
+ padding: 0;
645
+ text-decoration: underline;
646
+ text-underline-offset: 3px;
647
+ }
648
+
649
+ [part~='controls'] {
650
+ border-radius: var(--_radius);
651
+ display: grid;
652
+ gap: 0.25rem;
653
+ padding: 0.3rem;
654
+ position: absolute;
655
+ right: 0.75rem;
656
+ top: 0.75rem;
657
+ z-index: 2;
658
+ }
659
+
660
+ [part~='control'] {
661
+ background: transparent;
662
+ border-color: transparent;
663
+ border-radius: var(--_radius-sm);
664
+ font-size: 1.05rem;
665
+ font-weight: 700;
666
+ height: 2.5rem;
667
+ width: 2.5rem;
668
+ }
669
+
670
+ [part~='control-active'] {
671
+ background: rgb(255 255 255 / 0.14);
672
+ }
673
+
674
+ .compass {
675
+ display: block;
676
+ transition: transform 0.1s linear;
677
+ }
678
+
679
+ [part~='play'] {
680
+ border-radius: 999px;
681
+ bottom: calc(var(--_profile-height, 9.5rem) + 1.25rem);
682
+ font-size: 0.875rem;
683
+ font-weight: 700;
684
+ gap: 0.5rem;
685
+ left: 0.75rem;
686
+ min-height: 2.75rem;
687
+ padding: 0 1.1rem 0 0.9rem;
688
+ position: absolute;
689
+ z-index: 2;
690
+ }
691
+
692
+ [part~='play'] .dot {
693
+ background: var(--_route);
694
+ border-radius: 999px;
695
+ box-shadow: 0 0 12px var(--_route);
696
+ height: 0.65rem;
697
+ width: 0.65rem;
698
+ }
699
+
700
+ @media (hover: hover) {
701
+ [part~='route-tab']:not([part~='route-tab-active']):hover,
702
+ [part~='control']:hover,
703
+ [part~='play']:hover {
704
+ background: rgb(255 255 255 / 0.14);
705
+ }
706
+ }
707
+
708
+ [part~='route-tab']:focus-visible,
709
+ [part~='control']:focus-visible,
710
+ [part~='play']:focus-visible,
711
+ [part~='download']:focus-visible,
712
+ [part~='profile']:focus-visible {
713
+ outline: 3px solid var(--_route);
714
+ outline-offset: 2px;
715
+ }
716
+
717
+ [part~='profile'] {
718
+ border-radius: var(--_radius);
719
+ bottom: 0.75rem;
720
+ height: var(--_profile-height);
721
+ left: 0.75rem;
722
+ margin: 0;
723
+ padding: 0.6rem 0.9rem 1.5rem 2.6rem;
724
+ position: absolute;
725
+ right: 0.75rem;
726
+ touch-action: pan-y;
727
+ z-index: 2;
728
+ }
729
+
730
+ [part~='profile'] svg {
731
+ display: block;
732
+ height: 100%;
733
+ overflow: visible;
734
+ width: 100%;
735
+ }
736
+
737
+ .axis {
738
+ white-space: nowrap;
739
+ color: var(--_panel-muted);
740
+ font-size: 0.7rem;
741
+ font-variant-numeric: tabular-nums;
742
+ pointer-events: none;
743
+ position: absolute;
744
+ }
745
+
746
+ .axis-y {
747
+ left: 0.5rem;
748
+ transform: translateY(-50%);
749
+ }
750
+
751
+ .axis-x {
752
+ bottom: 0.3rem;
753
+ transform: translateX(-50%);
754
+ }
755
+
756
+ .axis-x.first {
757
+ transform: none;
758
+ }
759
+
760
+ .axis-x.last {
761
+ color: var(--_route);
762
+ font-weight: 700;
763
+ transform: translateX(-100%);
764
+ }
765
+
766
+ .axis-x.first {
767
+ color: var(--_route);
768
+ font-weight: 700;
769
+ }
770
+
771
+ [part~='profile-tooltip'] {
772
+ background: #fff;
773
+ border-radius: 0.5rem;
774
+ box-shadow: 0 6px 18px rgb(0 0 0 / 0.35);
775
+ color: #10131a;
776
+ font-size: 0.75rem;
777
+ font-variant-numeric: tabular-nums;
778
+ font-weight: 700;
779
+ padding: 0.3rem 0.55rem;
780
+ pointer-events: none;
781
+ position: absolute;
782
+ top: -0.6rem;
783
+ transform: translate(-50%, -100%);
784
+ white-space: nowrap;
785
+ }
786
+
787
+ [part~='status'] {
788
+ align-items: center;
789
+ color: var(--_panel-muted);
790
+ display: grid;
791
+ gap: 0.75rem;
792
+ inset: 0;
793
+ justify-items: center;
794
+ margin: 0;
795
+ padding: 2rem;
796
+ position: absolute;
797
+ text-align: center;
798
+ z-index: 1;
799
+ }
800
+
801
+ [part~='status'] button {
802
+ background: var(--_route);
803
+ border: 0;
804
+ border-radius: var(--_radius-sm);
805
+ color: #160a02;
806
+ cursor: pointer;
807
+ font: inherit;
808
+ font-weight: 700;
809
+ min-height: 2.75rem;
810
+ padding: 0 1rem;
811
+ }
812
+
813
+ .spinner {
814
+ animation: spin 0.9s linear infinite;
815
+ border: 3px solid rgb(255 255 255 / 0.15);
816
+ border-radius: 999px;
817
+ border-top-color: var(--_route);
818
+ height: 2rem;
819
+ width: 2rem;
820
+ }
821
+
822
+ @keyframes spin {
823
+ to {
824
+ transform: rotate(1turn);
825
+ }
826
+ }
827
+
828
+ /* Markers live inside the MapLibre container, which is in this shadow root. */
829
+ .wr-pin {
830
+ align-items: center;
831
+ display: flex;
832
+ flex-direction: column;
833
+ pointer-events: none;
834
+ }
835
+
836
+ .wr-pin__label {
837
+ background: var(--wodira-route-start-color, #2f7d32);
838
+ border: 1px solid rgb(255 255 255 / 0.5);
839
+ border-radius: 0.3rem;
840
+ box-shadow: 0 4px 14px rgb(0 0 0 / 0.4);
841
+ color: #fff;
842
+ font-size: 0.75rem;
843
+ font-weight: 800;
844
+ letter-spacing: 0.04em;
845
+ order: -1;
846
+ padding: 0.2rem 0.5rem;
847
+ text-transform: uppercase;
848
+ white-space: nowrap;
849
+ }
850
+
851
+ .wr-pin--finish .wr-pin__label {
852
+ background: var(--wodira-route-finish-color, #b3261e);
853
+ }
854
+
855
+ .wr-pin__dot {
856
+ background: #fff;
857
+ border: 4px solid var(--_route);
858
+ border-radius: 999px;
859
+ box-shadow:
860
+ 0 0 0 4px rgb(255 255 255 / 0.25),
861
+ 0 0 18px var(--_route);
862
+ height: 1.1rem;
863
+ margin-top: 0.3rem;
864
+ width: 1.1rem;
865
+ }
866
+
867
+ .wr-poi {
868
+ align-items: center;
869
+ background: rgb(8 12 20 / 0.82);
870
+ border: 2px solid #fff;
871
+ border-radius: 999px;
872
+ box-shadow: 0 4px 12px rgb(0 0 0 / 0.4);
873
+ cursor: pointer;
874
+ display: flex;
875
+ font-size: 0.85rem;
876
+ height: 1.9rem;
877
+ justify-content: center;
878
+ width: 1.9rem;
879
+ }
880
+
881
+ .wr-km-anchor {
882
+ pointer-events: none;
883
+ }
884
+
885
+ .wr-km {
886
+ background: rgb(8 12 20 / 0.78);
887
+ border: 1px solid var(--_route);
888
+ border-radius: 999px;
889
+ color: #fff;
890
+ display: block;
891
+ font-size: 0.68rem;
892
+ font-weight: 800;
893
+ padding: 0.05rem 0.4rem;
894
+ transition: opacity 0.2s ease;
895
+ translate: 0 var(--km-offset, 0);
896
+ white-space: nowrap;
897
+ }
898
+
899
+ /* MapLibre writes an inline opacity for terrain occlusion, so hide with visibility. */
900
+ .wr-km--hidden {
901
+ visibility: hidden;
902
+ }
903
+
904
+ .wr-popup .maplibregl-popup-content {
905
+ background: rgb(8 12 20 / 0.9);
906
+ border-radius: 0.5rem;
907
+ color: #fff;
908
+ font: 600 0.8rem var(--wodira-font-family, inherit);
909
+ padding: 0.4rem 0.6rem;
910
+ }
911
+
912
+ /* Keep MapLibre's attribution readable, dark and clear of the elevation profile. */
913
+ .maplibregl-ctrl-bottom-right {
914
+ bottom: calc(var(--_profile-height) + 1rem);
915
+ right: 0.5rem;
916
+ }
917
+
918
+ .maplibregl-ctrl.maplibregl-ctrl-attrib {
919
+ background: rgb(8 12 20 / 0.6);
920
+ border-radius: 999px;
921
+ color: var(--_panel-muted);
922
+ font-size: 0.65rem;
923
+ margin: 0;
924
+ }
925
+
926
+ .maplibregl-ctrl-attrib a {
927
+ color: inherit;
928
+ }
929
+
930
+ .maplibregl-ctrl-attrib.maplibregl-compact-show {
931
+ border-radius: 0.5rem;
932
+ }
933
+
934
+ .maplibregl-ctrl-attrib-button {
935
+ background-color: rgb(255 255 255 / 0.85);
936
+ }
937
+
938
+ .wr-pin-marker {
939
+ z-index: 3;
940
+ }
941
+
942
+ @container (max-width: 40rem) {
943
+ [part~='header'] {
944
+ max-width: calc(100% - 4.75rem);
945
+ padding: 0.65rem 0.75rem;
946
+ }
947
+
948
+ [part~='stat-secondary'] {
949
+ display: none;
950
+ }
951
+
952
+ [part~='control'] {
953
+ height: 2.25rem;
954
+ width: 2.25rem;
955
+ }
956
+
957
+ [part~='profile'] {
958
+ padding-left: 2.3rem;
959
+ }
960
+ }
961
+
962
+ @media (prefers-reduced-motion: reduce) {
963
+ .spinner {
964
+ animation-duration: 2.5s;
965
+ }
966
+
967
+ .compass,
968
+ .wr-km,
969
+ [part~='route-tab'],
970
+ [part~='control'],
971
+ [part~='play'] {
972
+ transition: none;
973
+ }
974
+ }
975
+ `;
976
+ view = null;
977
+ viewContainer = null;
978
+ viewGeneration = 0;
979
+ abort = null;
980
+ profileCache = null;
981
+ themeObserver = null;
982
+ drawnTrack = null;
983
+ constructor() {
984
+ super();
985
+ this.eventId = "";
986
+ this.publishableKey = "";
987
+ this.baseUrl = "";
988
+ this.routeId = "";
989
+ this.gpxUrl = "";
990
+ this.label = "";
991
+ this.locale = "auto";
992
+ this.workerUrl = "";
993
+ this.freeGestures = false;
994
+ this.gpx = null;
995
+ this.tracks = null;
996
+ this.loaded = [];
997
+ this.loading = false;
998
+ this.failed = null;
999
+ this.activeIndex = 0;
1000
+ this.hoverDistance = null;
1001
+ this.flightDistance = null;
1002
+ this.flying = false;
1003
+ this.threeD = true;
1004
+ this.fullscreen = false;
1005
+ this.mapFailed = false;
1006
+ this.mapLoading = true;
1007
+ this.bearing = 0;
1008
+ }
1009
+ refreshTheme() {
1010
+ this.view?.setColors(this.colors());
1011
+ }
1012
+ connectedCallback() {
1013
+ super.connectedCallback();
1014
+ this.requestUpdate();
1015
+ if (this.loading && this.abort?.signal.aborted)
1016
+ this.load();
1017
+ document.addEventListener("fullscreenchange", this.onFullscreenChange);
1018
+ document.addEventListener("keydown", this.onDocumentKey);
1019
+ this.themeObserver = new MutationObserver(() => this.refreshTheme());
1020
+ for (const target of [this, this.ownerDocument.documentElement, this.ownerDocument.body])
1021
+ if (target)
1022
+ this.themeObserver.observe(target, {
1023
+ attributes: true,
1024
+ attributeFilter: ["class", "style", "data-theme"]
1025
+ });
1026
+ }
1027
+ disconnectedCallback() {
1028
+ document.removeEventListener("fullscreenchange", this.onFullscreenChange);
1029
+ document.removeEventListener("keydown", this.onDocumentKey);
1030
+ this.themeObserver?.disconnect();
1031
+ this.abort?.abort();
1032
+ this.disposeView();
1033
+ this.setPseudoFullscreen(false);
1034
+ super.disconnectedCallback();
1035
+ }
1036
+ willUpdate(changes) {
1037
+ if (changes.has("eventId") || changes.has("publishableKey") || changes.has("baseUrl") || changes.has("gpxUrl") || changes.has("gpx") || changes.has("tracks"))
1038
+ this.load();
1039
+ if (changes.has("routeId") && this.routeId) {
1040
+ const index = this.loaded.findIndex((track) => track.id === this.routeId);
1041
+ if (index >= 0)
1042
+ this.activeIndex = index;
1043
+ }
1044
+ }
1045
+ updated() {
1046
+ if (!this.isConnected)
1047
+ return;
1048
+ const container = this.renderRoot.querySelector('[part~="map"]');
1049
+ if (container !== this.viewContainer) {
1050
+ this.disposeView();
1051
+ if (container && !this.mapFailed)
1052
+ this.startView(container);
1053
+ }
1054
+ const track = this.activeTrack;
1055
+ if (this.view && track && track !== this.drawnTrack)
1056
+ this.drawTrack(track);
1057
+ this.view?.setCursor(this.flightDistance ?? this.hoverDistance);
1058
+ }
1059
+ get language() {
1060
+ const locale = this.locale && this.locale !== "auto" ? this.locale : this.ownerDocument.documentElement.lang || navigator.language || "es";
1061
+ const language = locale.toLowerCase().split("-")[0];
1062
+ return language === "en" || language === "pt" ? language : "es";
1063
+ }
1064
+ get numberLocale() {
1065
+ return this.locale && this.locale !== "auto" ? this.locale : this.ownerDocument.documentElement.lang || navigator.language || "es-ES";
1066
+ }
1067
+ get text() {
1068
+ return copy[this.language];
1069
+ }
1070
+ async load() {
1071
+ this.abort?.abort();
1072
+ const abort = new AbortController;
1073
+ this.abort = abort;
1074
+ this.failed = null;
1075
+ this.loading = true;
1076
+ try {
1077
+ const tracks = await this.fetchTracks(abort.signal);
1078
+ if (abort.signal.aborted)
1079
+ return;
1080
+ if (tracks === null) {
1081
+ this.loaded = [];
1082
+ this.failed = "invalid";
1083
+ return;
1084
+ }
1085
+ const usable = tracks.filter((track) => track.points.length >= 2);
1086
+ this.loaded = usable;
1087
+ const requested = usable.findIndex((track) => track.id === this.routeId);
1088
+ this.activeIndex = requested >= 0 ? requested : 0;
1089
+ if (!usable.length)
1090
+ this.failed = "empty";
1091
+ } catch {
1092
+ if (!abort.signal.aborted) {
1093
+ this.loaded = [];
1094
+ this.failed = "error";
1095
+ }
1096
+ } finally {
1097
+ if (!abort.signal.aborted)
1098
+ this.loading = false;
1099
+ }
1100
+ }
1101
+ async fetchTracks(signal) {
1102
+ if (this.tracks?.length)
1103
+ return this.tracks;
1104
+ if (this.gpx)
1105
+ return [this.trackFromGpx(this.gpx, "gpx", null)];
1106
+ if (this.gpxUrl) {
1107
+ const url = safeHttpUrl(this.gpxUrl);
1108
+ if (!url)
1109
+ return null;
1110
+ const response = await fetch(url, { signal });
1111
+ if (!response.ok)
1112
+ throw new Error(`GPX request failed (${response.status})`);
1113
+ return [this.trackFromGpx(await response.text(), url.pathname, url.href)];
1114
+ }
1115
+ if (this.eventId && this.publishableKey?.startsWith("wpk_live_")) {
1116
+ const options = { publishableKey: this.publishableKey };
1117
+ if (this.baseUrl) {
1118
+ if (!safeHttpUrl(this.baseUrl))
1119
+ return null;
1120
+ options.baseUrl = this.baseUrl;
1121
+ }
1122
+ const client = createWodiraBrowserClient(options);
1123
+ const routes = await client.getEventRoutes(this.eventId, signal);
1124
+ return routes.map((route) => fromWodira(route, client.eventRouteGpxUrl(this.eventId, route.id)));
1125
+ }
1126
+ return null;
1127
+ }
1128
+ trackFromGpx(text, id, gpxUrl) {
1129
+ const parsed = parseGpx2(text);
1130
+ const fileName = id.split("/").pop()?.replace(/\.gpx$/i, "") ?? "";
1131
+ return {
1132
+ id,
1133
+ name: parsed.name || decodeURIComponent(fileName) || this.text.label,
1134
+ points: parsed.points,
1135
+ waypoints: parsed.waypoints,
1136
+ gpxUrl
1137
+ };
1138
+ }
1139
+ get activeTrack() {
1140
+ return this.loaded[this.activeIndex] ?? this.loaded[0] ?? null;
1141
+ }
1142
+ get profile() {
1143
+ const track = this.activeTrack;
1144
+ if (!track)
1145
+ return null;
1146
+ if (this.profileCache?.track !== track) {
1147
+ const profile = measureRoute2(track.points);
1148
+ this.profileCache = {
1149
+ track,
1150
+ profile,
1151
+ waypointMarks: profile.hasElevation ? track.waypoints.filter((waypoint) => !["START", "FINISH", "KM"].includes(waypoint.type)).map((waypoint) => distanceAtNearest(track.points, profile, waypoint)) : []
1152
+ };
1153
+ }
1154
+ return this.profileCache.profile;
1155
+ }
1156
+ selectTrack(index) {
1157
+ if (index === this.activeIndex)
1158
+ return;
1159
+ this.view?.stopFlight();
1160
+ this.activeIndex = index;
1161
+ this.hoverDistance = null;
1162
+ const track = this.activeTrack;
1163
+ if (track)
1164
+ this.dispatchEvent(new CustomEvent("wodira:route:selected", {
1165
+ bubbles: true,
1166
+ composed: true,
1167
+ detail: { routeId: track.id }
1168
+ }));
1169
+ }
1170
+ colors() {
1171
+ const style = getComputedStyle(this);
1172
+ const read = (token) => style.getPropertyValue(token).trim();
1173
+ const route = read("--wodira-route-color") || this.activeTrack?.color || DEFAULT_ROUTE_COLOR;
1174
+ return {
1175
+ route,
1176
+ glow: read("--wodira-route-glow") || route,
1177
+ highlight: read("--wodira-route-highlight") || "#fff1df"
1178
+ };
1179
+ }
1180
+ labels() {
1181
+ const text = this.text;
1182
+ return {
1183
+ startFinish: text.startFinish,
1184
+ start: text.start,
1185
+ finish: text.finish,
1186
+ km: text.km,
1187
+ waypoints: { ...text.waypoints },
1188
+ cooperativeDesktop: text.cooperativeDesktop,
1189
+ cooperativeMac: text.cooperativeMac,
1190
+ cooperativeMobile: text.cooperativeMobile
1191
+ };
1192
+ }
1193
+ async startView(container) {
1194
+ const generation = ++this.viewGeneration;
1195
+ this.viewContainer = container;
1196
+ this.mapLoading = true;
1197
+ try {
1198
+ const { RouteMapView } = await (__preload("rn3jgtqn"), import("./map-view-rn3jgtqn.js"));
1199
+ if (generation !== this.viewGeneration)
1200
+ return;
1201
+ const options = {
1202
+ container,
1203
+ colors: this.colors(),
1204
+ labels: this.labels(),
1205
+ cooperative: !this.freeGestures && !this.fullscreen,
1206
+ threeD: this.threeD,
1207
+ onHover: (distance) => {
1208
+ if (!this.flying)
1209
+ this.hoverDistance = distance;
1210
+ },
1211
+ onFlight: (distance) => {
1212
+ this.flightDistance = distance;
1213
+ this.flying = distance !== null;
1214
+ },
1215
+ onBearing: (bearing) => {
1216
+ this.bearing = bearing;
1217
+ },
1218
+ onFail: () => {
1219
+ if (generation === this.viewGeneration) {
1220
+ this.disposeView();
1221
+ this.mapFailed = true;
1222
+ }
1223
+ }
1224
+ };
1225
+ if (this.workerUrl)
1226
+ options.workerUrl = this.workerUrl;
1227
+ this.view = new RouteMapView(options);
1228
+ const track = this.activeTrack;
1229
+ if (track)
1230
+ this.drawTrack(track);
1231
+ } catch {
1232
+ if (generation === this.viewGeneration) {
1233
+ this.disposeView();
1234
+ this.mapFailed = true;
1235
+ }
1236
+ }
1237
+ }
1238
+ drawTrack(track) {
1239
+ const profile = this.profile;
1240
+ const view = this.view;
1241
+ if (!view || !profile)
1242
+ return;
1243
+ this.drawnTrack = track;
1244
+ view.setColors(this.colors());
1245
+ view.setTrack(track, profile, true).then(() => {
1246
+ if (!this.isConnected || this.view !== view || this.activeTrack !== track)
1247
+ return;
1248
+ this.mapLoading = false;
1249
+ this.dispatchEvent(new CustomEvent("wodira:route:ready", {
1250
+ bubbles: true,
1251
+ composed: true,
1252
+ detail: {
1253
+ routeId: track.id,
1254
+ distanceM: track.distanceM ?? profile.distanceM,
1255
+ ascentM: track.ascentM ?? profile.ascentM
1256
+ }
1257
+ }));
1258
+ });
1259
+ }
1260
+ disposeView() {
1261
+ this.viewGeneration++;
1262
+ this.view?.dispose();
1263
+ this.view = null;
1264
+ this.viewContainer = null;
1265
+ this.drawnTrack = null;
1266
+ this.flying = false;
1267
+ this.flightDistance = null;
1268
+ }
1269
+ toggle3d() {
1270
+ this.threeD = !this.threeD;
1271
+ this.view?.set3d(this.threeD);
1272
+ }
1273
+ toggleFlight() {
1274
+ if (!this.view)
1275
+ return;
1276
+ if (this.view.flying)
1277
+ this.view.stopFlight();
1278
+ else
1279
+ this.view.fly(this.hoverDistance ?? 0);
1280
+ }
1281
+ async toggleFullscreen() {
1282
+ const shell = this.renderRoot.querySelector('[part~="container"]');
1283
+ if (!shell)
1284
+ return;
1285
+ if (this.fullscreen) {
1286
+ if (document.fullscreenElement)
1287
+ await document.exitFullscreen().catch(() => {});
1288
+ else
1289
+ this.setPseudoFullscreen(false);
1290
+ return;
1291
+ }
1292
+ if (shell.requestFullscreen && document.fullscreenEnabled) {
1293
+ await shell.requestFullscreen().catch(() => this.setPseudoFullscreen(true));
1294
+ } else
1295
+ this.setPseudoFullscreen(true);
1296
+ }
1297
+ pseudoFullscreen = false;
1298
+ setPseudoFullscreen(enabled) {
1299
+ if (this.pseudoFullscreen === enabled)
1300
+ return;
1301
+ this.pseudoFullscreen = enabled;
1302
+ this.ownerDocument.documentElement.style.overflow = enabled ? "hidden" : "";
1303
+ this.fullscreen = enabled;
1304
+ this.view?.setCooperative(!enabled && !this.freeGestures);
1305
+ requestAnimationFrame(() => this.view?.resize());
1306
+ }
1307
+ onFullscreenChange = () => {
1308
+ const shell = this.renderRoot.querySelector('[part~="container"]');
1309
+ const active = !!shell && document.fullscreenElement === this;
1310
+ const inside = !!shell && this.shadowRoot?.fullscreenElement === shell;
1311
+ this.fullscreen = active || inside;
1312
+ this.view?.setCooperative(!this.fullscreen && !this.freeGestures);
1313
+ requestAnimationFrame(() => this.view?.resize());
1314
+ };
1315
+ onDocumentKey = (event) => {
1316
+ if (event.key === "Escape" && this.pseudoFullscreen)
1317
+ this.setPseudoFullscreen(false);
1318
+ };
1319
+ profileDistanceAt(event) {
1320
+ const profile = this.profile;
1321
+ const svgElement = this.renderRoot.querySelector('[part~="profile"] svg');
1322
+ if (!profile || !svgElement)
1323
+ return null;
1324
+ const box = svgElement.getBoundingClientRect();
1325
+ const fraction = Math.max(0, Math.min(1, (event.clientX - box.left) / box.width));
1326
+ return fraction * profile.distanceM;
1327
+ }
1328
+ onProfilePointer(event) {
1329
+ if (this.flying)
1330
+ return;
1331
+ const distance = this.profileDistanceAt(event);
1332
+ if (distance !== null)
1333
+ this.hoverDistance = distance;
1334
+ }
1335
+ onProfileLeave(event) {
1336
+ if (event.pointerType === "mouse")
1337
+ this.hoverDistance = null;
1338
+ }
1339
+ onProfileKey(event) {
1340
+ const profile = this.profile;
1341
+ if (!profile)
1342
+ return;
1343
+ const step = profile.distanceM / 100;
1344
+ const current = this.hoverDistance ?? 0;
1345
+ const moves = {
1346
+ ArrowRight: current + step,
1347
+ ArrowLeft: current - step,
1348
+ PageUp: current + step * 10,
1349
+ PageDown: current - step * 10,
1350
+ Home: 0,
1351
+ End: profile.distanceM
1352
+ };
1353
+ const next = moves[event.key];
1354
+ if (next === undefined)
1355
+ return;
1356
+ event.preventDefault();
1357
+ this.hoverDistance = Math.max(0, Math.min(profile.distanceM, next));
1358
+ }
1359
+ formatKm(metres, digits = 1) {
1360
+ const km = metres / 1000;
1361
+ return new Intl.NumberFormat(this.numberLocale, {
1362
+ maximumFractionDigits: km >= 100 ? 0 : digits
1363
+ }).format(km);
1364
+ }
1365
+ formatMetres(metres) {
1366
+ return new Intl.NumberFormat(this.numberLocale, { maximumFractionDigits: 0 }).format(metres);
1367
+ }
1368
+ render() {
1369
+ const text = this.text;
1370
+ const classes = [
1371
+ this.fullscreen && !this.pseudoFullscreen ? "is-fullscreen" : "",
1372
+ this.pseudoFullscreen ? "is-pseudo-fullscreen" : ""
1373
+ ].join(" ");
1374
+ return html`<section
1375
+ part="container"
1376
+ class=${classes}
1377
+ aria-label=${text.label}
1378
+ style=${styleMap({
1379
+ "--_route": `var(--wodira-route-color, ${this.activeTrack?.color || DEFAULT_ROUTE_COLOR})`
1380
+ })}
1381
+ >
1382
+ ${this.renderBody()}
1383
+ </section>`;
1384
+ }
1385
+ renderBody() {
1386
+ const text = this.text;
1387
+ if (this.loading && !this.loaded.length)
1388
+ return html`<div part="status loader" role="status">
1389
+ <span class="spinner" aria-hidden="true"></span>${text.loading}
1390
+ </div>`;
1391
+ if (this.failed)
1392
+ return html`<div part="status error" role=${this.failed === "empty" ? "status" : "alert"}>
1393
+ <span>${text[this.failed]}</span>
1394
+ ${this.failed === "error" ? html`<button type="button" @click=${() => this.load()}>${text.retry}</button>` : nothing}
1395
+ </div>`;
1396
+ const track = this.activeTrack;
1397
+ const profile = this.profile;
1398
+ if (!track || !profile)
1399
+ return nothing;
1400
+ return html`
1401
+ ${this.mapFailed ? html`<p part="status">${text.noMap}</p>` : html`<div part="map"></div>`}
1402
+ ${this.mapLoading && !this.mapFailed ? html`<div part="status loader" role="status" style="pointer-events:none">
1403
+ <span class="spinner" aria-hidden="true"></span>
1404
+ </div>` : nothing}
1405
+ ${this.renderHeader(track, profile)} ${this.renderControls()}
1406
+ ${this.mapFailed ? nothing : html`<button
1407
+ part="play"
1408
+ class="glass"
1409
+ type="button"
1410
+ aria-pressed=${String(this.flying)}
1411
+ @click=${this.toggleFlight}
1412
+ >
1413
+ <span class="dot" aria-hidden="true"></span>${this.flying ? text.stop : text.fly}
1414
+ </button>`}
1415
+ ${this.renderProfile(track, profile)}
1416
+ `;
1417
+ }
1418
+ renderHeader(track, profile) {
1419
+ const text = this.text;
1420
+ const distance = track.distanceM ?? profile.distanceM;
1421
+ const ascent = track.ascentM ?? profile.ascentM;
1422
+ const descent = track.descentM ?? profile.descentM;
1423
+ return html`<header part="header" class="glass">
1424
+ <h2 part="title">${this.label || track.name}</h2>
1425
+ <dl part="stats">
1426
+ <div part="stat stat-primary">
1427
+ <dt>${text.distance}</dt>
1428
+ <dd>${this.formatKm(distance)} km</dd>
1429
+ </div>
1430
+ ${profile.hasElevation || track.ascentM ? html`<div part="stat stat-primary">
1431
+ <dt>${text.ascent}</dt>
1432
+ <dd>${this.formatMetres(ascent)} m</dd>
1433
+ </div>
1434
+ <div part="stat stat-secondary">
1435
+ <dt>${text.descent}</dt>
1436
+ <dd>${this.formatMetres(descent)} m</dd>
1437
+ </div>` : nothing}
1438
+ ${profile.maxEleM !== null ? html`<div part="stat stat-secondary">
1439
+ <dt>${text.highest}</dt>
1440
+ <dd>${this.formatMetres(profile.maxEleM)} m</dd>
1441
+ </div>` : nothing}
1442
+ </dl>
1443
+ ${this.loaded.length > 1 ? html`<div part="route-tabs" role="group" aria-label=${text.routes}>
1444
+ ${this.loaded.map((item, index) => html`<button
1445
+ part=${index === this.activeIndex ? "route-tab route-tab-active" : "route-tab"}
1446
+ type="button"
1447
+ aria-pressed=${String(index === this.activeIndex)}
1448
+ @click=${() => this.selectTrack(index)}
1449
+ >
1450
+ ${item.name}
1451
+ </button>`)}
1452
+ </div>` : nothing}
1453
+ ${track.gpxUrl ? html`<a part="download" href=${track.gpxUrl} download rel="noopener"
1454
+ >↓ ${text.download}</a
1455
+ >` : nothing}
1456
+ </header>`;
1457
+ }
1458
+ renderControls() {
1459
+ const text = this.text;
1460
+ if (this.mapFailed)
1461
+ return nothing;
1462
+ const control = (label, content, handler, active = false) => html`<button
1463
+ part=${active ? "control control-active" : "control"}
1464
+ type="button"
1465
+ aria-label=${label}
1466
+ title=${label}
1467
+ @click=${handler}
1468
+ >
1469
+ ${content}
1470
+ </button>`;
1471
+ return html`<div part="controls" class="glass" role="toolbar" aria-label=${text.label}>
1472
+ ${control(text.zoomIn, "+", () => this.view?.zoomBy(1))}
1473
+ ${control(text.zoomOut, "−", () => this.view?.zoomBy(-1))}
1474
+ ${control(text.north, html`<svg
1475
+ class="compass"
1476
+ style=${`transform: rotate(${-this.bearing}deg)`}
1477
+ width="18"
1478
+ height="18"
1479
+ viewBox="0 0 24 24"
1480
+ aria-hidden="true"
1481
+ >
1482
+ <path d="M12 2 16 12H8Z" fill="currentColor" />
1483
+ <path d="M12 22 8 12h8Z" fill="currentColor" opacity="0.35" />
1484
+ </svg>`, () => this.view?.resetNorth())}
1485
+ ${control(this.threeD ? text.view2d : text.view3d, this.threeD ? "2D" : "3D", () => this.toggle3d())}
1486
+ ${control(text.frame, html`<svg
1487
+ width="18"
1488
+ height="18"
1489
+ viewBox="0 0 24 24"
1490
+ aria-hidden="true"
1491
+ fill="none"
1492
+ stroke="currentColor"
1493
+ stroke-width="2"
1494
+ stroke-linecap="round"
1495
+ >
1496
+ <path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5" />
1497
+ </svg>`, () => this.view?.frame(1200))}
1498
+ ${control(this.fullscreen ? text.exitFullscreen : text.fullscreen, html`<svg
1499
+ width="18"
1500
+ height="18"
1501
+ viewBox="0 0 24 24"
1502
+ aria-hidden="true"
1503
+ fill="none"
1504
+ stroke="currentColor"
1505
+ stroke-width="2"
1506
+ stroke-linecap="round"
1507
+ >
1508
+ ${this.fullscreen ? svg`<path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5" />` : svg`<path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5M9 9l-5-5M15 9l5-5M9 15l-5 5M15 15l5 5" />`}
1509
+ </svg>`, () => void this.toggleFullscreen(), this.fullscreen)}
1510
+ </div>`;
1511
+ }
1512
+ renderProfile(track, profile) {
1513
+ const text = this.text;
1514
+ const samples = sampleProfile(track.points, profile);
1515
+ if (samples.length < 2 || profile.minEleM === null || profile.maxEleM === null)
1516
+ return nothing;
1517
+ const range = Math.max(50, profile.maxEleM - profile.minEleM);
1518
+ const floor = profile.minEleM - range * 0.15;
1519
+ const ceiling = profile.maxEleM + range * 0.12;
1520
+ const x = (distance) => distance / profile.distanceM * PROFILE_WIDTH;
1521
+ const y = (ele) => PROFILE_HEIGHT - (ele - floor) / (ceiling - floor) * PROFILE_HEIGHT;
1522
+ const line = samples.map((sample, index) => `${index ? "L" : "M"}${x(sample.distance).toFixed(1)},${y(sample.ele).toFixed(1)}`).join("");
1523
+ const area = `${line}L${PROFILE_WIDTH},${PROFILE_HEIGHT}L0,${PROFILE_HEIGHT}Z`;
1524
+ const step = kilometreStep(profile.distanceM, 6);
1525
+ const ticks = [];
1526
+ for (let km = step;km * 1000 < profile.distanceM - step * 400; km += step)
1527
+ ticks.push(km);
1528
+ const levels = [
1529
+ floor + (ceiling - floor) * 0.2,
1530
+ floor + (ceiling - floor) * 0.55,
1531
+ floor + (ceiling - floor) * 0.9
1532
+ ];
1533
+ const cursorDistance = this.flightDistance ?? this.hoverDistance;
1534
+ const cursor = cursorDistance !== null ? pointAtDistance(track.points, profile, cursorDistance) : null;
1535
+ const slope = (() => {
1536
+ if (cursorDistance === null)
1537
+ return null;
1538
+ const before = pointAtDistance(track.points, profile, cursorDistance - 100);
1539
+ const after = pointAtDistance(track.points, profile, cursorDistance + 100);
1540
+ if (before?.ele == null || after?.ele == null)
1541
+ return null;
1542
+ const span = Math.min(profile.distanceM, cursorDistance + 100) - Math.max(0, cursorDistance - 100);
1543
+ return span > 0 ? (after.ele - before.ele) / span * 100 : null;
1544
+ })();
1545
+ const waypointMarks = this.profileCache.waypointMarks;
1546
+ const gradientId = "wr-profile-fill";
1547
+ const percent = (distance) => `${distance / profile.distanceM * 100}%`;
1548
+ return html`<figure
1549
+ part="profile"
1550
+ class="glass"
1551
+ tabindex="0"
1552
+ role="slider"
1553
+ aria-label=${text.profile}
1554
+ aria-valuemin="0"
1555
+ aria-valuemax=${Math.round(profile.distanceM)}
1556
+ aria-valuenow=${Math.round(cursorDistance ?? 0)}
1557
+ aria-valuetext=${cursor ? `${this.formatKm(cursorDistance ?? 0, 2)} km, ${cursor.ele === null ? "" : `${this.formatMetres(cursor.ele)} m`}` : `0 km`}
1558
+ @pointermove=${this.onProfilePointer}
1559
+ @pointerdown=${this.onProfilePointer}
1560
+ @pointerleave=${this.onProfileLeave}
1561
+ @keydown=${this.onProfileKey}
1562
+ >
1563
+ <div style="position:relative;height:100%">
1564
+ <svg
1565
+ viewBox="0 0 ${PROFILE_WIDTH} ${PROFILE_HEIGHT}"
1566
+ preserveAspectRatio="none"
1567
+ aria-hidden="true"
1568
+ >
1569
+ <defs>
1570
+ <linearGradient id=${gradientId} x1="0" y1="0" x2="0" y2="1">
1571
+ <stop offset="0" stop-color="var(--_route)" stop-opacity="0.75"></stop>
1572
+ <stop offset="1" stop-color="var(--_route)" stop-opacity="0.05"></stop>
1573
+ </linearGradient>
1574
+ </defs>
1575
+ ${levels.map((level) => svg`<line x1="0" x2=${PROFILE_WIDTH} y1=${y(level)} y2=${y(level)} stroke="currentColor" stroke-opacity="0.12" stroke-dasharray="4 6" vector-effect="non-scaling-stroke"></line>`)}
1576
+ <path d=${area} fill="url(#${gradientId})"></path>
1577
+ <path
1578
+ d=${line}
1579
+ fill="none"
1580
+ stroke="var(--_route)"
1581
+ stroke-width="2.5"
1582
+ vector-effect="non-scaling-stroke"
1583
+ style="filter: drop-shadow(0 0 6px var(--_route))"
1584
+ ></path>
1585
+ ${waypointMarks.map((distance) => svg`<line x1=${x(distance)} x2=${x(distance)} y1=${PROFILE_HEIGHT - 8} y2=${PROFILE_HEIGHT} stroke="#fff" stroke-width="2" vector-effect="non-scaling-stroke"></line>`)}
1586
+ ${cursor && cursor.ele !== null ? svg`<line x1=${x(cursorDistance)} x2=${x(cursorDistance)} y1="0" y2=${PROFILE_HEIGHT} stroke="#fff" stroke-opacity="0.7" vector-effect="non-scaling-stroke"></line>` : nothing}
1587
+ </svg>
1588
+ ${cursor && cursor.ele !== null ? html`<span
1589
+ style=${`position:absolute;left:${percent(cursorDistance)};top:${y(cursor.ele) / PROFILE_HEIGHT * 100}%;width:0.75rem;height:0.75rem;margin:-0.375rem 0 0 -0.375rem;border-radius:999px;background:#fff;border:3px solid var(--_route);pointer-events:none`}
1590
+ ></span>
1591
+ <span
1592
+ part="profile-tooltip"
1593
+ style=${`left:${percent(cursorDistance)};${cursorDistance / profile.distanceM < 0.1 ? "transform:translate(0,-100%)" : cursorDistance / profile.distanceM > 0.9 ? "transform:translate(-100%,-100%)" : ""}`}
1594
+ >
1595
+ ${this.formatKm(cursorDistance, 1)} km · ${this.formatMetres(cursor.ele)}
1596
+ m${slope === null ? "" : ` · ${slope >= 0 ? "+" : ""}${Math.round(slope)} %`}
1597
+ </span>` : nothing}
1598
+ </div>
1599
+ ${levels.map((level) => html`<span
1600
+ class="axis axis-y"
1601
+ style=${`top:calc(0.6rem + (100% - 2.1rem) * ${y(level) / PROFILE_HEIGHT})`}
1602
+ >${this.formatMetres(Math.round(level / 10) * 10)} m</span
1603
+ >`)}
1604
+ <span class="axis axis-x first" style="left:2.6rem">0 km</span>
1605
+ ${ticks.map((km) => html`<span
1606
+ class="axis axis-x"
1607
+ style=${`left:calc(2.6rem + (100% - 3.5rem) * ${km * 1000 / profile.distanceM})`}
1608
+ >${km}</span
1609
+ >`)}
1610
+ <span class="axis axis-x last" style="left:calc(100% - 0.9rem)"
1611
+ >${this.formatKm(profile.distanceM)} km</span
1612
+ >
1613
+ </figure>`;
1614
+ }
1615
+ }
1616
+
1617
+ // src/ui/route-3d/index.ts
1618
+ function defineWodiraRouteElements2() {
1619
+ if (!globalThis.customElements)
1620
+ throw new Error("WODira route elements require a browser.");
1621
+ if (!customElements.get("wodira-route-3d"))
1622
+ customElements.define("wodira-route-3d", WodiraRoute3d2);
1623
+ }
1624
+
1625
+ export { parseGpx2, measureRoute2, pointAtDistance, bearing, distanceAtNearest, kilometreStep, routeBounds, isLoop, WodiraRoute3d2, defineWodiraRouteElements2 };