@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,87 @@
1
+ import type { Directive } from 'vue'
2
+
3
+ /** Options for `v-skeleton`. */
4
+ export interface SkeletonOptions {
5
+ /** Shows the placeholder while true. */
6
+ loading?: boolean
7
+ /** MSkeleton's animations (default `'pulse'`). */
8
+ animation?: 'pulse' | 'wave' | 'none'
9
+ }
10
+
11
+ /** `v-skeleton` value: whether it's loading, or an options object. */
12
+ export type SkeletonValue = boolean | SkeletonOptions | null | undefined
13
+
14
+ function normalize(value: SkeletonValue): Required<SkeletonOptions> {
15
+ if (value == null || typeof value === 'boolean') return { loading: !!value, animation: 'pulse' }
16
+ return { loading: !!value.loading, animation: value.animation ?? 'pulse' }
17
+ }
18
+
19
+ interface SkeletonState {
20
+ shimmer: HTMLSpanElement | null
21
+ madeRelative: boolean
22
+ }
23
+
24
+ const states = new WeakMap<HTMLElement, SkeletonState>()
25
+
26
+ // The look is in theme.css (`[data-m3-skeleton]`): the element keeps its size and corners, its content turns
27
+ // invisible (but still lays out), and its background becomes MSkeleton's tint
28
+ function apply(el: HTMLElement, state: SkeletonState, value: SkeletonValue) {
29
+ const { loading, animation } = normalize(value)
30
+ if (!loading) return clear(el, state)
31
+ el.dataset.m3Skeleton = animation
32
+ el.setAttribute('aria-busy', 'true')
33
+ if (animation === 'wave') {
34
+ const { position } = getComputedStyle(el)
35
+ if (!state.madeRelative && (!position || position === 'static')) {
36
+ el.style.position = 'relative'
37
+ state.madeRelative = true
38
+ }
39
+ if (!state.shimmer) {
40
+ state.shimmer = document.createElement('span')
41
+ state.shimmer.className = 'm3-skeleton-shimmer'
42
+ state.shimmer.setAttribute('aria-hidden', 'true')
43
+ }
44
+ if (state.shimmer.parentNode !== el) el.appendChild(state.shimmer)
45
+ }
46
+ else state.shimmer?.remove()
47
+ }
48
+
49
+ function clear(el: HTMLElement, state: SkeletonState) {
50
+ delete el.dataset.m3Skeleton
51
+ el.removeAttribute('aria-busy')
52
+ state.shimmer?.remove()
53
+ if (state.madeRelative) {
54
+ el.style.position = ''
55
+ state.madeRelative = false
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Turns an element into its own loading placeholder: `v-skeleton="loading"` or
61
+ * `v-skeleton="{ loading, animation }"`. While loading it keeps its size and corners, hides its content (which
62
+ * still sizes it: placeholder text like `{{ user?.name ?? 'Loading name' }}` gives an empty element a width),
63
+ * takes MSkeleton's tint and animation (`pulse`, `wave` or `none`; still with reduced motion), ignores the pointer
64
+ * and is `aria-busy`. Registered globally as `v-skeleton` by `createM3UI()`; import `vSkeleton` to use it
65
+ * without the plugin.
66
+ */
67
+ export const vSkeleton: Directive<HTMLElement, SkeletonValue> = {
68
+ // Server-rendered as a placeholder already (the wave's shimmer layer joins on the client)
69
+ getSSRProps(binding) {
70
+ const { loading, animation } = normalize(binding.value)
71
+ return loading ? { 'data-m3-skeleton': animation, 'aria-busy': 'true' } : {}
72
+ },
73
+ mounted(el, binding) {
74
+ const state: SkeletonState = { shimmer: null, madeRelative: false }
75
+ states.set(el, state)
76
+ apply(el, state, binding.value)
77
+ },
78
+ updated(el, binding) {
79
+ const state = states.get(el)
80
+ if (state) apply(el, state, binding.value)
81
+ },
82
+ beforeUnmount(el) {
83
+ const state = states.get(el)
84
+ if (state) clear(el, state)
85
+ states.delete(el)
86
+ },
87
+ }
@@ -0,0 +1,83 @@
1
+ import type { Directive } from 'vue'
2
+
3
+ /** Options for `v-state-layer`. */
4
+ export interface StateLayerOptions {
5
+ /** No state layer while true (e.g. bound to the element's disabled state). `disabled` / `aria-disabled="true"` hosts get none either way. */
6
+ disabled?: boolean
7
+ /** Any CSS color for the layer; defaults to the element's text color (`currentColor`). */
8
+ color?: string
9
+ /** Holds the dragged state (16%) while true, e.g. while the element is being dragged. */
10
+ dragged?: boolean
11
+ }
12
+
13
+ /** `v-state-layer` value: nothing or `true` (on), `false` (off), a CSS color, or an options object. */
14
+ export type StateLayerValue = boolean | string | StateLayerOptions | null | undefined
15
+
16
+ function normalize(value: StateLayerValue): StateLayerOptions {
17
+ if (value === false) return { disabled: true }
18
+ if (typeof value === 'string') return { color: value }
19
+ if (value === true || value == null) return {}
20
+ return value
21
+ }
22
+
23
+ interface StateLayerState {
24
+ layer: HTMLSpanElement
25
+ ensurePositioned: () => void
26
+ }
27
+
28
+ const states = new WeakMap<HTMLElement, StateLayerState>()
29
+
30
+ // The opacities (hover 8%, focus 10%, pressed 10%, dragged 16%) live in theme.css, keyed on the host's
31
+ // `data-m3-state-layer`; this only keeps the layer, its color and that attribute in step with the value.
32
+ function apply(el: HTMLElement, layer: HTMLElement, options: StateLayerOptions) {
33
+ el.dataset.m3StateLayer = options.disabled ? 'off' : options.dragged ? 'dragged' : ''
34
+ layer.style.background = options.color ?? ''
35
+ }
36
+
37
+ /**
38
+ * The M3 state layer for any element: a tint in its text color at 8% on hover, 10% on keyboard focus and press,
39
+ * 16% while dragged. `<div v-state-layer>`, `v-state-layer="false"`, `v-state-layer="'#e91e63'"` or
40
+ * `v-state-layer="{ disabled, color, dragged }"`. Pairs with `v-ripple`. A statically positioned element is made
41
+ * `position: relative`. Registered globally as `v-state-layer` by `createM3UI()`; import `vStateLayer` to use it
42
+ * without the plugin.
43
+ */
44
+ export const vStateLayer: Directive<HTMLElement, StateLayerValue> = {
45
+ // The marker only (the layer itself is added on the client)
46
+ getSSRProps(binding) {
47
+ const o = normalize(binding.value)
48
+ return { 'data-m3-state-layer': o.disabled ? 'off' : o.dragged ? 'dragged' : '' }
49
+ },
50
+ mounted(el, binding) {
51
+ const layer = document.createElement('span')
52
+ layer.className = 'm3-state-layer'
53
+ layer.setAttribute('aria-hidden', 'true')
54
+ el.appendChild(layer)
55
+ const ensurePositioned = () => {
56
+ const { position } = getComputedStyle(el)
57
+ if (!position || position === 'static') el.style.position = 'relative'
58
+ }
59
+ // On mount, and again on the first hover or focus in case the element wasn't in the document yet
60
+ ensurePositioned()
61
+ el.addEventListener('pointerenter', ensurePositioned, { once: true })
62
+ el.addEventListener('focusin', ensurePositioned, { once: true })
63
+ states.set(el, { layer, ensurePositioned })
64
+ apply(el, layer, normalize(binding.value))
65
+ },
66
+ updated(el, binding) {
67
+ const state = states.get(el)
68
+ if (!state) return
69
+ // A re-render that replaced the host's children can drop the layer: put it back
70
+ if (state.layer.parentNode !== el) el.appendChild(state.layer)
71
+ apply(el, state.layer, normalize(binding.value))
72
+ },
73
+ beforeUnmount(el) {
74
+ const state = states.get(el)
75
+ if (state) {
76
+ el.removeEventListener('pointerenter', state.ensurePositioned)
77
+ el.removeEventListener('focusin', state.ensurePositioned)
78
+ state.layer.remove()
79
+ }
80
+ delete el.dataset.m3StateLayer
81
+ states.delete(el)
82
+ },
83
+ }
@@ -0,0 +1,197 @@
1
+ import type { Directive } from 'vue'
2
+
3
+ export type SwipeDirection = 'left' | 'right' | 'up' | 'down'
4
+
5
+ /** What a swipe handler gets. */
6
+ export interface SwipeInfo {
7
+ direction: SwipeDirection
8
+ /** Distance from where the press started, px (x grows rightwards, y downwards). */
9
+ dx: number
10
+ dy: number
11
+ /** Speed along the swipe's axis when the finger lifted, px/ms. */
12
+ velocity: number
13
+ /** The pointerup that ended it. */
14
+ event: PointerEvent
15
+ }
16
+
17
+ /** Options for `v-swipe`. */
18
+ export interface SwipeOptions {
19
+ left?: (info: SwipeInfo) => void
20
+ right?: (info: SwipeInfo) => void
21
+ up?: (info: SwipeInfo) => void
22
+ down?: (info: SwipeInfo) => void
23
+ /** Called for a swipe in any direction that has no handler of its own. Listens on both axes. */
24
+ handler?: (info: SwipeInfo) => void
25
+ /** How far (px) the finger has to travel for a slow swipe to count (default 50). */
26
+ threshold?: number
27
+ /** A swipe at least this fast (px/ms) counts whatever its length (default 0.5, a flick). */
28
+ velocity?: number
29
+ /** Called while the finger moves along a listened axis, for feedback (follow the finger, fade a hint). */
30
+ onMove?: (dx: number, dy: number, event: PointerEvent) => void
31
+ /** Called when the press ends, swiped or not (spring a moved element back). */
32
+ onEnd?: (swiped: boolean) => void
33
+ /** Also with a mouse drag (default false: swipes are for touch and pen). */
34
+ mouse?: boolean
35
+ /** Off while true. */
36
+ disabled?: boolean
37
+ }
38
+
39
+ /** `v-swipe` value: a handler for any direction, or an options object. */
40
+ export type SwipeValue = ((info: SwipeInfo) => void) | SwipeOptions | null | undefined
41
+
42
+ function normalize(value: SwipeValue): SwipeOptions {
43
+ if (value == null) return {}
44
+ return typeof value === 'function' ? { handler: value } : value
45
+ }
46
+
47
+ // Before this much movement a press is still a tap
48
+ const SLOP = 10
49
+
50
+ interface SwipeState {
51
+ options: SwipeOptions
52
+ press: { id: number, x: number, y: number, axis: 'x' | 'y' | null, lastX: number, lastY: number, lastT: number, vx: number, vy: number } | null
53
+ moved: boolean
54
+ onPointerDown: (e: PointerEvent) => void
55
+ onMove: (e: PointerEvent) => void
56
+ onUp: (e: PointerEvent) => void
57
+ onCancel: (e: PointerEvent) => void
58
+ onClick: (e: MouseEvent) => void
59
+ }
60
+
61
+ const states = new WeakMap<HTMLElement, SwipeState>()
62
+
63
+ function axes(o: SwipeOptions) {
64
+ const any = !!o.handler
65
+ return { x: any || !!o.left || !!o.right, y: any || !!o.up || !!o.down }
66
+ }
67
+
68
+ // The browser keeps panning along the axes nobody swipes on, and leaves the others to us (a drag the browser
69
+ // pans is cancelled for pointer events). Both axes: nothing pans from this element
70
+ function applyTouchAction(el: HTMLElement, o: SwipeOptions) {
71
+ const { x, y } = axes(o)
72
+ el.style.touchAction = o.disabled || (!x && !y) ? '' : x && y ? 'none' : x ? 'pan-y' : 'pan-x'
73
+ }
74
+
75
+ function stopListening(state: SwipeState) {
76
+ window.removeEventListener('pointermove', state.onMove)
77
+ window.removeEventListener('pointerup', state.onUp)
78
+ window.removeEventListener('pointercancel', state.onCancel)
79
+ }
80
+
81
+ // The click comes right after the finger lifts, if at all (touch fires none after a move): stop waiting for it
82
+ // a moment later, or a later keyboard click would be swallowed
83
+ function expireClickGuard(state: SwipeState) {
84
+ setTimeout(() => { state.moved = false }, 400)
85
+ }
86
+
87
+ /**
88
+ * Calls handlers when an element is swiped: `v-swipe="onSwipe"` (any direction, `info.direction` says which) or
89
+ * `v-swipe="{ left, right, up, down, threshold, velocity, onMove, onEnd, mouse, disabled }"`. A swipe counts past
90
+ * `threshold` px, or at any length when flicked faster than `velocity`. The element's `touch-action` is set from
91
+ * the directions you listen to: only left/right leaves vertical scrolling to the page (`pan-y`), only up/down the
92
+ * horizontal (`pan-x`), both block panning from it (`none`). The click a swipe ends in is swallowed. Registered
93
+ * globally as `v-swipe` by `createM3UI()`; import `vSwipe` to use it without the plugin.
94
+ */
95
+ export const vSwipe: Directive<HTMLElement, SwipeValue> = {
96
+ mounted(el, binding) {
97
+ const state: SwipeState = {
98
+ options: normalize(binding.value),
99
+ press: null,
100
+ moved: false,
101
+ onPointerDown(e) {
102
+ const o = state.options
103
+ if (o.disabled || state.press || e.button !== 0 || (!o.mouse && e.pointerType === 'mouse')) return
104
+ const { x, y } = axes(o)
105
+ if (!x && !y) return
106
+ state.moved = false
107
+ state.press = { id: e.pointerId, x: e.clientX, y: e.clientY, axis: null, lastX: e.clientX, lastY: e.clientY, lastT: e.timeStamp, vx: 0, vy: 0 }
108
+ window.addEventListener('pointermove', state.onMove)
109
+ window.addEventListener('pointerup', state.onUp)
110
+ window.addEventListener('pointercancel', state.onCancel)
111
+ },
112
+ onMove(e) {
113
+ const p = state.press
114
+ if (!p || e.pointerId !== p.id) return
115
+ const dx = e.clientX - p.x
116
+ const dy = e.clientY - p.y
117
+ if (!p.axis) {
118
+ if (Math.hypot(dx, dy) < SLOP) return
119
+ const { x, y } = axes(state.options)
120
+ const axis = Math.abs(dx) >= Math.abs(dy) ? 'x' : 'y'
121
+ // Along an axis nobody listens to: the page's (or the element's) own scroll
122
+ if ((axis === 'x' && !x) || (axis === 'y' && !y)) {
123
+ state.press = null
124
+ return stopListening(state)
125
+ }
126
+ p.axis = axis
127
+ state.moved = true
128
+ }
129
+ const dt = e.timeStamp - p.lastT
130
+ if (dt > 0) {
131
+ p.vx = 0.8 * ((e.clientX - p.lastX) / dt) + 0.2 * p.vx
132
+ p.vy = 0.8 * ((e.clientY - p.lastY) / dt) + 0.2 * p.vy
133
+ }
134
+ p.lastX = e.clientX
135
+ p.lastY = e.clientY
136
+ p.lastT = e.timeStamp
137
+ state.options.onMove?.(p.axis === 'x' ? dx : 0, p.axis === 'y' ? dy : 0, e)
138
+ },
139
+ onUp(e) {
140
+ const p = state.press
141
+ if (!p || e.pointerId !== p.id) return
142
+ state.press = null
143
+ stopListening(state)
144
+ if (!p.axis) return
145
+ expireClickGuard(state)
146
+ const o = state.options
147
+ const dx = e.clientX - p.x
148
+ const dy = e.clientY - p.y
149
+ // A pause before lifting ends the flick
150
+ const fresh = e.timeStamp - p.lastT < 100
151
+ const along = p.axis === 'x' ? dx : dy
152
+ const speed = fresh ? (p.axis === 'x' ? p.vx : p.vy) : 0
153
+ // Fast enough counts in the direction of the motion, as long as it ends on that side of the start
154
+ const swiped = Math.abs(along) >= (o.threshold ?? 50) || (Math.abs(speed) >= (o.velocity ?? 0.5) && Math.sign(speed) === Math.sign(along))
155
+ const direction: SwipeDirection = p.axis === 'x' ? (along > 0 ? 'right' : 'left') : (along > 0 ? 'down' : 'up')
156
+ const handler = swiped ? (o[direction] ?? o.handler) : undefined
157
+ if (handler) handler({ direction, dx, dy, velocity: Math.abs(speed), event: e })
158
+ o.onEnd?.(!!handler)
159
+ },
160
+ onCancel(e) {
161
+ const p = state.press
162
+ if (!p || e.pointerId !== p.id) return
163
+ state.press = null
164
+ stopListening(state)
165
+ if (!p.axis) return
166
+ expireClickGuard(state)
167
+ state.options.onEnd?.(false)
168
+ },
169
+ // A press that moved was a swipe (or an attempt), not a tap
170
+ onClick(e) {
171
+ if (!state.moved) return
172
+ state.moved = false
173
+ e.preventDefault()
174
+ e.stopPropagation()
175
+ },
176
+ }
177
+ states.set(el, state)
178
+ applyTouchAction(el, state.options)
179
+ el.addEventListener('pointerdown', state.onPointerDown)
180
+ el.addEventListener('click', state.onClick, true)
181
+ },
182
+ updated(el, binding) {
183
+ const state = states.get(el)
184
+ if (!state) return
185
+ state.options = normalize(binding.value)
186
+ applyTouchAction(el, state.options)
187
+ },
188
+ beforeUnmount(el) {
189
+ const state = states.get(el)
190
+ if (!state) return
191
+ stopListening(state)
192
+ el.removeEventListener('pointerdown', state.onPointerDown)
193
+ el.removeEventListener('click', state.onClick, true)
194
+ el.style.touchAction = ''
195
+ states.delete(el)
196
+ },
197
+ }
@@ -0,0 +1,128 @@
1
+ import type { Directive } from 'vue'
2
+ import { createTooltipTrigger, placeTooltip, type TooltipPlacement } from '../composables/_tooltipTrigger'
3
+
4
+ /** Options for `v-tooltip`. */
5
+ export interface TooltipOptions {
6
+ /** The tooltip's text; nothing shows while it's empty. */
7
+ text?: string
8
+ /** Side of the element it shows on (default `'top'`); it stays inside the window. */
9
+ placement?: TooltipPlacement
10
+ /** Delay before it shows on hover or keyboard focus, in ms (default 600, like MTooltip). */
11
+ delay?: number
12
+ /** Never shows while true. */
13
+ disabled?: boolean
14
+ }
15
+
16
+ /** `v-tooltip` value: the text, or an options object. */
17
+ export type TooltipValue = string | TooltipOptions | null | undefined
18
+
19
+ function normalize(value: TooltipValue): TooltipOptions {
20
+ if (value == null) return {}
21
+ return typeof value === 'string' ? { text: value } : value
22
+ }
23
+
24
+ // MTooltip's plain tooltip
25
+ const TIP_CLASS = 'pointer-events-none fixed z-400 min-h-6 min-w-10 max-w-[200px] rounded bg-inverse-surface px-2 py-1 text-body-small text-inverse-on-surface'
26
+
27
+ let nextId = 0
28
+
29
+ interface TooltipState {
30
+ options: TooltipOptions
31
+ tip: HTMLDivElement | null
32
+ // Tooltips still fading out, removed at once if the element goes away first
33
+ leaving: Set<HTMLDivElement>
34
+ id: string
35
+ trigger: ReturnType<typeof createTooltipTrigger>
36
+ }
37
+
38
+ const states = new WeakMap<HTMLElement, TooltipState>()
39
+
40
+ function open(el: HTMLElement, state: TooltipState) {
41
+ const { text, disabled, placement = 'top' } = state.options
42
+ if (!text || disabled) return
43
+ let tip = state.tip
44
+ if (!tip) {
45
+ tip = document.createElement('div')
46
+ tip.className = TIP_CLASS
47
+ tip.id = state.id
48
+ tip.setAttribute('role', 'tooltip')
49
+ document.body.appendChild(tip)
50
+ state.tip = tip
51
+ tip.animate?.([{ opacity: 0 }, { opacity: 1 }], { duration: 150 })
52
+ }
53
+ tip.textContent = text
54
+ const { top, left } = placeTooltip(el, tip, placement)
55
+ tip.style.top = `${top}px`
56
+ tip.style.left = `${left}px`
57
+ addDescribedBy(el, state.id)
58
+ }
59
+
60
+ function close(el: HTMLElement, state: TooltipState) {
61
+ const tip = state.tip
62
+ if (!tip) return
63
+ state.tip = null
64
+ removeDescribedBy(el, state.id)
65
+ const anim = tip.animate?.([{ opacity: 1 }, { opacity: 0 }], { duration: 100, fill: 'forwards' })
66
+ if (!anim) return tip.remove()
67
+ state.leaving.add(tip)
68
+ anim.onfinish = () => {
69
+ state.leaving.delete(tip)
70
+ tip.remove()
71
+ }
72
+ }
73
+
74
+ // While it shows, the element is described by it (aria-describedby), keeping any ids already there
75
+ function addDescribedBy(el: HTMLElement, id: string) {
76
+ const ids = (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean)
77
+ if (!ids.includes(id)) el.setAttribute('aria-describedby', [...ids, id].join(' '))
78
+ }
79
+ function removeDescribedBy(el: HTMLElement, id: string) {
80
+ const ids = (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter((x) => x && x !== id)
81
+ if (ids.length) el.setAttribute('aria-describedby', ids.join(' '))
82
+ else el.removeAttribute('aria-describedby')
83
+ }
84
+
85
+ /**
86
+ * MTooltip's plain tooltip on any element, without wrapping it: `v-tooltip="'Save'"` or
87
+ * `v-tooltip="{ text, placement, delay, disabled }"`. Shows after a delay on mouse hover, on keyboard focus, and
88
+ * on a long press on touch (swallowing that press's click, hiding 1.5s after the finger lifts); Escape and
89
+ * scrolling hide it. Registered globally as `v-tooltip` by `createM3UI()`; import `vTooltip` to use it without
90
+ * the plugin.
91
+ */
92
+ export const vTooltip: Directive<HTMLElement, TooltipValue> = {
93
+ mounted(el, binding) {
94
+ const state = {
95
+ options: normalize(binding.value),
96
+ tip: null,
97
+ leaving: new Set(),
98
+ id: `m3-tooltip-${++nextId}`,
99
+ } as unknown as TooltipState
100
+ state.trigger = createTooltipTrigger(el, {
101
+ delay: () => state.options.delay ?? 600,
102
+ visible: () => !!state.tip,
103
+ open: () => open(el, state),
104
+ close: () => close(el, state),
105
+ tip: () => state.tip,
106
+ })
107
+ states.set(el, state)
108
+ },
109
+ updated(el, binding) {
110
+ const state = states.get(el)
111
+ if (!state) return
112
+ state.options = normalize(binding.value)
113
+ // Showing: follow the new text, or hide when it went empty or disabled
114
+ if (state.tip) {
115
+ if (!state.options.text || state.options.disabled) state.trigger.closeNow()
116
+ else open(el, state)
117
+ }
118
+ },
119
+ beforeUnmount(el) {
120
+ const state = states.get(el)
121
+ if (!state) return
122
+ state.trigger.destroy()
123
+ state.tip?.remove()
124
+ state.leaving.forEach((tip) => tip.remove())
125
+ removeDescribedBy(el, state.id)
126
+ states.delete(el)
127
+ },
128
+ }
package/src/index.ts CHANGED
@@ -15,6 +15,8 @@ export type { Palette, PaletteId, ActiveSeed, ContrastLevel } from './composable
15
15
  export { SEED_PALETTE } from './composables/useColorPalette'
16
16
  export { themeInitScript } from './composables/themeInitScript'
17
17
  export type { ThemeInitOptions } from './composables/themeInitScript'
18
+ export { viewportFromHeaders, VIEWPORT_HINTS } from './composables/viewportHints'
19
+ export type { RequestHeaders, ViewportSize } from './composables/viewportHints'
18
20
  export { generateScheme, schemeToCss, schemeRoles, seedFromImage, seedFromPixels } from './composables/dynamicColor'
19
21
  export type { SchemeVariant, SeedOptions, GeneratedScheme } from './composables/dynamicColor'
20
22
  export { useToast } from './composables/useToast'
@@ -23,6 +25,12 @@ export { useFieldBg } from './composables/useFieldBg'
23
25
  export { useLocale, defaultLocale } from './composables/useLocale'
24
26
  export type { M3Locale } from './composables/useLocale'
25
27
  export { useDevice } from './composables/useDevice'
28
+ export { useAutoGrow } from './composables/useAutoGrow'
29
+ export type { AutoGrowOptions } from './composables/useAutoGrow'
30
+ export { useThemeTokens } from './composables/useThemeTokens'
31
+ export type { ThemeTokensOptions } from './composables/useThemeTokens'
32
+ export { useScrollReveal } from './composables/useScrollReveal'
33
+ export type { ScrollRevealOptions, RevealEffect } from './composables/useScrollReveal'
26
34
  export { useWindowSizeClass, widthSizeClass, heightSizeClass } from './composables/useWindowSizeClass'
27
35
  export type { WidthSizeClass, HeightSizeClass, WindowSizeClassInfo } from './composables/useWindowSizeClass'
28
36
  export { useNotification } from './composables/useNotification'
@@ -36,6 +44,24 @@ export type { SpringSpec } from './composables/motion'
36
44
  // Directives
37
45
  export { vRipple } from './directives/vRipple'
38
46
  export type { RippleOptions, RippleValue } from './directives/vRipple'
47
+ export { vReveal } from './directives/vReveal'
48
+ export type { RevealValue } from './directives/vReveal'
49
+ export { vStateLayer } from './directives/vStateLayer'
50
+ export type { StateLayerOptions, StateLayerValue } from './directives/vStateLayer'
51
+ export { vTooltip } from './directives/vTooltip'
52
+ export type { TooltipOptions, TooltipValue } from './directives/vTooltip'
53
+ export { vFocusRing } from './directives/vFocusRing'
54
+ export type { FocusRingOptions, FocusRingValue } from './directives/vFocusRing'
55
+ export { vScrollElevation } from './directives/vScrollElevation'
56
+ export type { ScrollElevationOptions, ScrollElevationValue } from './directives/vScrollElevation'
57
+ export { vLongPress } from './directives/vLongPress'
58
+ export type { LongPressOptions, LongPressValue } from './directives/vLongPress'
59
+ export { vSwipe } from './directives/vSwipe'
60
+ export type { SwipeDirection, SwipeInfo, SwipeOptions, SwipeValue } from './directives/vSwipe'
61
+ export { vClickOutside } from './directives/vClickOutside'
62
+ export type { ClickOutsideOptions, ClickOutsideValue } from './directives/vClickOutside'
63
+ export { vSkeleton } from './directives/vSkeleton'
64
+ export type { SkeletonOptions, SkeletonValue } from './directives/vSkeleton'
39
65
 
40
66
  // Components
41
67
  export { default as MAbsolute } from './components/MAbsolute.vue'
@@ -154,6 +180,7 @@ export { default as MScheduler } from './components/MScheduler.vue'
154
180
  export { default as MScheme } from './components/MScheme.vue'
155
181
  export { default as MScrollable } from './components/MScrollable.vue'
156
182
  export { default as MSearchBar } from './components/MSearchBar.vue'
183
+ export { default as MSearchField } from './components/MSearchField.vue'
157
184
  export { default as MSection } from './components/MSection.vue'
158
185
  export { default as MSeekBar } from './components/MSeekBar.vue'
159
186
  export { default as MSegmentedButton } from './components/MSegmentedButton.vue'
@@ -235,7 +262,7 @@ export type { SpotlightResult } from './components/MSpotlightSearch.vue'
235
262
  export type { StepItem } from './components/MStepper.vue'
236
263
  export type { CommandItem } from './components/MCommandPalette.vue'
237
264
  export type { TableFetchParams } from './components/MTable.vue'
238
- export type { TimelineItem } from './components/MTimeline.vue'
265
+ export type { TimelineItem, TimelineStatus } from './components/MTimeline.vue'
239
266
  export type { TourStep } from './components/MTour.vue'
240
267
  export type { TransferItem } from './components/MTransferList.vue'
241
268
  export type { TreeNode } from './components/MTree.vue'
package/src/locales/de.ts CHANGED
@@ -226,4 +226,6 @@ export const deLocale: M3Locale = {
226
226
  mapDeleteMeasurement: 'Messung löschen',
227
227
  mapTotal: 'Gesamt',
228
228
  mapSearchPlaces: 'Orte suchen',
229
+ timelineShowMore: '{count} weitere anzeigen',
230
+ timelineShowLess: 'Weniger anzeigen',
229
231
  }
package/src/locales/es.ts CHANGED
@@ -226,4 +226,6 @@ export const esLocale: M3Locale = {
226
226
  mapDeleteMeasurement: 'Borrar medición',
227
227
  mapTotal: 'Total',
228
228
  mapSearchPlaces: 'Buscar lugares',
229
+ timelineShowMore: 'Mostrar {count} más',
230
+ timelineShowLess: 'Mostrar menos',
229
231
  }
package/src/locales/fr.ts CHANGED
@@ -226,4 +226,6 @@ export const frLocale: M3Locale = {
226
226
  mapDeleteMeasurement: 'Supprimer la mesure',
227
227
  mapTotal: 'Total',
228
228
  mapSearchPlaces: 'Rechercher un lieu',
229
+ timelineShowMore: 'Afficher {count} de plus',
230
+ timelineShowLess: 'Afficher moins',
229
231
  }
package/src/locales/ja.ts CHANGED
@@ -226,4 +226,6 @@ export const jaLocale: M3Locale = {
226
226
  mapDeleteMeasurement: '測定を削除',
227
227
  mapTotal: '合計',
228
228
  mapSearchPlaces: '場所を検索',
229
+ timelineShowMore: 'さらに {count} 件を表示',
230
+ timelineShowLess: '表示を減らす',
229
231
  }
package/src/locales/ko.ts CHANGED
@@ -226,4 +226,6 @@ export const koLocale: M3Locale = {
226
226
  mapDeleteMeasurement: '측정 삭제',
227
227
  mapTotal: '합계',
228
228
  mapSearchPlaces: '장소 검색',
229
+ timelineShowMore: '{count}개 더 보기',
230
+ timelineShowLess: '간략히 보기',
229
231
  }
package/src/locales/pt.ts CHANGED
@@ -226,4 +226,6 @@ export const ptLocale: M3Locale = {
226
226
  mapDeleteMeasurement: 'Apagar medição',
227
227
  mapTotal: 'Total',
228
228
  mapSearchPlaces: 'Pesquisar lugares',
229
+ timelineShowMore: 'Mostrar mais {count}',
230
+ timelineShowLess: 'Mostrar menos',
229
231
  }
package/src/locales/zh.ts CHANGED
@@ -226,4 +226,6 @@ export const zhLocale: M3Locale = {
226
226
  mapDeleteMeasurement: '删除测量',
227
227
  mapTotal: '总计',
228
228
  mapSearchPlaces: '搜索地点',
229
+ timelineShowMore: '再显示 {count} 项',
230
+ timelineShowLess: '收起',
229
231
  }
package/src/map.ts CHANGED
@@ -6,7 +6,7 @@ export { default as MMapGeoJson } from './components/MMapGeoJson.vue'
6
6
  export type { MapGeoJsonLayer } from './components/MMapGeoJson.vue'
7
7
  export { default as MMapControl } from './components/MMapControl.vue'
8
8
  export { useMap } from './composables/useMap'
9
- export type { MapContext, MaplibreModule } from './composables/useMap'
9
+ export type { MapContext, MapSource, MaplibreModule } from './composables/useMap'
10
10
  export { default as MMapLayers } from './components/MMapLayers.vue'
11
11
  export { default as MMapBaseLayers } from './components/MMapBaseLayers.vue'
12
12
  export { default as MMapIdentify } from './components/MMapIdentify.vue'