@m3ui-vue/m3ui-vue 1.1.4 → 1.2.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 (199) hide show
  1. package/dist/API.md +511 -34
  2. package/dist/MMenuItem-DI351kIf.js +929 -0
  3. package/dist/MMenuItem-DI351kIf.js.map +1 -0
  4. package/dist/{MSlider-JflHJ70q.js → MSlider-BnEy5ieZ.js} +295 -320
  5. package/dist/MSlider-BnEy5ieZ.js.map +1 -0
  6. package/dist/MTextField-BBmkaIbO.js +633 -0
  7. package/dist/MTextField-BBmkaIbO.js.map +1 -0
  8. package/dist/api.json +1 -1
  9. package/dist/chart.js +83 -49
  10. package/dist/chart.js.map +1 -1
  11. package/dist/code-editor.js +1 -1
  12. package/dist/components/MButton.vue.d.ts +7 -1
  13. package/dist/components/MButtonGroup.vue.d.ts +40 -31
  14. package/dist/components/MCarousel.vue.d.ts +2 -0
  15. package/dist/components/MChart.vue.d.ts +6 -0
  16. package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
  17. package/dist/components/MContextMenu.vue.d.ts +2 -2
  18. package/dist/components/MCopyButton.vue.d.ts +1 -1
  19. package/dist/components/MExportButton.vue.d.ts +1 -1
  20. package/dist/components/MFab.vue.d.ts +2 -2
  21. package/dist/components/MFabMenu.vue.d.ts +1 -1
  22. package/dist/components/MIconButton.vue.d.ts +13 -1
  23. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  24. package/dist/components/MMap.vue.d.ts +20 -2
  25. package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
  26. package/dist/components/MMapFilter.vue.d.ts +3 -0
  27. package/dist/components/MMapLayers.vue.d.ts +3 -0
  28. package/dist/components/MMenu.vue.d.ts +2 -2
  29. package/dist/components/MMenuItem.vue.d.ts +7 -3
  30. package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
  31. package/dist/components/MOverlay.vue.d.ts +12 -1
  32. package/dist/components/MProgressBar.vue.d.ts +5 -3
  33. package/dist/components/MPullToRefresh.vue.d.ts +7 -2
  34. package/dist/components/MRichTextEditor.vue.d.ts +7 -1
  35. package/dist/components/MSearchField.vue.d.ts +58 -0
  36. package/dist/components/MSegmentedButton.vue.d.ts +31 -23
  37. package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
  38. package/dist/components/MSkeleton.vue.d.ts +6 -3
  39. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  40. package/dist/components/MSwitch.vue.d.ts +1 -1
  41. package/dist/components/MTextField.vue.d.ts +5 -1
  42. package/dist/components/MTimeline.vue.d.ts +85 -22
  43. package/dist/components/MTooltip.vue.d.ts +1 -1
  44. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  45. package/dist/composables/_mapStyle.d.ts +13 -0
  46. package/dist/composables/_themeTransition.d.ts +2 -0
  47. package/dist/composables/_tooltipTrigger.d.ts +22 -0
  48. package/dist/composables/_useMenuNav.d.ts +28 -0
  49. package/dist/composables/useAutoGrow.d.ts +21 -0
  50. package/dist/composables/useColorPalette.d.ts +1 -1
  51. package/dist/composables/useLocale.d.ts +3 -0
  52. package/dist/composables/useMap.d.ts +19 -3
  53. package/dist/composables/useMapFilter.d.ts +4 -1
  54. package/dist/composables/useMapLayers.d.ts +5 -2
  55. package/dist/composables/useScrollReveal.d.ts +44 -0
  56. package/dist/composables/useThemeTokens.d.ts +21 -0
  57. package/dist/composables/viewportHints.d.ts +27 -0
  58. package/dist/directives/vClickOutside.d.ts +25 -0
  59. package/dist/directives/vFocusRing.d.ts +22 -0
  60. package/dist/directives/vLongPress.d.ts +27 -0
  61. package/dist/directives/vReveal.d.ts +10 -0
  62. package/dist/directives/vScrollElevation.d.ts +31 -0
  63. package/dist/directives/vSkeleton.d.ts +19 -0
  64. package/dist/directives/vStateLayer.d.ts +20 -0
  65. package/dist/directives/vSwipe.d.ts +45 -0
  66. package/dist/directives/vTooltip.d.ts +23 -0
  67. package/dist/index.d.ts +28 -1
  68. package/dist/locales/index.js +21 -7
  69. package/dist/locales/index.js.map +1 -1
  70. package/dist/m3ui-vue.css +1 -1
  71. package/dist/m3ui.js +7131 -6216
  72. package/dist/m3ui.js.map +1 -1
  73. package/dist/map.d.ts +1 -1
  74. package/dist/map.js +821 -791
  75. package/dist/map.js.map +1 -1
  76. package/dist/motion-DZiXG09o.js +150 -0
  77. package/dist/motion-DZiXG09o.js.map +1 -0
  78. package/dist/plugin.d.ts +24 -0
  79. package/dist/rich-text-editor.js +13 -9
  80. package/dist/rich-text-editor.js.map +1 -1
  81. package/dist/styles/theme.css +63 -0
  82. package/dist/styles.css +1 -1
  83. package/dist/{useLocale-CXibICQA.js → useLocale-JYxDDeXC.js} +4 -2
  84. package/dist/useLocale-JYxDDeXC.js.map +1 -0
  85. package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
  86. package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
  87. package/package.json +1 -1
  88. package/src/__tests__/MButton.test.ts +22 -0
  89. package/src/__tests__/MCarousel.test.ts +9 -0
  90. package/src/__tests__/MChart.test.ts +77 -5
  91. package/src/__tests__/MIconButton.test.ts +33 -0
  92. package/src/__tests__/MMap.test.ts +53 -1
  93. package/src/__tests__/MMapLayers.test.ts +46 -2
  94. package/src/__tests__/MMenu.test.ts +104 -1
  95. package/src/__tests__/MMenuItem.test.ts +18 -0
  96. package/src/__tests__/MNavigationDrawer.test.ts +80 -0
  97. package/src/__tests__/MOverlay.test.ts +49 -0
  98. package/src/__tests__/MProgressBar.test.ts +41 -0
  99. package/src/__tests__/MPullToRefresh.test.ts +33 -0
  100. package/src/__tests__/MRichTextEditor.test.ts +22 -0
  101. package/src/__tests__/MSearchField.test.ts +71 -0
  102. package/src/__tests__/MSkeleton.test.ts +38 -0
  103. package/src/__tests__/MTimeline.test.ts +238 -0
  104. package/src/__tests__/_fakeMaplibre.ts +3 -1
  105. package/src/__tests__/attrsFallthrough.test.ts +3 -0
  106. package/src/__tests__/escapeStack.test.ts +93 -0
  107. package/src/__tests__/ssr.test.ts +21 -2
  108. package/src/__tests__/useAutoGrow.test.ts +103 -0
  109. package/src/__tests__/useScrollReveal.test.ts +102 -0
  110. package/src/__tests__/useThemeTokens.test.ts +114 -0
  111. package/src/__tests__/vClickOutside.test.ts +82 -0
  112. package/src/__tests__/vFocusRing.test.ts +36 -0
  113. package/src/__tests__/vLongPress.test.ts +81 -0
  114. package/src/__tests__/vScrollElevation.test.ts +89 -0
  115. package/src/__tests__/vSkeleton.test.ts +48 -0
  116. package/src/__tests__/vStateLayer.test.ts +53 -0
  117. package/src/__tests__/vSwipe.test.ts +93 -0
  118. package/src/__tests__/vTooltip.test.ts +95 -0
  119. package/src/__tests__/viewportHints.test.ts +41 -0
  120. package/src/components/MAutocomplete.vue +5 -0
  121. package/src/components/MBottomSheet.vue +4 -1
  122. package/src/components/MButton.vue +15 -1
  123. package/src/components/MButtonGroup.vue +22 -17
  124. package/src/components/MCarousel.vue +7 -1
  125. package/src/components/MChart.vue +74 -34
  126. package/src/components/MCircleProgressBar.vue +14 -9
  127. package/src/components/MCommandPalette.vue +3 -2
  128. package/src/components/MContextMenu.vue +19 -60
  129. package/src/components/MDragDropList.vue +2 -0
  130. package/src/components/MIconButton.vue +40 -1
  131. package/src/components/MKanban.vue +2 -0
  132. package/src/components/MLightbox.vue +7 -2
  133. package/src/components/MMap.vue +38 -5
  134. package/src/components/MMapBaseLayers.vue +7 -3
  135. package/src/components/MMapFilter.vue +7 -4
  136. package/src/components/MMapGeoJson.vue +1 -1
  137. package/src/components/MMapLayers.vue +6 -2
  138. package/src/components/MMapMeasure.vue +5 -2
  139. package/src/components/MMenu.vue +18 -59
  140. package/src/components/MMenuItem.vue +11 -2
  141. package/src/components/MMultiAutocomplete.vue +5 -0
  142. package/src/components/MNavigationDrawer.vue +96 -11
  143. package/src/components/MNavigationRail.vue +4 -15
  144. package/src/components/MOverlay.vue +32 -13
  145. package/src/components/MProgressBar.vue +25 -27
  146. package/src/components/MPullToRefresh.vue +20 -1
  147. package/src/components/MRichTextEditor.vue +19 -5
  148. package/src/components/MSearchBar.vue +5 -0
  149. package/src/components/MSearchField.vue +142 -0
  150. package/src/components/MSegmentedButton.vue +19 -17
  151. package/src/components/MSelect.vue +10 -1
  152. package/src/components/MSideSheet.vue +5 -2
  153. package/src/components/MSimpleCarousel.vue +10 -1
  154. package/src/components/MSkeleton.vue +30 -8
  155. package/src/components/MSpotlightSearch.vue +3 -2
  156. package/src/components/MTextField.vue +15 -2
  157. package/src/components/MTimeline.vue +370 -81
  158. package/src/components/MTooltip.vue +20 -152
  159. package/src/components/_MDrawerItemList.vue +25 -6
  160. package/src/composables/_mapStyle.ts +45 -0
  161. package/src/composables/_themeTransition.ts +2 -0
  162. package/src/composables/_tooltipTrigger.ts +184 -0
  163. package/src/composables/_useMenuNav.ts +209 -0
  164. package/src/composables/useAutoGrow.ts +78 -0
  165. package/src/composables/useLocale.ts +5 -0
  166. package/src/composables/useMap.ts +43 -5
  167. package/src/composables/useMapFilter.ts +6 -5
  168. package/src/composables/useMapLayers.ts +7 -6
  169. package/src/composables/useScrollReveal.ts +151 -0
  170. package/src/composables/useThemeTokens.ts +116 -0
  171. package/src/composables/viewportHints.ts +80 -0
  172. package/src/directives/vClickOutside.ts +90 -0
  173. package/src/directives/vFocusRing.ts +60 -0
  174. package/src/directives/vLongPress.ts +134 -0
  175. package/src/directives/vReveal.ts +57 -0
  176. package/src/directives/vScrollElevation.ts +116 -0
  177. package/src/directives/vSkeleton.ts +87 -0
  178. package/src/directives/vStateLayer.ts +83 -0
  179. package/src/directives/vSwipe.ts +197 -0
  180. package/src/directives/vTooltip.ts +128 -0
  181. package/src/index.ts +28 -1
  182. package/src/locales/de.ts +2 -0
  183. package/src/locales/es.ts +2 -0
  184. package/src/locales/fr.ts +2 -0
  185. package/src/locales/ja.ts +2 -0
  186. package/src/locales/ko.ts +2 -0
  187. package/src/locales/pt.ts +2 -0
  188. package/src/locales/zh.ts +2 -0
  189. package/src/map.ts +1 -1
  190. package/src/plugin.ts +34 -0
  191. package/src/styles/theme.css +63 -0
  192. package/dist/MMenuItem-BfjqwcYP.js +0 -830
  193. package/dist/MMenuItem-BfjqwcYP.js.map +0 -1
  194. package/dist/MSlider-JflHJ70q.js.map +0 -1
  195. package/dist/MTextField-NaIB6RbM.js +0 -673
  196. package/dist/MTextField-NaIB6RbM.js.map +0 -1
  197. package/dist/composables/_useThemeTokens.d.ts +0 -7
  198. package/dist/useLocale-CXibICQA.js.map +0 -1
  199. package/src/composables/_useThemeTokens.ts +0 -42
@@ -0,0 +1,209 @@
1
+ import { computed, nextTick, onUnmounted, ref } from 'vue'
2
+ import { motionSprings } from './motion'
3
+ import { playSamples, prefersReducedMotion, sampleSpring } from './_springAnimation'
4
+
5
+ /*
6
+ * Internal (not exported from index.ts): the `submenuMode="push"` navigation shared by MMenu and MContextMenu.
7
+ * A stack of levels (one per opened MMenuItem with #children) shown one at a time in the panel's scroll
8
+ * wrapper (`navBox`), with:
9
+ * - M3's shared axis X between levels: a 30dp slide with a crossfade, the old level fading out quickly and the
10
+ * new one fading in after it. Driven by the Web Animations API through a `:css="false"` Transition: with
11
+ * direction-dependent classes on a mode-less Transition, Vue's class swap unreliably never completed.
12
+ * - the panel's height following the new level on a spring (Standard DefaultSpatial), measured before and
13
+ * after the swap, with no scrollbar while the levels cross.
14
+ * - swipe right to go back on touch: the level follows the finger and, released past a third of the panel
15
+ * (or flung), leaves from where it is; otherwise it springs back.
16
+ */
17
+
18
+ export type MenuNavEntry = { icon?: string, header?: () => any, content?: () => any }
19
+
20
+ const SHARED_AXIS_OFFSET = 30
21
+ // Back to scrolling once the slide (60ms delay + 300ms) has settled
22
+ const SLIDE_SETTLE_MS = 380
23
+ // A touch decides between a vertical scroll and a swipe once it has moved this far
24
+ const SWIPE_SLOP = 8
25
+ const SWIPE_DISTANCE = 1 / 3
26
+ const SWIPE_VELOCITY = 0.5 // px/ms
27
+
28
+ export function useMenuNav(focusFirst: () => void) {
29
+ const navStack = ref<MenuNavEntry[]>([])
30
+ const currentNav = computed(() => navStack.value[navStack.value.length - 1])
31
+ const navDirection = ref<'forward' | 'backward'>('forward')
32
+ const navBox = ref<HTMLElement>()
33
+
34
+ // Where a swiped level was released, so its leave starts there instead of jumping back to 0
35
+ let leaveFromX = 0
36
+ let leaveFromOpacity = 1
37
+
38
+ function navSlideEnter(el: Element, done: () => void) {
39
+ const dir = navDirection.value === 'forward' ? 1 : -1
40
+ const anim = (el as HTMLElement).animate(
41
+ [
42
+ { transform: `translateX(${dir * SHARED_AXIS_OFFSET}px)`, opacity: 0 },
43
+ { transform: 'translateX(0)', opacity: 1 },
44
+ ],
45
+ { duration: 300, delay: 60, easing: 'cubic-bezier(0.05,0.7,0.1,1)', fill: 'backwards' },
46
+ )
47
+ anim.onfinish = done
48
+ }
49
+
50
+ function navSlideLeave(el: Element, done: () => void) {
51
+ const dir = navDirection.value === 'forward' ? -1 : 1
52
+ const htmlEl = el as HTMLElement
53
+ htmlEl.style.position = 'absolute'
54
+ htmlEl.style.insetInline = '0'
55
+ htmlEl.style.top = '0'
56
+ const from = leaveFromX
57
+ const opacity = leaveFromOpacity
58
+ leaveFromX = 0
59
+ leaveFromOpacity = 1
60
+ const anim = htmlEl.animate(
61
+ [
62
+ { transform: `translateX(${from}px)`, opacity },
63
+ { transform: `translateX(${from + dir * SHARED_AXIS_OFFSET}px)`, opacity: 0 },
64
+ ],
65
+ { duration: 90, easing: 'cubic-bezier(0.3,0,0.8,0.15)', fill: 'forwards' },
66
+ )
67
+ anim.onfinish = done
68
+ }
69
+
70
+ function resizeAround(change: () => void) {
71
+ const el = navBox.value
72
+ const from = el?.offsetHeight ?? 0
73
+ // Both levels overflow for a moment: no scrollbar until they settle, then the wrapper's own inline value
74
+ const prevOverflow = el?.style.overflowY ?? ''
75
+ if (el) el.style.overflowY = 'hidden'
76
+ const restore = () => { if (el) el.style.overflowY = prevOverflow }
77
+ change()
78
+ if (!el || prefersReducedMotion()) return restore()
79
+ nextTick(() => {
80
+ const to = el.offsetHeight
81
+ const anim = Math.abs(to - from) < 1 ? null
82
+ : playSamples(el, sampleSpring(from, to, 0, motionSprings.standard.defaultSpatial, 0.5), (h) => ({ height: `${h}px` }))
83
+ const slide = new Promise((r) => setTimeout(r, SLIDE_SETTLE_MS))
84
+ Promise.all([slide, anim?.finished.catch(() => {})]).then(restore)
85
+ })
86
+ }
87
+
88
+ function pushNav(entry: MenuNavEntry) {
89
+ navDirection.value = 'forward'
90
+ resizeAround(() => navStack.value.push(entry))
91
+ nextTick(focusFirst)
92
+ }
93
+
94
+ function popNav() {
95
+ navDirection.value = 'backward'
96
+ resizeAround(() => navStack.value.pop())
97
+ nextTick(focusFirst)
98
+ }
99
+
100
+ function resetNav() {
101
+ navStack.value = []
102
+ }
103
+
104
+ // Swipe back. The wrapper has `touch-action: pan-y` while a level is pushed, so a sideways drag reaches us
105
+ // as pointer events while vertical ones still scroll the list
106
+ let swipe: { id: number, x: number, y: number, level: HTMLElement, width: number, active: boolean, lastX: number, lastT: number, vel: number } | null = null
107
+
108
+ function levelEl() {
109
+ // The level on screen (a level still leaving has another depth)
110
+ return navBox.value?.querySelector<HTMLElement>(`:scope > [data-menu-level="${navStack.value.length}"]`) ?? null
111
+ }
112
+
113
+ function onNavPointerDown(e: PointerEvent) {
114
+ if (e.pointerType !== 'touch' || !navStack.value.length || swipe) return
115
+ const level = levelEl()
116
+ if (!level) return
117
+ swipe = { id: e.pointerId, x: e.clientX, y: e.clientY, level, width: navBox.value!.clientWidth, active: false, lastX: e.clientX, lastT: e.timeStamp, vel: 0 }
118
+ window.addEventListener('pointermove', onMove)
119
+ window.addEventListener('pointerup', onUp)
120
+ window.addEventListener('pointercancel', onCancel)
121
+ }
122
+
123
+ function writeDrag(dx: number) {
124
+ if (!swipe) return
125
+ swipe.level.style.transform = `translateX(${dx}px)`
126
+ swipe.level.style.opacity = String(1 - 0.5 * Math.min(1, dx / swipe.width))
127
+ }
128
+
129
+ function onMove(e: PointerEvent) {
130
+ if (!swipe || e.pointerId !== swipe.id) return
131
+ const dx = e.clientX - swipe.x
132
+ const dy = e.clientY - swipe.y
133
+ if (!swipe.active) {
134
+ if (Math.hypot(dx, dy) < SWIPE_SLOP) return
135
+ // Vertical (a scroll) or leftwards: not ours
136
+ if (Math.abs(dy) > Math.abs(dx) || dx < 0) return stopListening()
137
+ swipe.active = true
138
+ swipe.x = e.clientX
139
+ swipe.level.getAnimations().forEach((a) => a.finish())
140
+ }
141
+ const dt = e.timeStamp - swipe.lastT
142
+ if (dt > 0) swipe.vel = 0.8 * ((e.clientX - swipe.lastX) / dt) + 0.2 * swipe.vel
143
+ swipe.lastX = e.clientX
144
+ swipe.lastT = e.timeStamp
145
+ writeDrag(Math.max(0, e.clientX - swipe.x))
146
+ }
147
+
148
+ function onUp(e: PointerEvent) {
149
+ if (!swipe || e.pointerId !== swipe.id) return
150
+ const s = swipe
151
+ stopListening()
152
+ if (!s.active) return
153
+ // The finger lifted on an item: that's not a tap on it. The click comes in a later task, so the guard
154
+ // waits for it a little while
155
+ window.addEventListener('click', swallowClick, { capture: true, once: true })
156
+ clearTimeout(swallowTimer)
157
+ swallowTimer = setTimeout(stopSwallowing, 400)
158
+ const dx = Math.max(0, e.clientX - s.x)
159
+ if (dx > s.width * SWIPE_DISTANCE || s.vel > SWIPE_VELOCITY) {
160
+ leaveFromX = dx
161
+ leaveFromOpacity = Number(s.level.style.opacity || 1)
162
+ popNav()
163
+ }
164
+ else settleBack(s.level, dx)
165
+ }
166
+
167
+ function onCancel(e: PointerEvent) {
168
+ if (!swipe || e.pointerId !== swipe.id) return
169
+ const s = swipe
170
+ stopListening()
171
+ if (s.active) settleBack(s.level, Math.max(0, s.lastX - s.x))
172
+ }
173
+
174
+ function settleBack(level: HTMLElement, dx: number) {
175
+ level.style.transform = ''
176
+ level.style.opacity = ''
177
+ if (prefersReducedMotion() || dx < 1) return
178
+ const width = navBox.value?.clientWidth || 1
179
+ playSamples(level, sampleSpring(dx, 0, 0, motionSprings.standard.defaultSpatial, 0.5), (x) => ({
180
+ transform: `translateX(${x}px)`,
181
+ opacity: String(1 - 0.5 * Math.min(1, x / width)),
182
+ }))
183
+ }
184
+
185
+ let swallowTimer: ReturnType<typeof setTimeout> | undefined
186
+ function stopSwallowing() {
187
+ clearTimeout(swallowTimer)
188
+ window.removeEventListener('click', swallowClick, { capture: true })
189
+ }
190
+
191
+ function swallowClick(e: Event) {
192
+ e.stopPropagation()
193
+ e.preventDefault()
194
+ }
195
+
196
+ function stopListening() {
197
+ swipe = null
198
+ window.removeEventListener('pointermove', onMove)
199
+ window.removeEventListener('pointerup', onUp)
200
+ window.removeEventListener('pointercancel', onCancel)
201
+ }
202
+
203
+ onUnmounted(() => {
204
+ stopListening()
205
+ stopSwallowing()
206
+ })
207
+
208
+ return { navStack, currentNav, navBox, navSlideEnter, navSlideLeave, pushNav, popNav, resetNav, onNavPointerDown }
209
+ }
@@ -0,0 +1,78 @@
1
+ import { getCurrentInstance, onBeforeUnmount, toValue, watch, type MaybeRefOrGetter, type WatchSource } from 'vue'
2
+
3
+ export interface AutoGrowOptions {
4
+ /** Fewest rows it shrinks to (default 1) */
5
+ minRows?: MaybeRefOrGetter<number | undefined>
6
+ /** Most rows it grows to; past them it scrolls. Unset grows without limit */
7
+ maxRows?: MaybeRefOrGetter<number | undefined>
8
+ /**
9
+ * The text, when it can change without typing (cleared after sending, an emoji inserted…): a ref or getter, so the
10
+ * height follows. Typing is followed on its own
11
+ */
12
+ value?: WatchSource<unknown>
13
+ }
14
+
15
+ /**
16
+ * Makes a `<textarea>` grow with its text, between `minRows` and `maxRows` rows, scrolling past the last one: a chat
17
+ * composer, a comment box. Works on any textarea, styled however you like (rows are measured from its computed line
18
+ * height, padding and border). It also follows width changes, which rewrap the text. Returns `resize()` for anything
19
+ * else that changes the text.
20
+ */
21
+ export function useAutoGrow(target: MaybeRefOrGetter<HTMLTextAreaElement | null | undefined>, options: AutoGrowOptions = {}) {
22
+ let el: HTMLTextAreaElement | null = null
23
+ let observer: ResizeObserver | null = null
24
+ let lastWidth = 0
25
+
26
+ function resize() {
27
+ if (!el) return
28
+ const cs = getComputedStyle(el)
29
+ const px = (v: string) => parseFloat(v) || 0
30
+ // `normal` line height has no number: about 1.5× the font size
31
+ const lineHeight = px(cs.lineHeight) || px(cs.fontSize) * 1.5 || 24
32
+ const padding = px(cs.paddingTop) + px(cs.paddingBottom)
33
+ const border = cs.boxSizing === 'border-box' ? px(cs.borderTopWidth) + px(cs.borderBottomWidth) : 0
34
+ const extra = (cs.boxSizing === 'border-box' ? padding : 0) + border
35
+ const min = (toValue(options.minRows) ?? 1) * lineHeight + extra
36
+ const maxRows = toValue(options.maxRows)
37
+ const max = maxRows ? maxRows * lineHeight + extra : Infinity
38
+
39
+ // Collapse first so scrollHeight measures the text, not the current height
40
+ el.style.height = 'auto'
41
+ const content = el.scrollHeight + border + (cs.boxSizing === 'border-box' ? 0 : -padding)
42
+ const height = Math.min(max, Math.max(min, content))
43
+ el.style.height = `${height}px`
44
+ el.style.overflowY = content > max ? 'auto' : 'hidden'
45
+ }
46
+
47
+ function attach(next: HTMLTextAreaElement | null | undefined) {
48
+ if (el) {
49
+ el.removeEventListener('input', resize)
50
+ observer?.disconnect()
51
+ // Released (autoGrow turned off, another element): back to its own height
52
+ el.style.height = ''
53
+ el.style.overflowY = ''
54
+ }
55
+ el = next ?? null
56
+ if (!el) return
57
+ el.addEventListener('input', resize)
58
+ if (typeof ResizeObserver !== 'undefined') {
59
+ // Only width changes rewrap the text; our own height writes would otherwise loop
60
+ observer ??= new ResizeObserver(([entry]) => {
61
+ const w = entry!.contentRect.width
62
+ if (w !== lastWidth) {
63
+ lastWidth = w
64
+ resize()
65
+ }
66
+ })
67
+ observer.observe(el)
68
+ }
69
+ resize()
70
+ }
71
+
72
+ watch(() => toValue(target), attach, { immediate: true, flush: 'post' })
73
+ watch([() => toValue(options.minRows), () => toValue(options.maxRows)], () => resize(), { flush: 'post' })
74
+ if (options.value) watch(options.value, () => resize(), { flush: 'post' })
75
+ if (getCurrentInstance()) onBeforeUnmount(() => attach(null))
76
+
77
+ return { resize }
78
+ }
@@ -235,6 +235,9 @@ export interface M3Locale {
235
235
  mapDeleteMeasurement: string
236
236
  mapTotal: string
237
237
  mapSearchPlaces: string
238
+ /** MTimeline's button past `limit`; `{count}` is how many entries are hidden */
239
+ timelineShowMore: string
240
+ timelineShowLess: string
238
241
  }
239
242
 
240
243
  export const defaultLocale: M3Locale = {
@@ -451,6 +454,8 @@ export const defaultLocale: M3Locale = {
451
454
  mapDeleteMeasurement: 'Delete measurement',
452
455
  mapTotal: 'Total',
453
456
  mapSearchPlaces: 'Search places',
457
+ timelineShowMore: 'Show {count} more',
458
+ timelineShowLess: 'Show less',
454
459
  }
455
460
 
456
461
  export const M3_LOCALE_KEY: InjectionKey<MaybeRef<Partial<M3Locale>>> = Symbol('m3-locale')
@@ -1,4 +1,4 @@
1
- import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, watch, type ComputedRef, type InjectionKey, type Ref, type ShallowRef } from 'vue'
1
+ import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, provide, toValue, watch, type ComputedRef, type InjectionKey, type MaybeRefOrGetter, type Ref, type ShallowRef } from 'vue'
2
2
  import type * as Maplibre from 'maplibre-gl'
3
3
  import type { MapLayerModel } from './mapAdapters'
4
4
  import type { MapLayerState } from './useMapLayers'
@@ -28,21 +28,59 @@ export interface MapContext {
28
28
  // Internal: provided by MMap
29
29
  export const MAP_KEY: InjectionKey<MapContext> = Symbol('m3-map')
30
30
 
31
+ /**
32
+ * A map to use from outside `<MMap>`: the `MMap` itself (a template ref: `<MMap ref="map">` → `:map="map"`) or its
33
+ * `context`. Null or undefined until it mounts.
34
+ */
35
+ export type MapSource = { context: MapContext } | MapContext | null | undefined
36
+
37
+ /**
38
+ * Internal: the enclosing MMap's context or, outside one, a context that follows `source` (empty until it's
39
+ * there), provided to the caller's children too. Null when there's neither.
40
+ */
41
+ export function resolveMapContext(source?: MaybeRefOrGetter<MapSource>): MapContext | null {
42
+ const injected = inject(MAP_KEY, null)
43
+ if (injected || source === undefined) return injected
44
+ const ctx = computed(() => {
45
+ const s = toValue(source)
46
+ return !s ? undefined : 'context' in s ? s.context : s
47
+ })
48
+ const empty = { visible: {} as Record<string, boolean>, opacity: {} as Record<string, number> }
49
+ const forwarded = {
50
+ map: computed(() => ctx.value?.map.value),
51
+ maplibre: computed(() => ctx.value?.maplibre.value),
52
+ styleVersion: computed(() => ctx.value?.styleVersion.value ?? 0),
53
+ model: computed(() => ctx.value?.model.value),
54
+ // Reads and writes reach the map's own state once it's there
55
+ layerState: new Proxy(empty, { get: (target, key) => Reflect.get(ctx.value?.layerState ?? target, key) }),
56
+ activeTool: computed({
57
+ get: () => ctx.value?.activeTool.value ?? null,
58
+ set: (v) => { if (ctx.value) ctx.value.activeTool.value = v },
59
+ }),
60
+ } as unknown as MapContext
61
+ provide(MAP_KEY, forwarded)
62
+ return forwarded
63
+ }
64
+
31
65
  type MapEventType = keyof Maplibre.MapEventType
32
66
  type LayerEventType = keyof Maplibre.MapLayerEventType
33
67
 
34
68
  /**
35
69
  * 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.
70
+ * `MMap`). Listeners added through it are removed when the component unmounts. Outside an `MMap` (a side panel),
71
+ * pass it one: the `MMap`'s template ref, or a getter for it; until it mounts, `map` is undefined and `onReady` waits.
37
72
  *
38
73
  * ```ts
39
74
  * const { map, onLayer } = useMap()
40
75
  * onLayer('click', 'parcels-fill', (e) => console.log(e.features?.[0]?.properties))
76
+ *
77
+ * // In a panel next to the map: <MMap ref="mapRef"> … <MyPanel :map="mapRef" />
78
+ * const { map } = useMap(() => props.map)
41
79
  * ```
42
80
  */
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>')
81
+ export function useMap(source?: MaybeRefOrGetter<MapSource>) {
82
+ const ctx = resolveMapContext(source)
83
+ if (!ctx) throw new Error('useMap() must be called in a component inside <MMap>, or be given one')
46
84
  const cleanups: (() => void)[] = []
47
85
  if (getCurrentInstance()) onBeforeUnmount(() => cleanups.splice(0).forEach((fn) => fn()))
48
86
 
@@ -1,6 +1,6 @@
1
- import { inject } from 'vue'
1
+ import type { MaybeRefOrGetter } from 'vue'
2
2
  import type * as Maplibre from 'maplibre-gl'
3
- import { MAP_KEY } from './useMap'
3
+ import { resolveMapContext, type MapSource } from './useMap'
4
4
 
5
5
  // The style's own filter of each layer we filter (undefined: none), per map
6
6
  const originals = new WeakMap<Maplibre.Map, Map<string, Maplibre.FilterSpecification | undefined>>()
@@ -9,10 +9,11 @@ const originals = new WeakMap<Maplibre.Map, Map<string, Maplibre.FilterSpecifica
9
9
  * Filters for the layers of the enclosing `MMap`, on top of the filters their style already has (a layer that only
10
10
  * draws parks keeps doing so): `setFilter(layer, expression)` combines both, `setFilter(layer, null)` brings the
11
11
  * style's back. `MMapFilter` is built on it; use it for filters of your own (a range slider, a date, a search…).
12
+ * Outside an `MMap`, pass it one (its template ref), as with `useMap`.
12
13
  */
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>')
14
+ export function useMapFilter(source?: MaybeRefOrGetter<MapSource>) {
15
+ const ctx = resolveMapContext(source)
16
+ if (!ctx) throw new Error('useMapFilter() must be called in a component inside <MMap>, or be given one')
16
17
 
17
18
  function setFilter(layerId: string, filter: Maplibre.FilterSpecification | null) {
18
19
  const map = ctx!.map.value
@@ -1,6 +1,6 @@
1
- import { computed, inject, reactive } from 'vue'
1
+ import { computed, reactive, type MaybeRefOrGetter } from 'vue'
2
2
  import type * as Maplibre from 'maplibre-gl'
3
- import { MAP_KEY } from './useMap'
3
+ import { resolveMapContext, type MapSource } from './useMap'
4
4
  import type { MapLayerInfo, MapLayerModel } from './mapAdapters'
5
5
 
6
6
  /** The paint properties that make each layer type transparent. */
@@ -43,11 +43,12 @@ export function readLayerState(state: MapLayerState, map: Maplibre.Map, model: M
43
43
  /**
44
44
  * The layers of the enclosing `MMap`'s style as its `adapter` describes them, with their visibility and opacity, for a
45
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.
46
+ * the map and to every component using it; a layer's `children` follow it. Outside an `MMap`, pass it one (its
47
+ * template ref), as with `useMap`.
47
48
  */
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>')
49
+ export function useMapLayers(source?: MaybeRefOrGetter<MapSource>) {
50
+ const ctx = resolveMapContext(source)
51
+ if (!ctx) throw new Error('useMapLayers() must be called in a component inside <MMap>, or be given one')
51
52
  const { map, model, layerState: state } = ctx
52
53
 
53
54
  const layers = computed(() => model.value?.layers ?? [])
@@ -0,0 +1,151 @@
1
+ import { getCurrentInstance, onBeforeUnmount, toValue, watch, type MaybeRefOrGetter } from 'vue'
2
+ import { motionSprings } from './motion'
3
+ import { playSamples, prefersReducedMotion, sampleSpring } from './_springAnimation'
4
+
5
+ /** How an element enters: from below, from a side, growing, or only fading. */
6
+ export type RevealEffect = 'fade-up' | 'fade' | 'scale' | 'slide-left' | 'slide-right'
7
+
8
+ export interface ScrollRevealOptions {
9
+ /** How it enters (default `'fade-up'`) */
10
+ effect?: RevealEffect
11
+ /** Distance in px for the slide effects (default 24) */
12
+ distance?: number
13
+ /** Delay in ms before it starts (default 0) */
14
+ delay?: number
15
+ /** Extra delay in ms for each next element revealed at the same time, so a list cascades in (default 60) */
16
+ stagger?: number
17
+ /** Reveal only the first time (default `true`); with `false` it hides again once it leaves the screen */
18
+ once?: boolean
19
+ /** How much of the element has to be visible, 0 to 1 (default 0.15) */
20
+ threshold?: number
21
+ /** Grows or shrinks the area that counts as visible, like IntersectionObserver's `rootMargin` (default `'0px'`) */
22
+ rootMargin?: string
23
+ /** Motion scheme of the springs: `'standard'` (default) or `'expressive'` (a little bounce) */
24
+ scheme?: 'standard' | 'expressive'
25
+ /** Pace: M3's fast, default or slow springs (default `'default'`); slow suits large, calm entrances */
26
+ speed?: 'fast' | 'default' | 'slow'
27
+ }
28
+
29
+ const OFFSET: Record<RevealEffect, (d: number) => { x: number; y: number; scale: number }> = {
30
+ 'fade-up': (d) => ({ x: 0, y: d, scale: 1 }),
31
+ fade: () => ({ x: 0, y: 0, scale: 1 }),
32
+ scale: () => ({ x: 0, y: 0, scale: 0.92 }),
33
+ 'slide-left': (d) => ({ x: d, y: 0, scale: 1 }),
34
+ 'slide-right': (d) => ({ x: -d, y: 0, scale: 1 }),
35
+ }
36
+
37
+ const hiddenStyle = (o: ReturnType<(typeof OFFSET)[RevealEffect]>) =>
38
+ ({ opacity: '0', transform: `translate(${o.x}px, ${o.y}px) scale(${o.scale})` })
39
+
40
+ /**
41
+ * Internal engine shared by `useScrollReveal` and `v-reveal`: one IntersectionObserver for a set of options.
42
+ * Elements are hidden (inline opacity/transform) when observed and play the springs in as they enter; the ones
43
+ * entering together cascade by `stagger`.
44
+ */
45
+ export function createReveal(options: ScrollRevealOptions = {}) {
46
+ const { effect = 'fade-up', distance = 24, delay = 0, stagger = 60, once = true, threshold = 0.15, rootMargin = '0px', scheme = 'standard', speed = 'default' } = options
47
+ const offset = OFFSET[effect](distance)
48
+ const springs = motionSprings[scheme]
49
+ const shown = new WeakSet<Element>()
50
+ const anims = new WeakMap<Element, Animation>()
51
+ const reduced = prefersReducedMotion()
52
+
53
+ function show(el: HTMLElement, wait: number) {
54
+ shown.add(el)
55
+ anims.get(el)?.cancel()
56
+ // End state inline, then the samples over it: nothing jumps when the animation ends
57
+ el.style.opacity = ''
58
+ el.style.transform = ''
59
+ const move = sampleSpring(0, 1, 0, springs[`${speed}Spatial`], 0.001)
60
+ const fade = sampleSpring(0, 1, 0, springs[`${speed}Effects`], 0.001)
61
+ const n = Math.max(move.length, fade.length)
62
+ const at = (s: number[], i: number) => s[Math.min(i, s.length - 1)]!
63
+ const frames = Array.from({ length: n }, (_, i) => i)
64
+ const anim = playSamples(el, frames, (i) => {
65
+ const m = at(move, i)
66
+ const k = 1 - m
67
+ return {
68
+ opacity: String(at(fade, i)),
69
+ transform: `translate(${offset.x * k}px, ${offset.y * k}px) scale(${1 - (1 - offset.scale) * k})`,
70
+ }
71
+ }, wait)
72
+ if (anim) {
73
+ // Before its delay the animation isn't applying yet: keep it hidden until then
74
+ anim.effect?.updateTiming({ fill: 'backwards' })
75
+ anims.set(el, anim)
76
+ }
77
+ }
78
+
79
+ function hide(el: HTMLElement) {
80
+ shown.delete(el)
81
+ anims.get(el)?.cancel()
82
+ Object.assign(el.style, hiddenStyle(offset))
83
+ }
84
+
85
+ const observer =
86
+ typeof IntersectionObserver === 'undefined' || reduced
87
+ ? null
88
+ : new IntersectionObserver(
89
+ (entries) => {
90
+ // Cascade in document order among the ones entering in this batch
91
+ const entering = entries
92
+ .filter((e) => e.isIntersecting && !shown.has(e.target))
93
+ .map((e) => e.target as HTMLElement)
94
+ .sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1))
95
+ entering.forEach((el, i) => {
96
+ show(el, delay + i * stagger)
97
+ if (once) observer!.unobserve(el)
98
+ })
99
+ if (!once) {
100
+ for (const e of entries) if (!e.isIntersecting && shown.has(e.target)) hide(e.target as HTMLElement)
101
+ }
102
+ },
103
+ { threshold, rootMargin },
104
+ )
105
+
106
+ return {
107
+ observe(el: Element) {
108
+ // Without an observer (server, old browser) or with reduced motion, it's simply there
109
+ if (!observer || shown.has(el)) return
110
+ hide(el as HTMLElement)
111
+ observer.observe(el)
112
+ },
113
+ unobserve(el: Element) {
114
+ observer?.unobserve(el)
115
+ anims.get(el)?.cancel()
116
+ },
117
+ disconnect() {
118
+ observer?.disconnect()
119
+ },
120
+ }
121
+ }
122
+
123
+ type Target = Element | null | undefined | Iterable<Element | null | undefined>
124
+
125
+ /**
126
+ * Reveals elements as they scroll into view: they fade (and slide or grow) in on M3's springs, cascading when
127
+ * several enter together. Pass an element, a template ref, an array of them, or a getter. Off with reduced motion:
128
+ * everything is simply there. For a single element in a template, `v-reveal` does the same.
129
+ */
130
+ export function useScrollReveal(target: MaybeRefOrGetter<Target>, options: ScrollRevealOptions = {}) {
131
+ const reveal = createReveal(options)
132
+ let current: Element[] = []
133
+ const list = (t: Target): Element[] =>
134
+ !t ? [] : t instanceof Element ? [t] : [...t].filter((e): e is Element => !!e)
135
+
136
+ watch(
137
+ () => list(toValue(target)),
138
+ (next) => {
139
+ for (const el of current) if (!next.includes(el)) reveal.unobserve(el)
140
+ for (const el of next) if (!current.includes(el)) reveal.observe(el)
141
+ current = next
142
+ },
143
+ { immediate: true, flush: 'post' },
144
+ )
145
+ if (getCurrentInstance()) onBeforeUnmount(() => reveal.disconnect())
146
+
147
+ return {
148
+ /** Stops watching (elements already revealed stay) */
149
+ stop: () => reveal.disconnect(),
150
+ }
151
+ }