@m3ui-vue/m3ui-vue 1.0.2 → 1.1.0

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 (157) hide show
  1. package/dist/API.md +666 -12
  2. package/dist/MMenuItem-BOkcVtEe.js +809 -0
  3. package/dist/MMenuItem-BOkcVtEe.js.map +1 -0
  4. package/dist/MSlider-BXsBv0ox.js +1402 -0
  5. package/dist/MSlider-BXsBv0ox.js.map +1 -0
  6. package/dist/MTextField-rML9jnXs.js +671 -0
  7. package/dist/MTextField-rML9jnXs.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +1 -1
  10. package/dist/components/MBottomSheet.vue.d.ts +20 -1
  11. package/dist/components/MDialog.vue.d.ts +17 -8
  12. package/dist/components/MDragDropList.vue.d.ts +1 -1
  13. package/dist/components/MIconButton.vue.d.ts +1 -1
  14. package/dist/components/MMap.vue.d.ts +74 -0
  15. package/dist/components/MMapBaseLayers.vue.d.ts +15 -0
  16. package/dist/components/MMapControl.vue.d.ts +40 -0
  17. package/dist/components/MMapFeatureInfo.vue.d.ts +25 -0
  18. package/dist/components/MMapFilter.vue.d.ts +19 -0
  19. package/dist/components/MMapGeoJson.vue.d.ts +34 -0
  20. package/dist/components/MMapHover.vue.d.ts +17 -0
  21. package/dist/components/MMapIdentify.vue.d.ts +37 -0
  22. package/dist/components/MMapLayers.vue.d.ts +31 -0
  23. package/dist/components/MMapMarker.vue.d.ts +45 -0
  24. package/dist/components/MMapMeasure.vue.d.ts +43 -0
  25. package/dist/components/MMapPopup.vue.d.ts +45 -0
  26. package/dist/components/MMapSearch.vue.d.ts +28 -0
  27. package/dist/components/MMenuItem.vue.d.ts +2 -2
  28. package/dist/components/MSeekBar.vue.d.ts +122 -0
  29. package/dist/components/MSplitButton.vue.d.ts +2 -2
  30. package/dist/components/_MMapAttribution.vue.d.ts +7 -0
  31. package/dist/components/_MMapLayerItem.vue.d.ts +25 -0
  32. package/dist/composables/_mapGeometry.d.ts +13 -0
  33. package/dist/composables/_mapPin.d.ts +5 -0
  34. package/dist/composables/_popupPosition.d.ts +12 -0
  35. package/dist/composables/_ssrState.d.ts +30 -0
  36. package/dist/composables/_storageKeys.d.ts +3 -0
  37. package/dist/composables/_useCalendarMonth.d.ts +24 -0
  38. package/dist/composables/_useEscapeStack.d.ts +3 -0
  39. package/dist/composables/_useScrollLock.d.ts +8 -0
  40. package/dist/composables/_useSheetMotion.d.ts +16 -1
  41. package/dist/composables/_useThemeTokens.d.ts +7 -0
  42. package/dist/composables/mapAdapters.d.ts +111 -0
  43. package/dist/composables/mapSearch.d.ts +31 -0
  44. package/dist/composables/themeInitScript.d.ts +4 -3
  45. package/dist/composables/useColorPalette.d.ts +173 -7
  46. package/dist/composables/useLocale.d.ts +38 -0
  47. package/dist/composables/useMap.d.ts +47 -0
  48. package/dist/composables/useMapFilter.d.ts +10 -0
  49. package/dist/composables/useMapLayers.d.ts +30 -0
  50. package/dist/composables/useTheme.d.ts +2 -1
  51. package/dist/index.d.ts +4 -1
  52. package/dist/locales/index.js +273 -7
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/m3ui-vue.css +1 -1
  55. package/dist/m3ui.js +7913 -8625
  56. package/dist/m3ui.js.map +1 -1
  57. package/dist/map.d.ts +24 -0
  58. package/dist/map.js +2067 -0
  59. package/dist/map.js.map +1 -0
  60. package/dist/plugin.d.ts +18 -2
  61. package/dist/rich-text-editor.js +26 -25
  62. package/dist/rich-text-editor.js.map +1 -1
  63. package/dist/styles.css +1 -1
  64. package/dist/{useLocale-CuvWRZ1h.js → useLocale-CqQrhWFl.js} +40 -2
  65. package/dist/useLocale-CqQrhWFl.js.map +1 -0
  66. package/package.json +11 -2
  67. package/src/__tests__/MDialog.test.ts +30 -0
  68. package/src/__tests__/MFab.test.ts +52 -6
  69. package/src/__tests__/MMap.test.ts +422 -0
  70. package/src/__tests__/MMapLayers.test.ts +257 -0
  71. package/src/__tests__/MMapTools.test.ts +233 -0
  72. package/src/__tests__/MSeekBar.test.ts +170 -0
  73. package/src/__tests__/MTooltip.test.ts +110 -0
  74. package/src/__tests__/_fakeMaplibre.ts +161 -0
  75. package/src/__tests__/calendarMonth.test.ts +59 -0
  76. package/src/__tests__/hydration.test.ts +33 -0
  77. package/src/__tests__/pickerModals.test.ts +128 -0
  78. package/src/__tests__/popupPosition.test.ts +224 -0
  79. package/src/__tests__/scrollLock.test.ts +110 -0
  80. package/src/__tests__/sheets.test.ts +158 -0
  81. package/src/__tests__/ssr.test.ts +63 -1
  82. package/src/__tests__/ssrState.test.ts +155 -0
  83. package/src/__tests__/themeInitScript.test.ts +18 -0
  84. package/src/components/MAutocomplete.vue +2 -4
  85. package/src/components/MBottomSheet.vue +211 -13
  86. package/src/components/MCommandPalette.vue +4 -6
  87. package/src/components/MContextMenu.vue +19 -5
  88. package/src/components/MDatePicker.vue +29 -70
  89. package/src/components/MDatePickerModal.vue +116 -172
  90. package/src/components/MDateRangePicker.vue +29 -51
  91. package/src/components/MDateRangePickerModal.vue +84 -162
  92. package/src/components/MDialog.vue +87 -63
  93. package/src/components/MFab.vue +29 -7
  94. package/src/components/MIconButton.vue +1 -1
  95. package/src/components/MLightbox.vue +12 -5
  96. package/src/components/MMap.vue +568 -0
  97. package/src/components/MMapBaseLayers.vue +67 -0
  98. package/src/components/MMapControl.vue +175 -0
  99. package/src/components/MMapFeatureInfo.vue +41 -0
  100. package/src/components/MMapFilter.vue +80 -0
  101. package/src/components/MMapGeoJson.vue +136 -0
  102. package/src/components/MMapHover.vue +131 -0
  103. package/src/components/MMapIdentify.vue +104 -0
  104. package/src/components/MMapLayers.vue +111 -0
  105. package/src/components/MMapMarker.vue +109 -0
  106. package/src/components/MMapMeasure.vue +452 -0
  107. package/src/components/MMapPopup.vue +103 -0
  108. package/src/components/MMapSearch.vue +162 -0
  109. package/src/components/MMenu.vue +31 -12
  110. package/src/components/MMenuItem.vue +21 -4
  111. package/src/components/MMultiAutocomplete.vue +2 -4
  112. package/src/components/MMultiSelect.vue +2 -4
  113. package/src/components/MNavigationDrawer.vue +2 -8
  114. package/src/components/MNavigationRail.vue +2 -3
  115. package/src/components/MSearchBar.vue +2 -5
  116. package/src/components/MSeekBar.vue +593 -0
  117. package/src/components/MSelect.vue +2 -8
  118. package/src/components/MSplitButton.vue +23 -7
  119. package/src/components/MSpotlightSearch.vue +4 -6
  120. package/src/components/MTimePicker.vue +23 -6
  121. package/src/components/MTimePickerModal.vue +213 -226
  122. package/src/components/MTooltip.vue +99 -3
  123. package/src/components/_MMapAttribution.vue +81 -0
  124. package/src/components/_MMapLayerItem.vue +77 -0
  125. package/src/composables/_mapGeometry.ts +75 -0
  126. package/src/composables/_mapPin.ts +25 -0
  127. package/src/composables/_popupPosition.ts +39 -0
  128. package/src/composables/_ssrState.ts +80 -0
  129. package/src/composables/_storageKeys.ts +6 -0
  130. package/src/composables/_useCalendarMonth.ts +74 -0
  131. package/src/composables/_useEscapeStack.ts +33 -0
  132. package/src/composables/_useScrollLock.ts +41 -0
  133. package/src/composables/_useSheetMotion.ts +82 -20
  134. package/src/composables/_useThemeTokens.ts +42 -0
  135. package/src/composables/mapAdapters.ts +208 -0
  136. package/src/composables/mapSearch.ts +56 -0
  137. package/src/composables/themeInitScript.ts +6 -4
  138. package/src/composables/useColorPalette.ts +23 -9
  139. package/src/composables/useLocale.ts +78 -0
  140. package/src/composables/useMap.ts +98 -0
  141. package/src/composables/useMapFilter.ts +45 -0
  142. package/src/composables/useMapLayers.ts +124 -0
  143. package/src/composables/useTheme.ts +8 -3
  144. package/src/composables/useWindowSizeClass.ts +14 -5
  145. package/src/index.ts +4 -1
  146. package/src/locales/de.ts +39 -1
  147. package/src/locales/es.ts +39 -1
  148. package/src/locales/fr.ts +39 -1
  149. package/src/locales/ja.ts +39 -1
  150. package/src/locales/ko.ts +39 -1
  151. package/src/locales/pt.ts +39 -1
  152. package/src/locales/zh.ts +39 -1
  153. package/src/map.ts +32 -0
  154. package/src/plugin.ts +54 -3
  155. package/dist/MTextField-BPbFeI9M.js +0 -1368
  156. package/dist/MTextField-BPbFeI9M.js.map +0 -1
  157. package/dist/useLocale-CuvWRZ1h.js.map +0 -1
@@ -38,6 +38,10 @@ export interface M3Locale {
38
38
 
39
39
  // Pickers
40
40
  selectDate: string
41
+ ok: string
42
+ dateToggleInput: string
43
+ dateToggleCalendar: string
44
+ dateInputLabel: string
41
45
  selectTime: string
42
46
  timeHourSelection: string
43
47
  timeMinuteSelection: string
@@ -48,6 +52,10 @@ export interface M3Locale {
48
52
  sheetExpand: string
49
53
  sheetCollapse: string
50
54
  sheetDismiss: string
55
+ seekBar: string
56
+ seekBarValue: string
57
+ seekBarShowRemaining: string
58
+ seekBarShowDuration: string
51
59
  selectRange: string
52
60
  pickStart: string
53
61
  pickEnd: string
@@ -187,6 +195,37 @@ export interface M3Locale {
187
195
  nextPage: string
188
196
  carousel: string
189
197
  carouselItem: string
198
+ // MMap (maplibre controls)
199
+ mapTitle: string
200
+ mapMarker: string
201
+ mapZoomIn: string
202
+ mapZoomOut: string
203
+ mapResetBearing: string
204
+ mapFindMyLocation: string
205
+ mapLocationNotAvailable: string
206
+ mapEnterFullscreen: string
207
+ mapExitFullscreen: string
208
+ mapToggleAttribution: string
209
+ mapFeedback: string
210
+ mapCtrlScroll: string
211
+ mapCmdScroll: string
212
+ mapTwoFingers: string
213
+ mapLayers: string
214
+ mapSearchLayers: string
215
+ mapNoLayers: string
216
+ mapShowLayer: string
217
+ mapHideLayer: string
218
+ mapOpacity: string
219
+ mapDownload: string
220
+ mapNoBaseLayer: string
221
+ mapHoverInfo: string
222
+ mapNoValue: string
223
+ mapMeasureDistance: string
224
+ mapMeasureArea: string
225
+ mapClearMeasurements: string
226
+ mapDeleteMeasurement: string
227
+ mapTotal: string
228
+ mapSearchPlaces: string
190
229
  }
191
230
 
192
231
  export const defaultLocale: M3Locale = {
@@ -220,6 +259,10 @@ export const defaultLocale: M3Locale = {
220
259
  remove: 'Remove',
221
260
 
222
261
  selectDate: 'Select date',
262
+ ok: 'OK',
263
+ dateToggleInput: 'Switch to text input',
264
+ dateToggleCalendar: 'Switch to calendar',
265
+ dateInputLabel: 'Date',
223
266
  selectTime: 'Select time',
224
267
  timeHourSelection: 'Select hour',
225
268
  timeMinuteSelection: 'Select minutes',
@@ -230,6 +273,10 @@ export const defaultLocale: M3Locale = {
230
273
  sheetExpand: 'Expand bottom sheet',
231
274
  sheetCollapse: 'Collapse bottom sheet',
232
275
  sheetDismiss: 'Dismiss bottom sheet',
276
+ seekBar: 'Seek',
277
+ seekBarValue: '{position} of {duration}',
278
+ seekBarShowRemaining: 'Show remaining time',
279
+ seekBarShowDuration: 'Show total time',
233
280
  selectRange: 'Select range',
234
281
  pickStart: 'Select start',
235
282
  pickEnd: 'Select end',
@@ -359,6 +406,37 @@ export const defaultLocale: M3Locale = {
359
406
  nextPage: 'Next page',
360
407
  carousel: 'Carousel',
361
408
  carouselItem: '{index} of {count}',
409
+ // MMap (maplibre controls)
410
+ mapTitle: 'Map',
411
+ mapMarker: 'Map marker',
412
+ mapZoomIn: 'Zoom in',
413
+ mapZoomOut: 'Zoom out',
414
+ mapResetBearing: 'Reset bearing to north',
415
+ mapFindMyLocation: 'Find my location',
416
+ mapLocationNotAvailable: 'Location not available',
417
+ mapEnterFullscreen: 'Enter fullscreen',
418
+ mapExitFullscreen: 'Exit fullscreen',
419
+ mapToggleAttribution: 'Toggle attribution',
420
+ mapFeedback: 'Map feedback',
421
+ mapCtrlScroll: 'Use Ctrl + scroll to zoom the map',
422
+ mapCmdScroll: 'Use ⌘ + scroll to zoom the map',
423
+ mapTwoFingers: 'Use two fingers to move the map',
424
+ mapLayers: 'Layers',
425
+ mapSearchLayers: 'Search layers',
426
+ mapNoLayers: 'No layers',
427
+ mapShowLayer: 'Show layer',
428
+ mapHideLayer: 'Hide layer',
429
+ mapOpacity: 'Opacity',
430
+ mapDownload: 'Download',
431
+ mapNoBaseLayer: 'No base layer',
432
+ mapHoverInfo: 'Info on hover',
433
+ mapNoValue: 'Not available',
434
+ mapMeasureDistance: 'Measure distance',
435
+ mapMeasureArea: 'Measure area',
436
+ mapClearMeasurements: 'Clear measurements',
437
+ mapDeleteMeasurement: 'Delete measurement',
438
+ mapTotal: 'Total',
439
+ mapSearchPlaces: 'Search places',
362
440
  }
363
441
 
364
442
  export const M3_LOCALE_KEY: InjectionKey<MaybeRef<Partial<M3Locale>>> = Symbol('m3-locale')
@@ -0,0 +1,98 @@
1
+ import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, watch, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'
2
+ import type * as Maplibre from 'maplibre-gl'
3
+ import type { MapLayerModel } from './mapAdapters'
4
+ import type { MapLayerState } from './useMapLayers'
5
+
6
+ /** The `maplibre-gl` module (its classes: `Map`, `Marker`, `Popup`…) */
7
+ export type MaplibreModule = typeof import('maplibre-gl')
8
+
9
+ /** What `MMap` provides to everything inside it. */
10
+ export interface MapContext {
11
+ /** The MapLibre map, once created (never on the server) */
12
+ map: ShallowRef<Maplibre.Map | undefined>
13
+ /** The `maplibre-gl` module, loaded with the map (so nothing imports it on the server) */
14
+ maplibre: ShallowRef<MaplibreModule | undefined>
15
+ /** Bumped on every `style.load`: sources and layers added by components are re-added after a style change */
16
+ styleVersion: Ref<number>
17
+ /** The style as `MMap`'s `adapter` reads it (undefined without one) */
18
+ model: ShallowRef<MapLayerModel | undefined>
19
+ /** Visibility and opacity of the model's layers */
20
+ layerState: MapLayerState
21
+ /**
22
+ * The tool that owns the map's clicks right now (`'measure'` while measuring), or null: `MMapIdentify` stays quiet
23
+ * meanwhile. Set it from tools of your own the same way
24
+ */
25
+ activeTool: Ref<string | null>
26
+ }
27
+
28
+ // Internal: provided by MMap
29
+ export const MAP_KEY: InjectionKey<MapContext> = Symbol('m3-map')
30
+
31
+ type MapEventType = keyof Maplibre.MapEventType
32
+ type LayerEventType = keyof Maplibre.MapLayerEventType
33
+
34
+ /**
35
+ * The map of the enclosing `MMap`, for your own controls, layers and handlers (call it in a component inside
36
+ * `MMap`). Listeners added through it are removed when the component unmounts.
37
+ *
38
+ * ```ts
39
+ * const { map, onLayer } = useMap()
40
+ * onLayer('click', 'parcels-fill', (e) => console.log(e.features?.[0]?.properties))
41
+ * ```
42
+ */
43
+ export function useMap() {
44
+ const ctx = inject(MAP_KEY, null)
45
+ if (!ctx) throw new Error('useMap() must be called in a component inside <MMap>')
46
+ const cleanups: (() => void)[] = []
47
+ if (getCurrentInstance()) onBeforeUnmount(() => cleanups.splice(0).forEach((fn) => fn()))
48
+
49
+ /**
50
+ * Runs `fn` with the map as soon as it exists (right away if it already does), and in a component not before it's
51
+ * mounted, so its template refs are there.
52
+ */
53
+ function onReady(fn: (map: Maplibre.Map, maplibre: MaplibreModule) => void) {
54
+ const run = () => {
55
+ if (ctx!.map.value && ctx!.maplibre.value) return fn(ctx!.map.value, ctx!.maplibre.value)
56
+ const stop = watch(ctx!.map, (map) => {
57
+ if (!map || !ctx!.maplibre.value) return
58
+ stop()
59
+ fn(map, ctx!.maplibre.value)
60
+ })
61
+ cleanups.push(stop)
62
+ }
63
+ const instance = getCurrentInstance()
64
+ if (instance && !instance.isMounted) onMounted(run)
65
+ else run()
66
+ }
67
+
68
+ /** A map event listener (`click`, `moveend`, `style.load`…), removed on unmount. */
69
+ function on<T extends MapEventType>(type: T, listener: (e: Maplibre.MapEventType[T] & object) => void) {
70
+ onReady((map) => {
71
+ map.on(type, listener)
72
+ cleanups.push(() => map.off(type, listener))
73
+ })
74
+ }
75
+
76
+ /**
77
+ * A listener for one layer's features (`click`, `mouseenter`, `mousemove`…: `e.features` holds the features under
78
+ * the pointer), removed on unmount. It survives style changes, being keyed by the layer id.
79
+ */
80
+ function onLayer<T extends LayerEventType>(type: T, layerId: string, listener: (e: Maplibre.MapLayerEventType[T] & object) => void) {
81
+ onReady((map) => {
82
+ map.on(type, layerId, listener)
83
+ cleanups.push(() => map.off(type, layerId, listener))
84
+ })
85
+ }
86
+
87
+ // computed, not readonly(): readonly() is deep, and a proxied maplibre Map breaks
88
+ return {
89
+ map: computed(() => ctx.map.value) as ComputedRef<Maplibre.Map | undefined>,
90
+ maplibre: computed(() => ctx.maplibre.value) as ComputedRef<MaplibreModule | undefined>,
91
+ styleVersion: computed(() => ctx.styleVersion.value),
92
+ /** The tool that owns the map's clicks (null: none): set it while yours does, and leave it alone otherwise */
93
+ activeTool: ctx.activeTool,
94
+ onReady,
95
+ on,
96
+ onLayer,
97
+ }
98
+ }
@@ -0,0 +1,45 @@
1
+ import { inject } from 'vue'
2
+ import type * as Maplibre from 'maplibre-gl'
3
+ import { MAP_KEY } from './useMap'
4
+
5
+ // The style's own filter of each layer we filter (undefined: none), per map
6
+ const originals = new WeakMap<Maplibre.Map, Map<string, Maplibre.FilterSpecification | undefined>>()
7
+
8
+ /**
9
+ * Filters for the layers of the enclosing `MMap`, on top of the filters their style already has (a layer that only
10
+ * draws parks keeps doing so): `setFilter(layer, expression)` combines both, `setFilter(layer, null)` brings the
11
+ * style's back. `MMapFilter` is built on it; use it for filters of your own (a range slider, a date, a search…).
12
+ */
13
+ export function useMapFilter() {
14
+ const ctx = inject(MAP_KEY, null)
15
+ if (!ctx) throw new Error('useMapFilter() must be called in a component inside <MMap>')
16
+
17
+ function setFilter(layerId: string, filter: Maplibre.FilterSpecification | null) {
18
+ const map = ctx!.map.value
19
+ if (!map?.getLayer(layerId)) return
20
+ let saved = originals.get(map)
21
+ if (!saved) originals.set(map, (saved = new Map()))
22
+ if (!saved.has(layerId)) saved.set(layerId, map.getFilter(layerId) ?? undefined)
23
+ const original = saved.get(layerId)
24
+ map.setFilter(layerId, filter ? (original ? ['all', original, filter] : filter) as Maplibre.FilterSpecification : original ?? null)
25
+ }
26
+
27
+ /**
28
+ * The distinct values of a property among a layer's features loaded in the map (for vector tiles, the tiles in
29
+ * view), sorted.
30
+ */
31
+ function valuesOf(layerId: string, property: string): (string | number)[] {
32
+ const map = ctx!.map.value
33
+ const layer = map?.getLayer(layerId) as (Maplibre.StyleLayer & { source?: string; sourceLayer?: string }) | undefined
34
+ if (!map || !layer?.source) return []
35
+ const features = map.querySourceFeatures(layer.source, layer.sourceLayer ? { sourceLayer: layer.sourceLayer } : undefined)
36
+ const values = new Set<string | number>()
37
+ for (const f of features) {
38
+ const v = f.properties?.[property]
39
+ if (typeof v === 'string' || typeof v === 'number') values.add(v)
40
+ }
41
+ return [...values].sort((a, b) => (typeof a === 'number' && typeof b === 'number' ? a - b : String(a).localeCompare(String(b))))
42
+ }
43
+
44
+ return { setFilter, valuesOf }
45
+ }
@@ -0,0 +1,124 @@
1
+ import { computed, inject, reactive } from 'vue'
2
+ import type * as Maplibre from 'maplibre-gl'
3
+ import { MAP_KEY } from './useMap'
4
+ import type { MapLayerInfo, MapLayerModel } from './mapAdapters'
5
+
6
+ /** The paint properties that make each layer type transparent. */
7
+ const OPACITY: Record<string, string[]> = {
8
+ fill: ['fill-opacity'],
9
+ line: ['line-opacity'],
10
+ circle: ['circle-opacity', 'circle-stroke-opacity'],
11
+ symbol: ['icon-opacity', 'text-opacity'],
12
+ raster: ['raster-opacity'],
13
+ heatmap: ['heatmap-opacity'],
14
+ 'fill-extrusion': ['fill-extrusion-opacity'],
15
+ }
16
+
17
+ /** Visibility and opacity of the model's layers, shared by everything inside one `MMap`. */
18
+ export interface MapLayerState {
19
+ visible: Record<string, boolean>
20
+ opacity: Record<string, number>
21
+ }
22
+
23
+ // Internal: MMap's shared state, filled from the map on every style load
24
+ export function createLayerState(): MapLayerState {
25
+ return reactive({ visible: {}, opacity: {} })
26
+ }
27
+
28
+ export function readLayerState(state: MapLayerState, map: Maplibre.Map, model: MapLayerModel | undefined) {
29
+ const visible: Record<string, boolean> = {}
30
+ const opacity: Record<string, number> = {}
31
+ for (const layer of model?.layers ?? []) {
32
+ const style = map.getLayer(layer.id)
33
+ if (!style) continue
34
+ visible[layer.id] = map.getLayoutProperty(layer.id, 'visibility') !== 'none'
35
+ const prop = OPACITY[style.type]?.[0]
36
+ const value = prop ? map.getPaintProperty(layer.id, prop) : undefined
37
+ opacity[layer.id] = typeof value === 'number' ? value : 1
38
+ }
39
+ state.visible = visible
40
+ state.opacity = opacity
41
+ }
42
+
43
+ /**
44
+ * The layers of the enclosing `MMap`'s style as its `adapter` describes them, with their visibility and opacity, for a
45
+ * layer panel or a base layer switcher of your own (`MMapLayers` and `MMapBaseLayers` are built on it). Changes go to
46
+ * the map and to every component using it; a layer's `children` follow it.
47
+ */
48
+ export function useMapLayers() {
49
+ const ctx = inject(MAP_KEY, null)
50
+ if (!ctx) throw new Error('useMapLayers() must be called in a component inside <MMap>')
51
+ const { map, model, layerState: state } = ctx
52
+
53
+ const layers = computed(() => model.value?.layers ?? [])
54
+ const byId = computed(() => new Map(layers.value.map((l) => [l.id, l])))
55
+
56
+ function isVisible(id: string) {
57
+ return state.visible[id] ?? true
58
+ }
59
+
60
+ function setVisible(id: string, visible: boolean) {
61
+ const m = map.value
62
+ if (m?.getLayer(id)) m.setLayoutProperty(id, 'visibility', visible ? 'visible' : 'none')
63
+ state.visible[id] = visible
64
+ for (const child of byId.value.get(id)?.children ?? []) setVisible(child, visible)
65
+ }
66
+
67
+ function toggle(id: string) {
68
+ setVisible(id, !isVisible(id))
69
+ }
70
+
71
+ function opacityOf(id: string) {
72
+ return state.opacity[id] ?? 1
73
+ }
74
+
75
+ function setOpacity(id: string, opacity: number) {
76
+ const m = map.value
77
+ const layer = m?.getLayer(id)
78
+ if (layer) for (const prop of OPACITY[layer.type] ?? []) m!.setPaintProperty(id, prop, opacity)
79
+ state.opacity[id] = opacity
80
+ for (const child of byId.value.get(id)?.children ?? []) setOpacity(child, opacity)
81
+ }
82
+
83
+ /** The layers of a group (listed ones), or the ungrouped ones with `null`. */
84
+ function layersOf(group: string | null): MapLayerInfo[] {
85
+ return layers.value.filter((l) => l.listed && (group === null ? !l.group || !model.value?.groups.some((g) => g.name === l.group) : l.group === group))
86
+ }
87
+
88
+ function groupState(group: string): 'visible' | 'hidden' | 'partial' {
89
+ const visible = layersOf(group).map((l) => isVisible(l.id))
90
+ if (visible.length && visible.every(Boolean)) return 'visible'
91
+ if (visible.some(Boolean)) return 'partial'
92
+ return 'hidden'
93
+ }
94
+
95
+ function setGroupVisible(group: string, visible: boolean) {
96
+ for (const layer of layersOf(group)) setVisible(layer.id, visible)
97
+ }
98
+
99
+ const baseLayers = computed(() => layers.value.filter((l) => l.base))
100
+ /** The visible base layer's id, or null */
101
+ const baseLayer = computed(() => baseLayers.value.find((l) => isVisible(l.id))?.id ?? null)
102
+
103
+ /** Shows this base layer only (null: none). */
104
+ function setBaseLayer(id: string | null) {
105
+ for (const layer of baseLayers.value) setVisible(layer.id, layer.id === id)
106
+ }
107
+
108
+ return {
109
+ /** The adapter's model (undefined without an `adapter`) */
110
+ model: computed(() => model.value),
111
+ layers,
112
+ isVisible,
113
+ setVisible,
114
+ toggle,
115
+ opacityOf,
116
+ setOpacity,
117
+ layersOf,
118
+ groupState,
119
+ setGroupVisible,
120
+ baseLayers,
121
+ baseLayer,
122
+ setBaseLayer,
123
+ }
124
+ }
@@ -1,14 +1,17 @@
1
1
  import { ref, watchEffect, onMounted, onUnmounted } from 'vue'
2
2
  import { themeTransition } from './_themeTransition'
3
+ import { initialState, readCookie, ssrValue, writeCookie } from './_ssrState'
4
+ import { THEME_KEY } from './_storageKeys'
3
5
 
4
6
  export type Theme = 'light' | 'dark' | 'system'
5
7
 
6
- export const THEME_KEY = 'm3-theme'
8
+ export { THEME_KEY }
7
9
 
8
10
  // No DOM on the server (SSR): nothing is read or applied there, the client does it when the module loads.
9
11
  const inBrowser = typeof window !== 'undefined'
10
12
 
11
- const theme = ref<Theme>((inBrowser ? localStorage.getItem(THEME_KEY) as Theme : null) ?? 'system')
13
+ // localStorage, else the cookie createM3UI({ cookies }) keeps (cleared storage, or a theme a server set)
14
+ const theme = ref<Theme>((inBrowser ? (localStorage.getItem(THEME_KEY) ?? readCookie(THEME_KEY)) as Theme : null) ?? 'system')
12
15
 
13
16
  let _appliedDark: boolean | null = null
14
17
 
@@ -37,6 +40,7 @@ export function useTheme() {
37
40
  watchEffect(() => {
38
41
  if (!inBrowser) return
39
42
  localStorage.setItem(THEME_KEY, theme.value)
43
+ writeCookie(THEME_KEY, theme.value)
40
44
  applyTheme(theme.value)
41
45
  })
42
46
 
@@ -49,5 +53,6 @@ export function useTheme() {
49
53
  theme.value = order[(idx + 1) % order.length]!
50
54
  }
51
55
 
52
- return { theme, cycle }
56
+ // Server-side rendering with `createM3UI({ initialState })`: the user's theme as the server knows it
57
+ return { theme: ssrValue(theme, initialState()?.theme), cycle }
53
58
  }
@@ -1,5 +1,6 @@
1
1
  import { computed, onMounted, onUnmounted, ref, toValue, watch, type MaybeRefOrGetter, type Ref } from 'vue'
2
2
  import { isHydrating } from './_hydration'
3
+ import { initialState } from './_ssrState'
3
4
 
4
5
  /*
5
6
  * M3 window size classes, with the breakpoints from androidx `WindowSizeClass`
@@ -49,15 +50,23 @@ function updateWindow() {
49
50
  export function useWindowSizeClass(target?: MaybeRefOrGetter<HTMLElement | null | undefined>): WindowSizeClassInfo {
50
51
  let width: Ref<number>
51
52
  let height: Ref<number>
52
- // Hydrating server-rendered HTML: start from the server's size (none, so compact) to match it, then measure
53
+ // Server rendering, and hydrating its HTML: the size the server rendered at, so both match, then measure. That's
54
+ // the window size it was given (createM3UI({ initialState: { viewport } }), from a cookie), or none (compact).
53
55
  const hydrating = isHydrating()
56
+ const server = typeof window === 'undefined'
57
+ const start = server || hydrating ? initialState()?.viewport : undefined
58
+ const startWidth = start?.width ?? 0
59
+ const startHeight = start?.height ?? 0
54
60
 
55
61
  if (target === undefined) {
56
62
  if (hydrating) {
57
63
  const mounted = ref(false)
58
64
  onMounted(() => { mounted.value = true })
59
- width = computed(() => (mounted.value ? winWidth.value : 0)) as Ref<number>
60
- height = computed(() => (mounted.value ? winHeight.value : 0)) as Ref<number>
65
+ width = computed(() => (mounted.value ? winWidth.value : startWidth)) as Ref<number>
66
+ height = computed(() => (mounted.value ? winHeight.value : startHeight)) as Ref<number>
67
+ } else if (server) {
68
+ width = ref(startWidth)
69
+ height = ref(startHeight)
61
70
  } else {
62
71
  width = winWidth
63
72
  height = winHeight
@@ -73,8 +82,8 @@ export function useWindowSizeClass(target?: MaybeRefOrGetter<HTMLElement | null
73
82
  })
74
83
  } else {
75
84
  // Until the element is measured, guess from the window so the first paint is usually right.
76
- width = ref(hydrating ? 0 : winWidth.value)
77
- height = ref(hydrating ? 0 : winHeight.value)
85
+ width = ref(server || hydrating ? startWidth : winWidth.value)
86
+ height = ref(server || hydrating ? startHeight : winHeight.value)
78
87
  let observer: ResizeObserver | undefined
79
88
  const observe = (el: HTMLElement | null | undefined) => {
80
89
  observer?.disconnect()
package/src/index.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  // Plugin
2
2
  export { createM3UI } from './plugin'
3
3
  export type { M3UIOptions } from './plugin'
4
+ export type { M3InitialState } from './composables/_ssrState'
4
5
 
5
6
  // Composables
6
7
  export { useTheme } from './composables/useTheme'
7
8
  export type { Theme } from './composables/useTheme'
8
9
  export { useColorPalette, palettes } from './composables/useColorPalette'
9
- export type { Palette, ActiveSeed, ContrastLevel } from './composables/useColorPalette'
10
+ export type { Palette, PaletteId, ActiveSeed, ContrastLevel } from './composables/useColorPalette'
10
11
  export { SEED_PALETTE } from './composables/useColorPalette'
11
12
  export { themeInitScript } from './composables/themeInitScript'
12
13
  export type { ThemeInitOptions } from './composables/themeInitScript'
@@ -146,6 +147,7 @@ export { default as MScheduler } from './components/MScheduler.vue'
146
147
  export { default as MScrollable } from './components/MScrollable.vue'
147
148
  export { default as MSearchBar } from './components/MSearchBar.vue'
148
149
  export { default as MSection } from './components/MSection.vue'
150
+ export { default as MSeekBar } from './components/MSeekBar.vue'
149
151
  export { default as MSegmentedButton } from './components/MSegmentedButton.vue'
150
152
  export { default as MScrollField } from './components/MScrollField.vue'
151
153
  export { default as MSelect } from './components/MSelect.vue'
@@ -218,6 +220,7 @@ export type { SpeedDialItem } from './components/MFab.vue'
218
220
  export type { FabMenuItem } from './components/MFabMenu.vue'
219
221
  export type { NavRailItem } from './components/MNavigationRail.vue'
220
222
  export type { SchedulerEvent } from './components/MScheduler.vue'
223
+ export type { SeekBarChapter } from './components/MSeekBar.vue'
221
224
  export type { SegmentedOption } from './components/MSegmentedButton.vue'
222
225
  export type { SpotlightResult } from './components/MSpotlightSearch.vue'
223
226
  export type { StepItem } from './components/MStepper.vue'
package/src/locales/de.ts CHANGED
@@ -37,6 +37,10 @@ export const deLocale: M3Locale = {
37
37
 
38
38
  // Pickers
39
39
  selectDate: 'Datum auswählen',
40
+ ok: 'OK',
41
+ dateToggleInput: 'Zur Texteingabe wechseln',
42
+ dateToggleCalendar: 'Zum Kalender wechseln',
43
+ dateInputLabel: 'Datum',
40
44
  selectTime: 'Uhrzeit auswählen',
41
45
  timeHourSelection: 'Stunde auswählen',
42
46
  timeMinuteSelection: 'Minuten auswählen',
@@ -47,6 +51,10 @@ export const deLocale: M3Locale = {
47
51
  sheetExpand: 'Ansicht am unteren Rand maximieren',
48
52
  sheetCollapse: 'Ansicht am unteren Rand minimieren',
49
53
  sheetDismiss: 'Ansicht am unteren Rand schließen',
54
+ seekBar: 'Spulen',
55
+ seekBarValue: '{position} von {duration}',
56
+ seekBarShowRemaining: 'Verbleibende Zeit anzeigen',
57
+ seekBarShowDuration: 'Gesamtdauer anzeigen',
50
58
  selectRange: 'Bereich auswählen',
51
59
  pickStart: 'Anfang auswählen',
52
60
  pickEnd: 'Ende auswählen',
@@ -182,5 +190,35 @@ export const deLocale: M3Locale = {
182
190
  previousPage: 'Vorherige Seite',
183
191
  nextPage: 'Nächste Seite',
184
192
  carousel: 'Karussell',
185
- carouselItem: '{index} von {count}',
193
+ carouselItem: '{index} von {count}', // MMap (maplibre controls)
194
+ mapTitle: 'Karte',
195
+ mapMarker: 'Kartenmarkierung',
196
+ mapZoomIn: 'Vergrößern',
197
+ mapZoomOut: 'Verkleinern',
198
+ mapResetBearing: 'Nach Norden ausrichten',
199
+ mapFindMyLocation: 'Meinen Standort finden',
200
+ mapLocationNotAvailable: 'Standort nicht verfügbar',
201
+ mapEnterFullscreen: 'Vollbild aktivieren',
202
+ mapExitFullscreen: 'Vollbild beenden',
203
+ mapToggleAttribution: 'Quellenangabe ein- oder ausblenden',
204
+ mapFeedback: 'Feedback zur Karte',
205
+ mapCtrlScroll: 'Strg + Scrollen zum Zoomen der Karte',
206
+ mapCmdScroll: '⌘ + Scrollen zum Zoomen der Karte',
207
+ mapTwoFingers: 'Mit zwei Fingern die Karte bewegen',
208
+ mapLayers: 'Ebenen',
209
+ mapSearchLayers: 'Ebenen suchen',
210
+ mapNoLayers: 'Keine Ebenen',
211
+ mapShowLayer: 'Ebene einblenden',
212
+ mapHideLayer: 'Ebene ausblenden',
213
+ mapOpacity: 'Deckkraft',
214
+ mapDownload: 'Herunterladen',
215
+ mapNoBaseLayer: 'Keine Grundkarte',
216
+ mapHoverInfo: 'Infos beim Überfahren',
217
+ mapNoValue: 'Nicht verfügbar',
218
+ mapMeasureDistance: 'Entfernung messen',
219
+ mapMeasureArea: 'Fläche messen',
220
+ mapClearMeasurements: 'Messungen löschen',
221
+ mapDeleteMeasurement: 'Messung löschen',
222
+ mapTotal: 'Gesamt',
223
+ mapSearchPlaces: 'Orte suchen',
186
224
  }
package/src/locales/es.ts CHANGED
@@ -37,6 +37,10 @@ export const esLocale: M3Locale = {
37
37
 
38
38
  // Pickers
39
39
  selectDate: 'Seleccionar fecha',
40
+ ok: 'Aceptar',
41
+ dateToggleInput: 'Cambiar a entrada de texto',
42
+ dateToggleCalendar: 'Cambiar a calendario',
43
+ dateInputLabel: 'Fecha',
40
44
  selectTime: 'Seleccionar hora',
41
45
  timeHourSelection: 'Seleccionar hora',
42
46
  timeMinuteSelection: 'Seleccionar minutos',
@@ -47,6 +51,10 @@ export const esLocale: M3Locale = {
47
51
  sheetExpand: 'Expandir hoja inferior',
48
52
  sheetCollapse: 'Contraer hoja inferior',
49
53
  sheetDismiss: 'Cerrar hoja inferior',
54
+ seekBar: 'Buscar posición',
55
+ seekBarValue: '{position} de {duration}',
56
+ seekBarShowRemaining: 'Mostrar tiempo restante',
57
+ seekBarShowDuration: 'Mostrar duración total',
50
58
  selectRange: 'Seleccionar rango',
51
59
  pickStart: 'Seleccionar inicio',
52
60
  pickEnd: 'Seleccionar fin',
@@ -182,5 +190,35 @@ export const esLocale: M3Locale = {
182
190
  previousPage: 'Página anterior',
183
191
  nextPage: 'Página siguiente',
184
192
  carousel: 'Carrusel',
185
- carouselItem: '{index} de {count}',
193
+ carouselItem: '{index} de {count}', // MMap (maplibre controls)
194
+ mapTitle: 'Mapa',
195
+ mapMarker: 'Marcador del mapa',
196
+ mapZoomIn: 'Acercar',
197
+ mapZoomOut: 'Alejar',
198
+ mapResetBearing: 'Restablecer orientación al norte',
199
+ mapFindMyLocation: 'Encontrar mi ubicación',
200
+ mapLocationNotAvailable: 'Ubicación no disponible',
201
+ mapEnterFullscreen: 'Entrar en pantalla completa',
202
+ mapExitFullscreen: 'Salir de pantalla completa',
203
+ mapToggleAttribution: 'Alternar atribución',
204
+ mapFeedback: 'Comentarios del mapa',
205
+ mapCtrlScroll: 'Usa Ctrl + rueda para hacer zoom en el mapa',
206
+ mapCmdScroll: 'Usa ⌘ + rueda para hacer zoom en el mapa',
207
+ mapTwoFingers: 'Usa dos dedos para mover el mapa',
208
+ mapLayers: 'Capas',
209
+ mapSearchLayers: 'Buscar capas',
210
+ mapNoLayers: 'No hay capas',
211
+ mapShowLayer: 'Mostrar capa',
212
+ mapHideLayer: 'Ocultar capa',
213
+ mapOpacity: 'Opacidad',
214
+ mapDownload: 'Descargar',
215
+ mapNoBaseLayer: 'Sin capa base',
216
+ mapHoverInfo: 'Información al pasar el cursor',
217
+ mapNoValue: 'No disponible',
218
+ mapMeasureDistance: 'Medir distancia',
219
+ mapMeasureArea: 'Medir área',
220
+ mapClearMeasurements: 'Borrar mediciones',
221
+ mapDeleteMeasurement: 'Borrar medición',
222
+ mapTotal: 'Total',
223
+ mapSearchPlaces: 'Buscar lugares',
186
224
  }
package/src/locales/fr.ts CHANGED
@@ -37,6 +37,10 @@ export const frLocale: M3Locale = {
37
37
 
38
38
  // Pickers
39
39
  selectDate: 'Sélectionner la date',
40
+ ok: 'OK',
41
+ dateToggleInput: 'Passer à la saisie de texte',
42
+ dateToggleCalendar: 'Passer au calendrier',
43
+ dateInputLabel: 'Date',
40
44
  selectTime: "Sélectionner l'heure",
41
45
  timeHourSelection: "Sélectionner l'heure",
42
46
  timeMinuteSelection: 'Sélectionner les minutes',
@@ -47,6 +51,10 @@ export const frLocale: M3Locale = {
47
51
  sheetExpand: 'Développer la feuille inférieure',
48
52
  sheetCollapse: 'Réduire la feuille inférieure',
49
53
  sheetDismiss: 'Fermer la feuille inférieure',
54
+ seekBar: 'Rechercher',
55
+ seekBarValue: '{position} sur {duration}',
56
+ seekBarShowRemaining: 'Afficher le temps restant',
57
+ seekBarShowDuration: 'Afficher la durée totale',
50
58
  selectRange: 'Sélectionner la plage',
51
59
  pickStart: 'Sélectionner le début',
52
60
  pickEnd: 'Sélectionner la fin',
@@ -182,5 +190,35 @@ export const frLocale: M3Locale = {
182
190
  previousPage: 'Page précédente',
183
191
  nextPage: 'Page suivante',
184
192
  carousel: 'Carrousel',
185
- carouselItem: '{index} sur {count}',
193
+ carouselItem: '{index} sur {count}', // MMap (maplibre controls)
194
+ mapTitle: 'Carte',
195
+ mapMarker: 'Marqueur de carte',
196
+ mapZoomIn: 'Zoom avant',
197
+ mapZoomOut: 'Zoom arrière',
198
+ mapResetBearing: 'Réorienter vers le nord',
199
+ mapFindMyLocation: 'Trouver ma position',
200
+ mapLocationNotAvailable: 'Position non disponible',
201
+ mapEnterFullscreen: 'Passer en plein écran',
202
+ mapExitFullscreen: 'Quitter le plein écran',
203
+ mapToggleAttribution: 'Afficher ou masquer l\'attribution',
204
+ mapFeedback: 'Commentaires sur la carte',
205
+ mapCtrlScroll: 'Utilisez Ctrl + molette pour zoomer sur la carte',
206
+ mapCmdScroll: 'Utilisez ⌘ + molette pour zoomer sur la carte',
207
+ mapTwoFingers: 'Utilisez deux doigts pour déplacer la carte',
208
+ mapLayers: 'Calques',
209
+ mapSearchLayers: 'Rechercher des calques',
210
+ mapNoLayers: 'Aucun calque',
211
+ mapShowLayer: 'Afficher le calque',
212
+ mapHideLayer: 'Masquer le calque',
213
+ mapOpacity: 'Opacité',
214
+ mapDownload: 'Télécharger',
215
+ mapNoBaseLayer: 'Aucun fond de carte',
216
+ mapHoverInfo: 'Infos au survol',
217
+ mapNoValue: 'Non disponible',
218
+ mapMeasureDistance: 'Mesurer une distance',
219
+ mapMeasureArea: 'Mesurer une surface',
220
+ mapClearMeasurements: 'Effacer les mesures',
221
+ mapDeleteMeasurement: 'Supprimer la mesure',
222
+ mapTotal: 'Total',
223
+ mapSearchPlaces: 'Rechercher un lieu',
186
224
  }