@m3ui-vue/m3ui-vue 1.0.2 → 1.0.3

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 (106) hide show
  1. package/dist/API.md +599 -9
  2. package/dist/MMenuItem-DFyXflk9.js +707 -0
  3. package/dist/MMenuItem-DFyXflk9.js.map +1 -0
  4. package/dist/MSlider-CdNIH7jc.js +1376 -0
  5. package/dist/MSlider-CdNIH7jc.js.map +1 -0
  6. package/dist/MTextField-B4X92vH_.js +671 -0
  7. package/dist/MTextField-B4X92vH_.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MIconButton.vue.d.ts +1 -1
  11. package/dist/components/MMap.vue.d.ts +74 -0
  12. package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
  13. package/dist/components/MMapControl.vue.d.ts +23 -0
  14. package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
  15. package/dist/components/MMapFilter.vue.d.ts +19 -0
  16. package/dist/components/MMapGeoJson.vue.d.ts +34 -0
  17. package/dist/components/MMapHover.vue.d.ts +17 -0
  18. package/dist/components/MMapIdentify.vue.d.ts +37 -0
  19. package/dist/components/MMapLayers.vue.d.ts +31 -0
  20. package/dist/components/MMapMarker.vue.d.ts +42 -0
  21. package/dist/components/MMapMeasure.vue.d.ts +43 -0
  22. package/dist/components/MMapPopup.vue.d.ts +43 -0
  23. package/dist/components/MMapSearch.vue.d.ts +28 -0
  24. package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
  25. package/dist/composables/_mapGeometry.d.ts +13 -0
  26. package/dist/composables/_ssrState.d.ts +30 -0
  27. package/dist/composables/_storageKeys.d.ts +3 -0
  28. package/dist/composables/_useThemeTokens.d.ts +7 -0
  29. package/dist/composables/mapAdapters.d.ts +111 -0
  30. package/dist/composables/mapSearch.d.ts +31 -0
  31. package/dist/composables/themeInitScript.d.ts +4 -3
  32. package/dist/composables/useColorPalette.d.ts +173 -7
  33. package/dist/composables/useLocale.d.ts +30 -0
  34. package/dist/composables/useMap.d.ts +47 -0
  35. package/dist/composables/useMapFilter.d.ts +10 -0
  36. package/dist/composables/useMapLayers.d.ts +30 -0
  37. package/dist/composables/useTheme.d.ts +2 -1
  38. package/dist/index.d.ts +2 -1
  39. package/dist/locales/index.js +217 -7
  40. package/dist/locales/index.js.map +1 -1
  41. package/dist/m3ui-vue.css +1 -1
  42. package/dist/m3ui.js +6709 -7976
  43. package/dist/m3ui.js.map +1 -1
  44. package/dist/map.d.ts +24 -0
  45. package/dist/map.js +1931 -0
  46. package/dist/map.js.map +1 -0
  47. package/dist/plugin.d.ts +18 -2
  48. package/dist/rich-text-editor.js +27 -26
  49. package/dist/rich-text-editor.js.map +1 -1
  50. package/dist/styles.css +1 -1
  51. package/dist/{useLocale-CuvWRZ1h.js → useLocale-b5-hzsL3.js} +32 -2
  52. package/dist/useLocale-b5-hzsL3.js.map +1 -0
  53. package/package.json +11 -2
  54. package/src/__tests__/MFab.test.ts +52 -6
  55. package/src/__tests__/MMap.test.ts +292 -0
  56. package/src/__tests__/MMapLayers.test.ts +257 -0
  57. package/src/__tests__/MMapTools.test.ts +233 -0
  58. package/src/__tests__/_fakeMaplibre.ts +158 -0
  59. package/src/__tests__/hydration.test.ts +33 -0
  60. package/src/__tests__/ssr.test.ts +63 -1
  61. package/src/__tests__/ssrState.test.ts +155 -0
  62. package/src/__tests__/themeInitScript.test.ts +18 -0
  63. package/src/components/MFab.vue +29 -7
  64. package/src/components/MIconButton.vue +1 -1
  65. package/src/components/MLightbox.vue +6 -2
  66. package/src/components/MMap.vue +522 -0
  67. package/src/components/MMapBaseLayers.vue +67 -0
  68. package/src/components/MMapControl.vue +61 -0
  69. package/src/components/MMapFeatureInfo.vue +41 -0
  70. package/src/components/MMapFilter.vue +80 -0
  71. package/src/components/MMapGeoJson.vue +136 -0
  72. package/src/components/MMapHover.vue +131 -0
  73. package/src/components/MMapIdentify.vue +103 -0
  74. package/src/components/MMapLayers.vue +111 -0
  75. package/src/components/MMapMarker.vue +102 -0
  76. package/src/components/MMapMeasure.vue +452 -0
  77. package/src/components/MMapPopup.vue +99 -0
  78. package/src/components/MMapSearch.vue +162 -0
  79. package/src/components/_MMapLayerItem.vue +77 -0
  80. package/src/composables/_mapGeometry.ts +75 -0
  81. package/src/composables/_ssrState.ts +80 -0
  82. package/src/composables/_storageKeys.ts +6 -0
  83. package/src/composables/_useThemeTokens.ts +42 -0
  84. package/src/composables/mapAdapters.ts +208 -0
  85. package/src/composables/mapSearch.ts +56 -0
  86. package/src/composables/themeInitScript.ts +6 -4
  87. package/src/composables/useColorPalette.ts +23 -9
  88. package/src/composables/useLocale.ts +62 -0
  89. package/src/composables/useMap.ts +98 -0
  90. package/src/composables/useMapFilter.ts +45 -0
  91. package/src/composables/useMapLayers.ts +124 -0
  92. package/src/composables/useTheme.ts +8 -3
  93. package/src/composables/useWindowSizeClass.ts +14 -5
  94. package/src/index.ts +2 -1
  95. package/src/locales/de.ts +31 -1
  96. package/src/locales/es.ts +31 -1
  97. package/src/locales/fr.ts +31 -1
  98. package/src/locales/ja.ts +31 -1
  99. package/src/locales/ko.ts +31 -1
  100. package/src/locales/pt.ts +31 -1
  101. package/src/locales/zh.ts +31 -1
  102. package/src/map.ts +32 -0
  103. package/src/plugin.ts +54 -3
  104. package/dist/MTextField-BPbFeI9M.js +0 -1368
  105. package/dist/MTextField-BPbFeI9M.js.map +0 -1
  106. package/dist/useLocale-CuvWRZ1h.js.map +0 -1
@@ -0,0 +1,522 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A MapLibre GL map, for any style: a style URL (from an MVT server like mvt-rs, MapTiler, OpenFreeMap…) or a style
4
+ * object. Its controls take the M3 look and the app's locale, the view can be a v-model and remembered between visits,
5
+ * and markers, popups, GeoJSON layers and your own controls go inside it as components. For anything else, the
6
+ * MapLibre map itself is the `ready` event's argument and the `map` of `useMap()` in components placed inside.
7
+ * Available from the `/map` entry point; needs `maplibre-gl` installed and its CSS imported
8
+ * (`maplibre-gl/dist/maplibre-gl.css`). Give it a height. Server-side rendering renders the empty container: MapLibre
9
+ * loads in the browser.
10
+ *
11
+ * @slot default Map components (`MMapMarker`, `MMapPopup`, `MMapGeoJson`, `MMapControl`) and anything to show over
12
+ * the map, rendered once the map exists
13
+ * @event ready The map loaded (with its style), with the MapLibre `Map`
14
+ * @event click A click on the map (MapLibre's `MapMouseEvent`: `lngLat`, `point`)
15
+ * @event update:center The view moved (on `moveend`): `[lng, lat]`
16
+ * @event update:zoom The zoom changed (on `moveend`)
17
+ * @event update:bearing The rotation changed (on `moveend`)
18
+ * @event update:pitch The tilt changed (on `moveend`)
19
+ */
20
+ import { markRaw, onBeforeUnmount, onMounted, onUnmounted, provide, ref, shallowRef, watch } from 'vue'
21
+ import type * as Maplibre from 'maplibre-gl'
22
+ import { useLocale } from '../composables/useLocale'
23
+ import { MAP_KEY, type MaplibreModule } from '../composables/useMap'
24
+ import { createLayerState, readLayerState } from '../composables/useMapLayers'
25
+ import type { MapAdapter, MapLayerModel } from '../composables/mapAdapters'
26
+
27
+ export type MapControlPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
28
+
29
+ const props = withDefaults(
30
+ defineProps<{
31
+ /** The map's style: a style JSON URL or a style object (MapLibre's `StyleSpecification`). Changing it reloads the style */
32
+ mapStyle: string | Maplibre.StyleSpecification
33
+ /** `[lng, lat]` (v-model). When left out, the style's (or the remembered view's) */
34
+ center?: [number, number]
35
+ /** Zoom level (v-model) */
36
+ zoom?: number
37
+ /** Rotation in degrees (v-model) */
38
+ bearing?: number
39
+ /** Tilt in degrees (v-model) */
40
+ pitch?: number
41
+ /**
42
+ * Remember the view (center, zoom, bearing, pitch) in localStorage and start from it on the next visit: `true`
43
+ * under `m3-map-view`, or your own key (one per map)
44
+ */
45
+ persist?: boolean | string
46
+ /** Zoom and compass buttons: `false`, or a corner (`true` is top-right) */
47
+ navigation?: boolean | MapControlPosition
48
+ /** A button that centers the map on the user's location and follows it: `false`, or a corner (`true` is top-right) */
49
+ geolocate?: boolean | MapControlPosition
50
+ /** A fullscreen button: `false`, or a corner (`true` is top-right) */
51
+ fullscreen?: boolean | MapControlPosition
52
+ /** A metric scale bar: `false`, or a corner (`true` is bottom-left) */
53
+ scale?: boolean | MapControlPosition
54
+ /** The style's attribution, compact: `false`, or a corner (`true` is bottom-right). Most tile providers require it */
55
+ attribution?: boolean | MapControlPosition
56
+ /** Anything else for MapLibre's `Map` constructor (`maxZoom`, `maxBounds`, `cooperativeGestures`…) */
57
+ options?: Partial<Omit<Maplibre.MapOptions, 'container' | 'style'>>
58
+ /**
59
+ * Reads the style's conventions (layer names, groups, base layers, what to identify or show on hover) for
60
+ * `MMapLayers`, `MMapBaseLayers`, `MMapIdentify` and `MMapHover`: `genericAdapter`, `orvianAdapter()`, or your own
61
+ */
62
+ adapter?: MapAdapter
63
+ }>(),
64
+ {
65
+ persist: false,
66
+ navigation: true,
67
+ geolocate: false,
68
+ fullscreen: false,
69
+ scale: true,
70
+ attribution: true,
71
+ },
72
+ )
73
+
74
+ const emit = defineEmits<{
75
+ ready: [map: Maplibre.Map]
76
+ click: [event: Maplibre.MapMouseEvent]
77
+ 'update:center': [center: [number, number]]
78
+ 'update:zoom': [zoom: number]
79
+ 'update:bearing': [bearing: number]
80
+ 'update:pitch': [pitch: number]
81
+ }>()
82
+
83
+ const root = ref<HTMLElement>()
84
+ const container = ref<HTMLElement>()
85
+ const map = shallowRef<Maplibre.Map>()
86
+ const maplibre = shallowRef<MaplibreModule>()
87
+ const styleVersion = ref(0)
88
+ const model = shallowRef<MapLayerModel>()
89
+ const layerState = createLayerState()
90
+ const activeTool = ref<string | null>(null)
91
+ provide(MAP_KEY, { map, maplibre, styleVersion, model, layerState, activeTool })
92
+
93
+ /** The adapter's model of the current style, and the layers' visibility and opacity in it. */
94
+ function readModel(m: Maplibre.Map) {
95
+ model.value = props.adapter
96
+ ? props.adapter(m.getStyle(), { styleUrl: typeof props.mapStyle === 'string' ? props.mapStyle : undefined })
97
+ : undefined
98
+ readLayerState(layerState, m, model.value)
99
+ }
100
+
101
+ const t = useLocale()
102
+
103
+ // ── Remembered view ────────────────────────────────────────────────────────────────────────────
104
+
105
+ interface View { center: [number, number]; zoom: number; bearing: number; pitch: number }
106
+ const persistKey = () => (typeof props.persist === 'string' ? props.persist : props.persist ? 'm3-map-view' : null)
107
+
108
+ function readView(): Partial<View> {
109
+ const key = persistKey()
110
+ if (!key) return {}
111
+ try {
112
+ const view = JSON.parse(localStorage.getItem(key) ?? 'null') as Partial<View> | null
113
+ return view && typeof view === 'object' ? view : {}
114
+ } catch {
115
+ return {}
116
+ }
117
+ }
118
+
119
+ function currentView(m: Maplibre.Map): View {
120
+ const c = m.getCenter()
121
+ return { center: [c.lng, c.lat], zoom: m.getZoom(), bearing: m.getBearing(), pitch: m.getPitch() }
122
+ }
123
+
124
+ // ── Controls ───────────────────────────────────────────────────────────────────────────────────
125
+
126
+ type ControlName = 'navigation' | 'geolocate' | 'fullscreen' | 'scale' | 'attribution'
127
+ const CONTROLS: Record<ControlName, { corner: MapControlPosition; create: (ml: MaplibreModule) => Maplibre.IControl }> = {
128
+ navigation: { corner: 'top-right', create: (ml) => new ml.NavigationControl() },
129
+ geolocate: {
130
+ corner: 'top-right',
131
+ create: (ml) => new ml.GeolocateControl({ positionOptions: { enableHighAccuracy: true }, trackUserLocation: true }),
132
+ },
133
+ fullscreen: { corner: 'top-right', create: (ml) => new ml.FullscreenControl({ container: root.value }) },
134
+ scale: { corner: 'bottom-left', create: (ml) => new ml.ScaleControl({ maxWidth: 100, unit: 'metric' }) },
135
+ attribution: { corner: 'bottom-right', create: (ml) => new ml.AttributionControl({ compact: true }) },
136
+ }
137
+ const added = new Map<ControlName, Maplibre.IControl>()
138
+
139
+ function syncControl(name: ControlName) {
140
+ const m = map.value
141
+ const ml = maplibre.value
142
+ if (!m || !ml) return
143
+ const old = added.get(name)
144
+ if (old) {
145
+ m.removeControl(old)
146
+ added.delete(name)
147
+ }
148
+ const setting = props[name]
149
+ if (!setting) return
150
+ const control = CONTROLS[name].create(ml)
151
+ m.addControl(control, setting === true ? CONTROLS[name].corner : setting)
152
+ added.set(name, control)
153
+ }
154
+
155
+ for (const name of Object.keys(CONTROLS) as ControlName[]) watch(() => props[name], () => syncControl(name))
156
+
157
+ // ── Map ────────────────────────────────────────────────────────────────────────────────────────
158
+
159
+ /** MapLibre's UI strings, from the app's M3 locale. */
160
+ function mapLocale() {
161
+ return {
162
+ 'AttributionControl.ToggleAttribution': t.mapToggleAttribution,
163
+ 'AttributionControl.MapFeedback': t.mapFeedback,
164
+ 'FullscreenControl.Enter': t.mapEnterFullscreen,
165
+ 'FullscreenControl.Exit': t.mapExitFullscreen,
166
+ 'GeolocateControl.FindMyLocation': t.mapFindMyLocation,
167
+ 'GeolocateControl.LocationNotAvailable': t.mapLocationNotAvailable,
168
+ 'Map.Title': t.mapTitle,
169
+ 'Marker.Title': t.mapMarker,
170
+ 'NavigationControl.ResetBearing': t.mapResetBearing,
171
+ 'NavigationControl.ZoomIn': t.mapZoomIn,
172
+ 'NavigationControl.ZoomOut': t.mapZoomOut,
173
+ 'Popup.Close': t.close,
174
+ 'CooperativeGesturesHandler.WindowsHelpText': t.mapCtrlScroll,
175
+ 'CooperativeGesturesHandler.MacHelpText': t.mapCmdScroll,
176
+ 'CooperativeGesturesHandler.MobileHelpText': t.mapTwoFingers,
177
+ }
178
+ }
179
+
180
+ // ── Control tooltips ───────────────────────────────────────────────────────────────────────────
181
+ // MapLibre's buttons (and yours, in MMapControl) carry a `title`, which the browser shows as its own tooltip: it's
182
+ // moved to data-m3-tip (and aria-label when there's none) and shown as an M3 plain tooltip, inside the map so it's
183
+ // there in fullscreen too
184
+
185
+ const TIP_DELAY = 600 // MTooltip's
186
+ const tip = ref<{ text: string; x: number; y: number; left: boolean } | null>(null)
187
+ let tipTimer: ReturnType<typeof setTimeout> | undefined
188
+ let tipObserver: MutationObserver | undefined
189
+
190
+ function adoptTitle(el: Element) {
191
+ const title = el.getAttribute('title')
192
+ if (!title || !el.closest('.maplibregl-ctrl')) return
193
+ el.setAttribute('data-m3-tip', title)
194
+ if (!el.hasAttribute('aria-label')) el.setAttribute('aria-label', title)
195
+ el.removeAttribute('title')
196
+ }
197
+
198
+ function showTip(el: HTMLElement) {
199
+ const text = el.getAttribute('data-m3-tip')
200
+ const box = root.value?.getBoundingClientRect()
201
+ if (!text || !box) return
202
+ const r = el.getBoundingClientRect()
203
+ // Toward the inside of the map: left of a control on the right half, right of one on the left
204
+ const left = r.left + r.width / 2 > box.left + box.width / 2
205
+ tip.value = { text, left, x: (left ? r.left - 8 : r.right + 8) - box.left, y: r.top + r.height / 2 - box.top }
206
+ }
207
+
208
+ function hideTip() {
209
+ clearTimeout(tipTimer)
210
+ tip.value = null
211
+ }
212
+
213
+ const tipTarget = (e: Event) => (e.target as Element | null)?.closest?.<HTMLElement>('.maplibregl-ctrl [data-m3-tip]') ?? null
214
+
215
+ function onTipOver(e: PointerEvent) {
216
+ const el = tipTarget(e)
217
+ if (!el || e.pointerType === 'touch') return
218
+ clearTimeout(tipTimer)
219
+ tipTimer = setTimeout(() => showTip(el), TIP_DELAY)
220
+ }
221
+ function onTipOut(e: PointerEvent) {
222
+ const el = tipTarget(e)
223
+ if (el && !el.contains(e.relatedTarget as Node | null)) hideTip()
224
+ }
225
+ function onTipFocus(e: FocusEvent) {
226
+ const el = tipTarget(e)
227
+ if (el?.matches(':focus-visible')) showTip(el)
228
+ }
229
+
230
+ onMounted(() => {
231
+ const el = root.value
232
+ if (!el) return
233
+ el.querySelectorAll('[title]').forEach(adoptTitle)
234
+ tipObserver = new MutationObserver((records) => {
235
+ for (const r of records) {
236
+ if (r.type === 'attributes') adoptTitle(r.target as Element)
237
+ else r.addedNodes.forEach((n) => {
238
+ if (!(n instanceof Element)) return
239
+ adoptTitle(n)
240
+ n.querySelectorAll('[title]').forEach(adoptTitle)
241
+ })
242
+ }
243
+ })
244
+ tipObserver.observe(el, { subtree: true, childList: true, attributes: true, attributeFilter: ['title'] })
245
+ })
246
+
247
+ onBeforeUnmount(() => {
248
+ tipObserver?.disconnect()
249
+ clearTimeout(tipTimer)
250
+ })
251
+
252
+ let destroyed = false
253
+
254
+ onMounted(async () => {
255
+ // maplibre-gl ships a UMD build: depending on the bundler its classes are on the namespace or on `default`
256
+ const mod = await import('maplibre-gl')
257
+ const ml = ('Map' in mod ? mod : (mod as { default: MaplibreModule }).default) as MaplibreModule
258
+ if (destroyed || !container.value) return
259
+ const saved = readView()
260
+ const view = {
261
+ center: saved.center ?? props.center,
262
+ zoom: saved.zoom ?? props.zoom,
263
+ bearing: saved.bearing ?? props.bearing,
264
+ pitch: saved.pitch ?? props.pitch,
265
+ }
266
+ const m = markRaw(new ml.Map({
267
+ container: container.value,
268
+ style: props.mapStyle,
269
+ attributionControl: false,
270
+ locale: mapLocale(),
271
+ // Only what's set, so a style's own center and zoom apply otherwise
272
+ ...Object.fromEntries(Object.entries(view).filter(([, v]) => v !== undefined)),
273
+ ...props.options,
274
+ }))
275
+ maplibre.value = ml
276
+
277
+ m.on('style.load', () => {
278
+ readModel(m)
279
+ styleVersion.value++
280
+ })
281
+ m.on('click', (e) => emit('click', e))
282
+ m.on('moveend', () => {
283
+ const v = currentView(m)
284
+ emit('update:center', v.center)
285
+ emit('update:zoom', v.zoom)
286
+ emit('update:bearing', v.bearing)
287
+ emit('update:pitch', v.pitch)
288
+ const key = persistKey()
289
+ if (key) {
290
+ try { localStorage.setItem(key, JSON.stringify(v)) } catch { /* storage blocked */ }
291
+ }
292
+ })
293
+ m.once('load', () => {
294
+ // The map is shared once its style is loaded: components can add sources and layers right away
295
+ map.value = m
296
+ for (const name of Object.keys(CONTROLS) as ControlName[]) syncControl(name)
297
+ emit('ready', m)
298
+ })
299
+ })
300
+
301
+ // After the children's unmount hooks (a parent's beforeUnmount runs before theirs): they remove their layers, markers
302
+ // and controls from a map that still exists
303
+ onUnmounted(() => {
304
+ destroyed = true
305
+ map.value?.remove()
306
+ map.value = undefined
307
+ })
308
+
309
+ // ── v-model ────────────────────────────────────────────────────────────────────────────────────
310
+ // Compared by value: an inline `:center="[lng, lat]"` is a new array on every parent render
311
+
312
+ const near = (a: number, b: number) => Math.abs(a - b) < 1e-9
313
+ watch(() => props.center?.join(','), () => {
314
+ const m = map.value
315
+ if (!m || !props.center) return
316
+ const c = m.getCenter()
317
+ if (!near(c.lng, props.center[0]) || !near(c.lat, props.center[1])) m.jumpTo({ center: props.center })
318
+ })
319
+ watch(() => props.zoom, (zoom) => {
320
+ if (map.value && zoom !== undefined && !near(map.value.getZoom(), zoom)) map.value.jumpTo({ zoom })
321
+ })
322
+ watch(() => props.bearing, (bearing) => {
323
+ if (map.value && bearing !== undefined && !near(map.value.getBearing(), bearing)) map.value.jumpTo({ bearing })
324
+ })
325
+ watch(() => props.pitch, (pitch) => {
326
+ if (map.value && pitch !== undefined && !near(map.value.getPitch(), pitch)) map.value.jumpTo({ pitch })
327
+ })
328
+ watch(() => props.adapter, () => { if (map.value) readModel(map.value) })
329
+ // A full reload (no diff): style.load fires, and components re-add their sources and layers
330
+ watch(() => props.mapStyle, (style) => map.value?.setStyle(style, { diff: false }))
331
+
332
+ defineExpose({
333
+ /** The MapLibre map, once loaded */
334
+ map,
335
+ })
336
+ </script>
337
+
338
+ <template>
339
+ <div
340
+ ref="root"
341
+ class="m3-map relative overflow-hidden"
342
+ @pointerover="onTipOver"
343
+ @pointerout="onTipOut"
344
+ @pointerdown="hideTip"
345
+ @focusin="onTipFocus"
346
+ @focusout="hideTip"
347
+ >
348
+ <!-- Sized, not positioned: MapLibre's CSS makes it position: relative (.maplibregl-map), which would undo absolute -->
349
+ <div ref="container" class="h-full w-full" />
350
+ <slot v-if="map" />
351
+ <Transition
352
+ enter-active-class="transition-opacity duration-150"
353
+ enter-from-class="opacity-0"
354
+ leave-active-class="transition-opacity duration-100"
355
+ leave-to-class="opacity-0"
356
+ >
357
+ <div
358
+ v-if="tip"
359
+ role="tooltip"
360
+ class="pointer-events-none absolute z-10 min-h-6 max-w-[200px] -translate-y-1/2 rounded bg-inverse-surface px-2 py-1 text-body-small whitespace-nowrap text-inverse-on-surface"
361
+ :class="tip.left ? '-translate-x-full' : ''"
362
+ :style="{ left: `${tip.x}px`, top: `${tip.y}px` }"
363
+ >
364
+ {{ tip.text }}
365
+ </div>
366
+ </Transition>
367
+ </div>
368
+ </template>
369
+
370
+ <style>
371
+ /* The app's typeface, not MapLibre's Helvetica (attribution, scale, popups) */
372
+ .m3-map .maplibregl-map {
373
+ font: inherit;
374
+ }
375
+
376
+ /* MapLibre's controls, popups and markers in M3: the theme's colors (they follow palette and dark mode), Material
377
+ Symbols icons instead of MapLibre's fixed-color SVGs, M3 shapes and elevation. Scoped to .m3-map. */
378
+ .m3-map .maplibregl-ctrl-group {
379
+ background: var(--color-surface-container-high);
380
+ border-radius: 12px;
381
+ box-shadow: var(--shadow-elevation-2);
382
+ overflow: hidden;
383
+ }
384
+ .m3-map .maplibregl-ctrl-group:not(:empty) {
385
+ box-shadow: var(--shadow-elevation-2);
386
+ }
387
+ .m3-map .maplibregl-ctrl-group button {
388
+ width: 40px;
389
+ height: 40px;
390
+ color: var(--color-on-surface-variant);
391
+ }
392
+ .m3-map .maplibregl-ctrl-group button + button {
393
+ border-top: 1px solid var(--color-outline-variant);
394
+ }
395
+ .m3-map .maplibregl-ctrl button:not(:disabled):hover {
396
+ background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
397
+ }
398
+ .m3-map .maplibregl-ctrl button:not(:disabled):active {
399
+ background-color: color-mix(in srgb, var(--color-on-surface) 12%, transparent);
400
+ }
401
+ .m3-map .maplibregl-ctrl-group button[aria-pressed='true'] {
402
+ background-color: var(--color-primary-container);
403
+ color: var(--color-on-primary-container);
404
+ }
405
+ .m3-map .maplibregl-ctrl button:focus-visible {
406
+ box-shadow: inset 0 0 0 2px var(--color-secondary);
407
+ }
408
+ .m3-map .maplibregl-ctrl button:disabled {
409
+ color: color-mix(in srgb, var(--color-on-surface) 38%, transparent);
410
+ }
411
+ .m3-map .maplibregl-ctrl button .maplibregl-ctrl-icon {
412
+ display: flex;
413
+ align-items: center;
414
+ justify-content: center;
415
+ background-image: none !important;
416
+ }
417
+ .m3-map .maplibregl-ctrl button .maplibregl-ctrl-icon::before,
418
+ .m3-map .maplibregl-ctrl-attrib-button::before {
419
+ font-family: 'Material Symbols Outlined';
420
+ font-size: 20px;
421
+ line-height: 1;
422
+ font-feature-settings: 'liga';
423
+ -webkit-font-smoothing: antialiased;
424
+ }
425
+ .m3-map .maplibregl-ctrl-zoom-in .maplibregl-ctrl-icon::before { content: 'add'; }
426
+ .m3-map .maplibregl-ctrl-zoom-out .maplibregl-ctrl-icon::before { content: 'remove'; }
427
+ .m3-map .maplibregl-ctrl-compass .maplibregl-ctrl-icon::before { content: 'navigation'; }
428
+ .m3-map .maplibregl-ctrl-geolocate .maplibregl-ctrl-icon::before { content: 'my_location'; }
429
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-active,
430
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background,
431
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-waiting {
432
+ color: var(--color-primary);
433
+ }
434
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background .maplibregl-ctrl-icon::before { content: 'location_searching'; }
435
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-active-error,
436
+ .m3-map .maplibregl-ctrl-geolocate.maplibregl-ctrl-geolocate-background-error {
437
+ color: var(--color-error);
438
+ }
439
+ .m3-map .maplibregl-ctrl-geolocate:disabled .maplibregl-ctrl-icon::before { content: 'location_disabled'; }
440
+ .m3-map .maplibregl-ctrl-fullscreen .maplibregl-ctrl-icon::before { content: 'fullscreen'; }
441
+ .m3-map .maplibregl-ctrl-shrink .maplibregl-ctrl-icon::before { content: 'fullscreen_exit'; }
442
+
443
+ /* Compact attribution: a surface pill with an info button */
444
+ .m3-map .maplibregl-ctrl-attrib {
445
+ background: color-mix(in srgb, var(--color-surface-container-high) 90%, transparent);
446
+ color: var(--color-on-surface-variant);
447
+ }
448
+ .m3-map .maplibregl-ctrl-attrib a {
449
+ color: inherit;
450
+ }
451
+ .m3-map .maplibregl-ctrl-attrib.maplibregl-compact {
452
+ min-height: 28px;
453
+ border-radius: 14px;
454
+ }
455
+ .m3-map .maplibregl-ctrl-attrib-button {
456
+ display: flex;
457
+ align-items: center;
458
+ justify-content: center;
459
+ width: 28px;
460
+ height: 28px;
461
+ border-radius: 14px;
462
+ background: none !important;
463
+ color: var(--color-on-surface-variant);
464
+ }
465
+ .m3-map .maplibregl-ctrl-attrib-button::before {
466
+ content: 'info';
467
+ font-size: 18px;
468
+ }
469
+ .m3-map .maplibregl-ctrl-scale {
470
+ background: color-mix(in srgb, var(--color-surface-container-high) 85%, transparent);
471
+ border-color: var(--color-outline);
472
+ color: var(--color-on-surface-variant);
473
+ font-size: 11px;
474
+ }
475
+
476
+ /* Popups: an M3 surface (elevation 2, 16px corners) with a matching tip */
477
+ .m3-map .maplibregl-popup-content {
478
+ padding: 12px 16px;
479
+ border-radius: 16px;
480
+ background: var(--color-surface-container-high);
481
+ color: var(--color-on-surface);
482
+ box-shadow: var(--shadow-elevation-2);
483
+ overflow: hidden;
484
+ font: inherit;
485
+ font-size: var(--text-body-medium);
486
+ line-height: var(--text-body-medium--line-height);
487
+ }
488
+ .m3-map .maplibregl-popup-anchor-top .maplibregl-popup-tip,
489
+ .m3-map .maplibregl-popup-anchor-top-left .maplibregl-popup-tip,
490
+ .m3-map .maplibregl-popup-anchor-top-right .maplibregl-popup-tip {
491
+ border-bottom-color: var(--color-surface-container-high);
492
+ }
493
+ .m3-map .maplibregl-popup-anchor-bottom .maplibregl-popup-tip,
494
+ .m3-map .maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip,
495
+ .m3-map .maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip {
496
+ border-top-color: var(--color-surface-container-high);
497
+ }
498
+ .m3-map .maplibregl-popup-anchor-left .maplibregl-popup-tip {
499
+ border-right-color: var(--color-surface-container-high);
500
+ }
501
+ .m3-map .maplibregl-popup-anchor-right .maplibregl-popup-tip {
502
+ border-left-color: var(--color-surface-container-high);
503
+ }
504
+ .m3-map .maplibregl-popup-close-button {
505
+ top: 6px;
506
+ right: 6px;
507
+ width: 28px;
508
+ height: 28px;
509
+ border-radius: 14px;
510
+ color: var(--color-on-surface-variant);
511
+ font-size: 18px;
512
+ line-height: 1;
513
+ }
514
+ .m3-map .maplibregl-popup-close-button:hover {
515
+ background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
516
+ }
517
+
518
+ /* The default marker takes the theme's primary (its SVG is drawn in currentColor) */
519
+ .m3-map .m3-map-marker--default {
520
+ color: var(--color-primary);
521
+ }
522
+ </style>
@@ -0,0 +1,67 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * The base layer switcher of an `MMap` with an `adapter`: a round thumbnail per base layer (the adapter's `image`,
4
+ * after `imageBase`), one shown at a time, plus "no base layer". Only the thumbnails: put them in an `MMapControl`
5
+ * (`:group="false"`), an `MFab`'s `#content` or a panel. Available from the `/map` entry point.
6
+ */
7
+ import MIcon from './MIcon.vue'
8
+ import { useLocale } from '../composables/useLocale'
9
+ import { useMapLayers } from '../composables/useMapLayers'
10
+
11
+ withDefaults(
12
+ defineProps<{
13
+ /** Prefix for the thumbnails' paths (e.g. `/images/`); full URLs are used as they are */
14
+ imageBase?: string
15
+ /** Offer "no base layer" */
16
+ none?: boolean
17
+ /** Lay them out in a column */
18
+ vertical?: boolean
19
+ }>(),
20
+ { imageBase: '', none: true, vertical: false },
21
+ )
22
+
23
+ const t = useLocale()
24
+ const { baseLayers, baseLayer, setBaseLayer } = useMapLayers()
25
+
26
+ const src = (image: string, base: string) => (/^(https?:|data:|\/\/)/.test(image) ? image : `${base}${image}`)
27
+ </script>
28
+
29
+ <template>
30
+ <div class="flex gap-2" :class="vertical ? 'flex-col' : 'flex-row flex-wrap'" role="radiogroup">
31
+ <button
32
+ v-for="layer in baseLayers"
33
+ :key="layer.id"
34
+ type="button"
35
+ role="radio"
36
+ class="m3-map-base grid size-12 shrink-0 cursor-pointer place-items-center overflow-hidden rounded-full border-2 bg-surface-variant transition-[border-color,transform] duration-150 hover:scale-110"
37
+ :class="baseLayer === layer.id ? 'm3-map-base--active border-primary' : 'border-transparent'"
38
+ :title="layer.title"
39
+ :aria-label="layer.title"
40
+ :aria-checked="baseLayer === layer.id"
41
+ @click="setBaseLayer(layer.id)"
42
+ >
43
+ <img v-if="layer.base?.image" :src="src(layer.base.image, imageBase)" alt="" class="size-full object-cover">
44
+ <MIcon v-else name="map" :size="22" class="text-on-surface-variant" />
45
+ </button>
46
+ <button
47
+ v-if="none"
48
+ type="button"
49
+ role="radio"
50
+ class="m3-map-base grid size-12 shrink-0 cursor-pointer place-items-center rounded-full border-2 bg-surface-variant transition-[border-color,transform] duration-150 hover:scale-110"
51
+ :class="baseLayer === null ? 'm3-map-base--active border-primary' : 'border-transparent'"
52
+ :title="t.mapNoBaseLayer"
53
+ :aria-label="t.mapNoBaseLayer"
54
+ :aria-checked="baseLayer === null"
55
+ @click="setBaseLayer(null)"
56
+ >
57
+ <MIcon name="layers_clear" :size="22" class="text-on-surface-variant" />
58
+ </button>
59
+ </div>
60
+ </template>
61
+
62
+ <style>
63
+ /* Inactive thumbnails in gray, the active one in color */
64
+ .m3-map-base:not(.m3-map-base--active) img {
65
+ filter: grayscale(1) opacity(0.6);
66
+ }
67
+ </style>
@@ -0,0 +1,61 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Your own control in a corner of an `MMap`, stacked with MapLibre's (zoom, geolocate…) in that corner. With `group`
4
+ * (the default) it's a control group like the zoom buttons: put `<button>`s with a Material Symbols icon in it and
5
+ * they get the same M3 look. Without it, anything goes (an `MFab`, an `MSearchBar`, a card). Available from the
6
+ * `/map` entry point.
7
+ *
8
+ * @slot default The control's content
9
+ */
10
+ import { onBeforeUnmount, ref, watch } from 'vue'
11
+ import type * as Maplibre from 'maplibre-gl'
12
+ import { useMap } from '../composables/useMap'
13
+ import type { MapControlPosition } from './MMap.vue'
14
+
15
+ // Attributes (class, style…) go on what's shown on the map, not on the hidden wrapper it's rendered in
16
+ defineOptions({ inheritAttrs: false })
17
+
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ /** The corner */
21
+ position?: MapControlPosition
22
+ /** Draw it as a control group (a surface with dividers between buttons), like MapLibre's zoom buttons */
23
+ group?: boolean
24
+ }>(),
25
+ { position: 'top-right', group: true },
26
+ )
27
+
28
+ const el = ref<HTMLElement>()
29
+ const { onReady } = useMap()
30
+
31
+ let map: Maplibre.Map | undefined
32
+ // MapLibre's IControl: the element it places in the corner
33
+ const control: Maplibre.IControl = {
34
+ onAdd: () => el.value!,
35
+ onRemove: () => el.value?.remove(),
36
+ }
37
+
38
+ onReady((m) => {
39
+ map = m
40
+ if (el.value) m.addControl(control, props.position)
41
+ })
42
+
43
+ watch(() => props.position, (position) => {
44
+ if (!map || !el.value) return
45
+ map.removeControl(control)
46
+ map.addControl(control, position)
47
+ })
48
+
49
+ onBeforeUnmount(() => {
50
+ if (map?.hasControl(control)) map.removeControl(control)
51
+ })
52
+ </script>
53
+
54
+ <template>
55
+ <!-- Moved into the map's corner by MapLibre -->
56
+ <div class="hidden">
57
+ <div ref="el" class="maplibregl-ctrl" :class="group ? 'maplibregl-ctrl-group' : ''" v-bind="$attrs">
58
+ <slot />
59
+ </div>
60
+ </div>
61
+ </template>
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Identify results (from `MMapIdentify`'s `identify` event, or `identifyFeatures()`): a card per feature with its
4
+ * layer's name and its formatted properties. `MMapIdentify` shows it in a popup; use it in a panel of your own (an
5
+ * `MWindow`, an `MSideSheet`) the same way. Values are shown as text. Available from the `/map` entry point.
6
+ *
7
+ * @slot value A property's value (scope: `{ field, result }`), e.g. to turn URLs into links
8
+ */
9
+ import MIcon from './MIcon.vue'
10
+ import { useLocale } from '../composables/useLocale'
11
+ import type { MapIdentifyResult } from '../composables/mapAdapters'
12
+
13
+ defineProps<{
14
+ /** What was found */
15
+ results: MapIdentifyResult[]
16
+ }>()
17
+
18
+ const t = useLocale()
19
+ </script>
20
+
21
+ <template>
22
+ <div class="flex flex-col gap-2">
23
+ <div v-for="(result, i) in results" :key="i" class="overflow-hidden rounded-2xl bg-surface-container">
24
+ <div class="flex items-center gap-2 bg-primary-container/40 px-4 py-2">
25
+ <MIcon name="layers" :size="16" class="text-on-primary-container" />
26
+ <span class="text-label-large text-on-primary-container">{{ result.layer.title }}</span>
27
+ </div>
28
+ <dl class="flex flex-col px-4 py-1">
29
+ <div v-for="field in result.fields" :key="field.key" class="flex flex-col gap-0.5 border-b border-outline-variant py-1.5 last:border-b-0">
30
+ <dt class="text-label-small text-on-surface-variant">{{ field.label }}</dt>
31
+ <dd class="text-body-medium text-on-surface">
32
+ <slot name="value" :field="field" :result="result">
33
+ <span v-if="field.value" class="break-words">{{ field.value }}</span>
34
+ <span v-else class="text-body-small italic text-on-surface-variant">{{ t.mapNoValue }}</span>
35
+ </slot>
36
+ </dd>
37
+ </div>
38
+ </dl>
39
+ </div>
40
+ </div>
41
+ </template>