@m3ui-vue/m3ui-vue 1.1.3 → 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 (236) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +579 -40
  3. package/dist/MMenuItem-DI351kIf.js +929 -0
  4. package/dist/MMenuItem-DI351kIf.js.map +1 -0
  5. package/dist/MSlider-BnEy5ieZ.js +1500 -0
  6. package/dist/MSlider-BnEy5ieZ.js.map +1 -0
  7. package/dist/MTextField-BBmkaIbO.js +633 -0
  8. package/dist/MTextField-BBmkaIbO.js.map +1 -0
  9. package/dist/api.json +1 -1
  10. package/dist/chart.js +83 -49
  11. package/dist/chart.js.map +1 -1
  12. package/dist/code-editor.js +1 -1
  13. package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
  14. package/dist/components/MButton.vue.d.ts +9 -1
  15. package/dist/components/MButtonGroup.vue.d.ts +40 -31
  16. package/dist/components/MCarousel.vue.d.ts +2 -0
  17. package/dist/components/MChart.vue.d.ts +6 -0
  18. package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
  19. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  20. package/dist/components/MContextMenu.vue.d.ts +2 -2
  21. package/dist/components/MCopyButton.vue.d.ts +1 -1
  22. package/dist/components/MDialog.vue.d.ts +8 -5
  23. package/dist/components/MExportButton.vue.d.ts +1 -1
  24. package/dist/components/MFab.vue.d.ts +2 -2
  25. package/dist/components/MFabMenu.vue.d.ts +1 -1
  26. package/dist/components/MFlex.vue.d.ts +1 -1
  27. package/dist/components/MIconButton.vue.d.ts +15 -1
  28. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  29. package/dist/components/MListItem.vue.d.ts +5 -5
  30. package/dist/components/MMap.vue.d.ts +20 -2
  31. package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
  32. package/dist/components/MMapFilter.vue.d.ts +3 -0
  33. package/dist/components/MMapLayers.vue.d.ts +3 -0
  34. package/dist/components/MMenu.vue.d.ts +2 -2
  35. package/dist/components/MMenuItem.vue.d.ts +7 -3
  36. package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
  37. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  38. package/dist/components/MOverlay.vue.d.ts +12 -1
  39. package/dist/components/MProgressBar.vue.d.ts +5 -3
  40. package/dist/components/MPullToRefresh.vue.d.ts +7 -2
  41. package/dist/components/MRichTextEditor.vue.d.ts +7 -1
  42. package/dist/components/MSearchField.vue.d.ts +58 -0
  43. package/dist/components/MSegmentedButton.vue.d.ts +31 -23
  44. package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
  45. package/dist/components/MSkeleton.vue.d.ts +6 -3
  46. package/dist/components/MSplitter.vue.d.ts +1 -1
  47. package/dist/components/MStack.vue.d.ts +1 -1
  48. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  49. package/dist/components/MSwitch.vue.d.ts +1 -1
  50. package/dist/components/MTextField.vue.d.ts +5 -1
  51. package/dist/components/MTimeline.vue.d.ts +85 -22
  52. package/dist/components/MToolbar.vue.d.ts +32 -5
  53. package/dist/components/MTooltip.vue.d.ts +1 -1
  54. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  55. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  56. package/dist/composables/_containerTransform.d.ts +48 -0
  57. package/dist/composables/_mapStyle.d.ts +13 -0
  58. package/dist/composables/_themeTransition.d.ts +2 -0
  59. package/dist/composables/_tooltipTrigger.d.ts +22 -0
  60. package/dist/composables/_useMenuNav.d.ts +28 -0
  61. package/dist/composables/useAutoGrow.d.ts +21 -0
  62. package/dist/composables/useColorPalette.d.ts +1 -1
  63. package/dist/composables/useContainerTransform.d.ts +30 -0
  64. package/dist/composables/useLocale.d.ts +6 -0
  65. package/dist/composables/useMap.d.ts +19 -3
  66. package/dist/composables/useMapFilter.d.ts +4 -1
  67. package/dist/composables/useMapLayers.d.ts +5 -2
  68. package/dist/composables/useScrollReveal.d.ts +44 -0
  69. package/dist/composables/useThemeTokens.d.ts +21 -0
  70. package/dist/composables/viewportHints.d.ts +27 -0
  71. package/dist/directives/vClickOutside.d.ts +25 -0
  72. package/dist/directives/vFocusRing.d.ts +22 -0
  73. package/dist/directives/vLongPress.d.ts +27 -0
  74. package/dist/directives/vReveal.d.ts +10 -0
  75. package/dist/directives/vScrollElevation.d.ts +31 -0
  76. package/dist/directives/vSkeleton.d.ts +19 -0
  77. package/dist/directives/vStateLayer.d.ts +20 -0
  78. package/dist/directives/vSwipe.d.ts +45 -0
  79. package/dist/directives/vTooltip.d.ts +23 -0
  80. package/dist/index.d.ts +31 -1
  81. package/dist/locales/index.js +35 -7
  82. package/dist/locales/index.js.map +1 -1
  83. package/dist/m3ui-vue.css +1 -1
  84. package/dist/m3ui.js +7692 -6273
  85. package/dist/m3ui.js.map +1 -1
  86. package/dist/map.d.ts +1 -1
  87. package/dist/map.js +823 -793
  88. package/dist/map.js.map +1 -1
  89. package/dist/motion-DZiXG09o.js +150 -0
  90. package/dist/motion-DZiXG09o.js.map +1 -0
  91. package/dist/plugin.d.ts +24 -0
  92. package/dist/rich-text-editor.js +20 -16
  93. package/dist/rich-text-editor.js.map +1 -1
  94. package/dist/styles/theme.css +63 -0
  95. package/dist/styles.css +1 -1
  96. package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
  97. package/dist/useLocale-JYxDDeXC.js.map +1 -0
  98. package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
  99. package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
  100. package/package.json +2 -1
  101. package/src/__tests__/MAnimatedNumber.test.ts +24 -2
  102. package/src/__tests__/MButton.test.ts +22 -0
  103. package/src/__tests__/MCarousel.test.ts +9 -0
  104. package/src/__tests__/MChart.test.ts +77 -5
  105. package/src/__tests__/MContainerTransform.test.ts +279 -0
  106. package/src/__tests__/MDialog.test.ts +27 -0
  107. package/src/__tests__/MIconButton.test.ts +33 -0
  108. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  109. package/src/__tests__/MListItemShape.test.ts +9 -6
  110. package/src/__tests__/MListKeyboard.test.ts +90 -0
  111. package/src/__tests__/MMap.test.ts +53 -1
  112. package/src/__tests__/MMapLayers.test.ts +46 -2
  113. package/src/__tests__/MMapTools.test.ts +2 -1
  114. package/src/__tests__/MMenu.test.ts +104 -1
  115. package/src/__tests__/MMenuItem.test.ts +18 -0
  116. package/src/__tests__/MNavigationDrawer.test.ts +80 -0
  117. package/src/__tests__/MNavigationRail.test.ts +33 -0
  118. package/src/__tests__/MOverlay.test.ts +49 -0
  119. package/src/__tests__/MProgressBar.test.ts +41 -0
  120. package/src/__tests__/MPullToRefresh.test.ts +33 -0
  121. package/src/__tests__/MRichTextEditor.test.ts +22 -0
  122. package/src/__tests__/MSearchField.test.ts +71 -0
  123. package/src/__tests__/MSkeleton.test.ts +38 -0
  124. package/src/__tests__/MSlider.test.ts +161 -0
  125. package/src/__tests__/MTimeline.test.ts +238 -0
  126. package/src/__tests__/MToolbar.test.ts +157 -0
  127. package/src/__tests__/_fakeMaplibre.ts +3 -1
  128. package/src/__tests__/attrsFallthrough.test.ts +9 -0
  129. package/src/__tests__/escapeStack.test.ts +93 -0
  130. package/src/__tests__/hydration.test.ts +25 -0
  131. package/src/__tests__/ssr.test.ts +21 -2
  132. package/src/__tests__/useAutoGrow.test.ts +103 -0
  133. package/src/__tests__/useScrollReveal.test.ts +102 -0
  134. package/src/__tests__/useThemeTokens.test.ts +114 -0
  135. package/src/__tests__/vClickOutside.test.ts +82 -0
  136. package/src/__tests__/vFocusRing.test.ts +36 -0
  137. package/src/__tests__/vLongPress.test.ts +81 -0
  138. package/src/__tests__/vScrollElevation.test.ts +89 -0
  139. package/src/__tests__/vSkeleton.test.ts +48 -0
  140. package/src/__tests__/vStateLayer.test.ts +53 -0
  141. package/src/__tests__/vSwipe.test.ts +93 -0
  142. package/src/__tests__/vTooltip.test.ts +95 -0
  143. package/src/__tests__/viewportHints.test.ts +41 -0
  144. package/src/components/MAnimatedNumber.vue +32 -6
  145. package/src/components/MAutocomplete.vue +5 -0
  146. package/src/components/MBottomSheet.vue +4 -1
  147. package/src/components/MButton.vue +19 -3
  148. package/src/components/MButtonGroup.vue +22 -17
  149. package/src/components/MCarousel.vue +7 -1
  150. package/src/components/MChart.vue +74 -34
  151. package/src/components/MCircleProgressBar.vue +14 -9
  152. package/src/components/MCommandPalette.vue +3 -2
  153. package/src/components/MContainerTransform.vue +321 -0
  154. package/src/components/MContextMenu.vue +19 -60
  155. package/src/components/MDialog.vue +31 -6
  156. package/src/components/MDragDropList.vue +2 -0
  157. package/src/components/MFab.vue +10 -5
  158. package/src/components/MIconButton.vue +43 -2
  159. package/src/components/MKanban.vue +2 -0
  160. package/src/components/MLightbox.vue +7 -2
  161. package/src/components/MList.vue +26 -2
  162. package/src/components/MListItem.vue +138 -84
  163. package/src/components/MMap.vue +38 -5
  164. package/src/components/MMapBaseLayers.vue +7 -3
  165. package/src/components/MMapFilter.vue +7 -4
  166. package/src/components/MMapGeoJson.vue +1 -1
  167. package/src/components/MMapLayers.vue +6 -2
  168. package/src/components/MMapMeasure.vue +5 -2
  169. package/src/components/MMenu.vue +18 -59
  170. package/src/components/MMenuItem.vue +11 -2
  171. package/src/components/MMultiAutocomplete.vue +5 -0
  172. package/src/components/MNavigationDrawer.vue +96 -11
  173. package/src/components/MNavigationRail.vue +44 -25
  174. package/src/components/MOverlay.vue +32 -13
  175. package/src/components/MProgressBar.vue +25 -27
  176. package/src/components/MPullToRefresh.vue +20 -1
  177. package/src/components/MRichTextEditor.vue +19 -5
  178. package/src/components/MSearchBar.vue +5 -0
  179. package/src/components/MSearchField.vue +142 -0
  180. package/src/components/MSegmentedButton.vue +19 -17
  181. package/src/components/MSelect.vue +10 -1
  182. package/src/components/MSideSheet.vue +5 -2
  183. package/src/components/MSimpleCarousel.vue +10 -1
  184. package/src/components/MSkeleton.vue +30 -8
  185. package/src/components/MSlider.vue +161 -42
  186. package/src/components/MSpotlightSearch.vue +3 -2
  187. package/src/components/MTextField.vue +15 -2
  188. package/src/components/MTimeline.vue +370 -81
  189. package/src/components/MToolbar.vue +256 -15
  190. package/src/components/MTooltip.vue +20 -152
  191. package/src/components/_MDrawerItemList.vue +25 -6
  192. package/src/components/_MToolbarFab.vue +14 -0
  193. package/src/composables/_containerTransform.ts +179 -0
  194. package/src/composables/_mapStyle.ts +45 -0
  195. package/src/composables/_themeTransition.ts +2 -0
  196. package/src/composables/_tooltipTrigger.ts +184 -0
  197. package/src/composables/_useEscapeStack.ts +2 -0
  198. package/src/composables/_useMenuNav.ts +209 -0
  199. package/src/composables/useAutoGrow.ts +78 -0
  200. package/src/composables/useContainerTransform.ts +59 -0
  201. package/src/composables/useLocale.ts +10 -0
  202. package/src/composables/useMap.ts +43 -5
  203. package/src/composables/useMapFilter.ts +6 -5
  204. package/src/composables/useMapLayers.ts +7 -6
  205. package/src/composables/useScrollReveal.ts +151 -0
  206. package/src/composables/useThemeTokens.ts +116 -0
  207. package/src/composables/viewportHints.ts +80 -0
  208. package/src/directives/vClickOutside.ts +90 -0
  209. package/src/directives/vFocusRing.ts +60 -0
  210. package/src/directives/vLongPress.ts +134 -0
  211. package/src/directives/vReveal.ts +57 -0
  212. package/src/directives/vScrollElevation.ts +116 -0
  213. package/src/directives/vSkeleton.ts +87 -0
  214. package/src/directives/vStateLayer.ts +83 -0
  215. package/src/directives/vSwipe.ts +197 -0
  216. package/src/directives/vTooltip.ts +128 -0
  217. package/src/index.ts +31 -1
  218. package/src/locales/de.ts +4 -0
  219. package/src/locales/es.ts +4 -0
  220. package/src/locales/fr.ts +4 -0
  221. package/src/locales/ja.ts +4 -0
  222. package/src/locales/ko.ts +4 -0
  223. package/src/locales/pt.ts +4 -0
  224. package/src/locales/zh.ts +4 -0
  225. package/src/map.ts +1 -1
  226. package/src/plugin.ts +34 -0
  227. package/src/styles/theme.css +63 -0
  228. package/dist/MMenuItem-BckcR0nW.js +0 -809
  229. package/dist/MMenuItem-BckcR0nW.js.map +0 -1
  230. package/dist/MSlider-LyH_gy8D.js +0 -1411
  231. package/dist/MSlider-LyH_gy8D.js.map +0 -1
  232. package/dist/MTextField-FCPOTB0o.js +0 -672
  233. package/dist/MTextField-FCPOTB0o.js.map +0 -1
  234. package/dist/composables/_useThemeTokens.d.ts +0 -7
  235. package/dist/useLocale-SfQHnJfp.js.map +0 -1
  236. package/src/composables/_useThemeTokens.ts +0 -42
@@ -0,0 +1,179 @@
1
+ /*
2
+ * Internal (not exported from index.ts): Material's container transform, the engine behind MContainerTransform.
3
+ *
4
+ * A port of Material Components for Android's MaterialContainerTransform (transition/MaterialContainerTransform.java,
5
+ * FitModeEvaluators, FadeModeEvaluators, MaskEvaluator, TransitionUtils), with its defaults: linear path between the
6
+ * two boxes' top-centers, FIT_MODE_AUTO, FADE_MODE_IN, the non-arc progress thresholds, a 32% black scrim, 500ms
7
+ * (motionDurationLong2) to open and 400ms (motionDurationMedium4) to close on the emphasized curve. Both views keep
8
+ * their own layout and are scaled uniformly to the container's current width (or height), so nothing stretches;
9
+ * a rounded clip, the union of both masked boxes, morphs between their shapes. Android draws snapshots on a canvas;
10
+ * here the source is a clone, the destination the real panel, and every frame is computed up front and played as
11
+ * Web Animations (see _springAnimation.ts) so the compositor runs the transforms and opacities.
12
+ */
13
+ import { SAMPLE_MS } from './_springAnimation'
14
+
15
+ export interface Box { left: number; top: number; width: number; height: number }
16
+
17
+ interface Thresholds { fade: [number, number]; scale: [number, number]; scaleMask: [number, number]; shapeMask: [number, number] }
18
+ const ENTER: Thresholds = { fade: [0, 0.25], scale: [0, 1], scaleMask: [0, 1], shapeMask: [0, 0.75] }
19
+ const RETURN: Thresholds = { fade: [0.6, 0.9], scale: [0, 1], scaleMask: [0, 0.9], shapeMask: [0.3, 0.9] }
20
+
21
+ export const OPEN_MS = 500
22
+ export const CLOSE_MS = 400
23
+ export const SCRIM_OPACITY = 0x52 / 255
24
+
25
+ // Android's emphasized interpolator (motionEasingEmphasizedInterpolator): the path
26
+ // M 0,0 C 0.05,0 0.133333,0.06 0.166666,0.4 C 0.208333,0.82 0.25,1 1,1, not a single cubic
27
+ function segment(x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, x: number) {
28
+ let lo = 0
29
+ let hi = 1
30
+ for (let i = 0; i < 30; i++) {
31
+ const u = (lo + hi) / 2
32
+ const bx = (1 - u) ** 3 * x0 + 3 * (1 - u) ** 2 * u * x1 + 3 * (1 - u) * u ** 2 * x2 + u ** 3 * x3
33
+ if (bx < x) lo = u
34
+ else hi = u
35
+ }
36
+ const u = (lo + hi) / 2
37
+ return (1 - u) ** 3 * y0 + 3 * (1 - u) ** 2 * u * y1 + 3 * (1 - u) * u ** 2 * y2 + u ** 3 * y3
38
+ }
39
+ export function emphasized(t: number) {
40
+ if (t <= 0) return 0
41
+ if (t >= 1) return 1
42
+ return t < 0.166666
43
+ ? segment(0, 0, 0.05, 0, 0.133333, 0.06, 0.166666, 0.4, t)
44
+ : segment(0.166666, 0.4, 0.208333, 0.82, 0.25, 1, 1, 1, t)
45
+ }
46
+
47
+ const lerp = (a: number, b: number, f: number) => a + f * (b - a)
48
+ // TransitionUtils.lerp with start/end fractions (clamped outside them, like Android unless overshoot is allowed)
49
+ function lerpRange(a: number, b: number, [from, to]: [number, number], f: number) {
50
+ if (f < from) return a
51
+ if (f > to) return b
52
+ return lerp(a, b, (f - from) / (to - from))
53
+ }
54
+
55
+ /** Where a view sits: translate from its own resting box, uniform scale from its top-left corner, opacity */
56
+ export interface ViewState { x: number; y: number; scale: number; opacity: number }
57
+ export interface Frame {
58
+ /** The container's clip, in the same coordinates as the boxes, and its corner radius */
59
+ clip: Box
60
+ radius: number
61
+ start: ViewState
62
+ end: ViewState
63
+ scrim: number
64
+ }
65
+
66
+ /**
67
+ * The transition's state at progress `p` (already eased), from the `start` box to the `end` one. `entering` is the
68
+ * direction (Android's TRANSITION_DIRECTION_AUTO: the bigger box is the detail), which picks the thresholds and the
69
+ * fade: entering, the end view fades in on top of the start one; returning, the start one fades out on top.
70
+ */
71
+ export function containerFrame(p: number, start: Box, end: Box, startRadius: number, endRadius: number, entering: boolean): Frame {
72
+ const th = entering ? ENTER : RETURN
73
+
74
+ // FitModeEvaluators: fit to the width unless the end box, scaled to the start's width, ends up shorter
75
+ const fitWidth = entering
76
+ ? (end.height * start.width) / end.width >= start.height
77
+ : (start.height * end.width) / start.width >= end.height
78
+ let startScale: number
79
+ let endScale: number
80
+ if (fitWidth) {
81
+ const width = lerpRange(start.width, end.width, th.scale, p)
82
+ startScale = width / start.width
83
+ endScale = width / end.width
84
+ } else {
85
+ const height = lerpRange(start.height, end.height, th.scale, p)
86
+ startScale = height / start.height
87
+ endScale = height / end.height
88
+ }
89
+ const sw = start.width * startScale
90
+ const sh = start.height * startScale
91
+ const ew = end.width * endScale
92
+ const eh = end.height * endScale
93
+
94
+ // The linear motion path between the top-centers
95
+ const mx = lerp(start.left + start.width / 2, end.left + end.width / 2, p)
96
+ const my = lerp(start.top, end.top, p)
97
+ const startBox = { left: mx - sw / 2, top: my, width: sw, height: sh }
98
+ const endBox = { left: mx - ew / 2, top: my, width: ew, height: eh }
99
+
100
+ // Mask the taller (or wider) of the two down toward the other over the scale-mask range
101
+ const startMasked = { ...startBox }
102
+ const endMasked = { ...endBox }
103
+ const maskProgress = lerpRange(0, 1, th.scaleMask, p)
104
+ if (fitWidth) {
105
+ const maskStart = sh > eh
106
+ const target = maskStart ? startMasked : endMasked
107
+ target.height -= Math.abs(eh - sh) * (maskStart ? maskProgress : 1 - maskProgress)
108
+ } else {
109
+ const maskStart = sw > ew
110
+ const target = maskStart ? startMasked : endMasked
111
+ const diff = Math.abs(ew - sw) * (maskStart ? maskProgress : 1 - maskProgress)
112
+ target.left += diff / 2
113
+ target.width -= diff
114
+ }
115
+ const left = Math.min(startMasked.left, endMasked.left)
116
+ const top = Math.min(startMasked.top, endMasked.top)
117
+ const right = Math.max(startMasked.left + startMasked.width, endMasked.left + endMasked.width)
118
+ const bottom = Math.max(startMasked.top + startMasked.height, endMasked.top + endMasked.height)
119
+
120
+ const fade = lerpRange(0, 1, th.fade, p)
121
+ return {
122
+ clip: { left, top, width: right - left, height: bottom - top },
123
+ radius: lerpRange(startRadius, endRadius, th.shapeMask, p),
124
+ start: { x: startBox.left - start.left, y: startBox.top - start.top, scale: startScale, opacity: entering ? 1 : 1 - fade },
125
+ end: { x: endBox.left - end.left, y: endBox.top - end.top, scale: endScale, opacity: entering ? fade : 1 },
126
+ scrim: (entering ? p : 1 - p) * SCRIM_OPACITY,
127
+ }
128
+ }
129
+
130
+ /** Every frame of a transition, one per 60Hz frame of `duration` ms, on the emphasized curve */
131
+ export function containerFrames(start: Box, end: Box, startRadius: number, endRadius: number, entering: boolean, duration: number): Frame[] {
132
+ const n = Math.max(1, Math.round(duration / SAMPLE_MS))
133
+ return Array.from({ length: n + 1 }, (_, i) => containerFrame(emphasized(i / n), start, end, startRadius, endRadius, entering))
134
+ }
135
+
136
+ const view = (s: ViewState): Keyframe => ({ transform: `translate(${s.x}px, ${s.y}px) scale(${s.scale})`, opacity: s.opacity })
137
+
138
+ /**
139
+ * Plays `frames` on the clip layer (positioned at the viewport's origin, `vw` × `vh`), the two views and the scrim.
140
+ * Returns the running animations (empty without the Web Animations API). `fill: 'forwards'` holds the last frame
141
+ * (a closing run, until the layer is removed).
142
+ */
143
+ export function playContainerFrames(
144
+ frames: Frame[],
145
+ els: { clip: HTMLElement; start?: HTMLElement | null; end: HTMLElement; scrim?: HTMLElement | null },
146
+ vw: number,
147
+ vh: number,
148
+ fill?: FillMode,
149
+ ): Animation[] {
150
+ if (typeof els.end.animate !== 'function') return []
151
+ const duration = (frames.length - 1) * SAMPLE_MS
152
+ const options: KeyframeAnimationOptions = { duration, easing: 'linear', fill }
153
+ const clip = (f: Frame) => {
154
+ const { left, top, width, height } = f.clip
155
+ return `inset(${top}px ${vw - left - width}px ${vh - top - height}px ${left}px round ${f.radius}px)`
156
+ }
157
+ const anims = [
158
+ els.clip.animate(frames.map((f) => ({ clipPath: clip(f) })), options),
159
+ els.end.animate(frames.map((f) => view(f.end)), options),
160
+ ]
161
+ if (els.start) anims.push(els.start.animate(frames.map((f) => view(f.start)), options))
162
+ if (els.scrim) anims.push(els.scrim.animate(frames.map((f) => ({ opacity: f.scrim })), options))
163
+ for (const a of anims) a.finished.catch(() => {})
164
+ return anims
165
+ }
166
+
167
+ /** A resting box in viewport coordinates */
168
+ export function boxOf(el: Element): Box {
169
+ const r = el.getBoundingClientRect()
170
+ return { left: r.left, top: r.top, width: r.width, height: r.height }
171
+ }
172
+
173
+ /** An element's top-left corner radius in px (a percentage resolves against its width) */
174
+ export function radiusOf(el: Element): number {
175
+ const value = getComputedStyle(el).borderTopLeftRadius || '0'
176
+ const n = parseFloat(value)
177
+ if (Number.isNaN(n)) return 0
178
+ return value.trim().endsWith('%') ? (n / 100) * (el as HTMLElement).offsetWidth : n
179
+ }
@@ -0,0 +1,45 @@
1
+ import type * as Maplibre from 'maplibre-gl'
2
+
3
+ /*
4
+ * Internal (not exported from index.ts): what MMap carries over when `mapStyle` changes.
5
+ *
6
+ * MapLibre's setStyle() replaces everything, so sources and layers added at runtime (with useMap(), or the
7
+ * library's own MMapGeoJson / MMapMeasure) were gone after a switch, until whoever added them noticed. A
8
+ * `transformStyle` hook moves them into the next style instead: whatever wasn't part of the previous style as
9
+ * loaded (`own`) was added at runtime. The library's components re-add theirs only when missing, so they just find
10
+ * them there.
11
+ */
12
+
13
+ /** The ids a style came with, before anything was added at runtime */
14
+ export interface StyleIds {
15
+ sources: Set<string>
16
+ layers: Set<string>
17
+ }
18
+
19
+ export function styleIds(style: Pick<Maplibre.StyleSpecification, 'sources' | 'layers'> | undefined): StyleIds {
20
+ return {
21
+ sources: new Set(Object.keys(style?.sources ?? {})),
22
+ layers: new Set((style?.layers ?? []).map((l) => l.id)),
23
+ }
24
+ }
25
+
26
+ /**
27
+ * `next` with the runtime sources and layers of `previous` added: layers on top, in their order, unless `keep`
28
+ * says no or the next style has the same id; sources unless the next style has one by that id (it wins, and
29
+ * carried layers use it).
30
+ */
31
+ export function carryRuntimeLayers(
32
+ previous: Maplibre.StyleSpecification | undefined,
33
+ next: Maplibre.StyleSpecification,
34
+ own: StyleIds,
35
+ keep: (layer: Maplibre.LayerSpecification) => boolean = () => true,
36
+ ): Maplibre.StyleSpecification {
37
+ if (!previous) return next
38
+ const nextLayers = new Set(next.layers.map((l) => l.id))
39
+ const layers = previous.layers.filter((l) => !own.layers.has(l.id) && !nextLayers.has(l.id) && keep(l))
40
+ const sources = { ...next.sources }
41
+ for (const [id, source] of Object.entries(previous.sources)) {
42
+ if (!own.sources.has(id) && !(id in sources)) sources[id] = source
43
+ }
44
+ return { ...next, sources, layers: [...next.layers, ...layers] }
45
+ }
@@ -19,6 +19,8 @@ const COLOR_TOKENS = [
19
19
  ].map((t) => `--color-${t}`)
20
20
 
21
21
  const DURATION = 250
22
+ /** How long a theme switch's color transition takes, in ms (both paths) */
23
+ export const THEME_TRANSITION_MS = DURATION
22
24
  const STYLE_ID = 'm3-theme-transition'
23
25
 
24
26
  // Injected only while switching: a registered <color> computes to rgb(), and code reading a token with
@@ -0,0 +1,184 @@
1
+ /*
2
+ * Internal (not exported from index.ts): what opens and closes a tooltip, shared by MTooltip and v-tooltip.
3
+ *
4
+ * Input as Compose's BasicTooltip: a mouse shows it on hover after `delay`; touch and pen on a long press, which
5
+ * also swallows the click it would end in (a long-pressed button doesn't fire) and hides it TOUCH_DURATION after
6
+ * the finger lifts (BasicTooltipDefaults.TooltipDuration); focus only from the keyboard. Escape hides it (and
7
+ * stops there, so a dialog around it stays open), and so does any scroll. A rich tooltip closes a moment after
8
+ * the pointer leaves (so it can move onto the tooltip), and after a long press stays until a touch outside it.
9
+ */
10
+
11
+ export type TooltipPlacement = 'top' | 'bottom' | 'left' | 'right'
12
+
13
+ const LONG_PRESS = 500
14
+ const TOUCH_DURATION = 1500
15
+ const RICH_HIDE_DELAY = 120
16
+ const GAP = 4
17
+ const MARGIN = 6
18
+
19
+ /** Where `tip` goes next to `trigger`, kept 6px inside the window */
20
+ export function placeTooltip(trigger: HTMLElement, tip: HTMLElement, placement: TooltipPlacement) {
21
+ const tr = trigger.getBoundingClientRect()
22
+ const tt = tip.getBoundingClientRect()
23
+ let top = 0
24
+ let left = 0
25
+ switch (placement) {
26
+ case 'top': top = tr.top - tt.height - GAP; left = tr.left + (tr.width - tt.width) / 2; break
27
+ case 'bottom': top = tr.bottom + GAP; left = tr.left + (tr.width - tt.width) / 2; break
28
+ case 'left': top = tr.top + (tr.height - tt.height) / 2; left = tr.left - tt.width - GAP; break
29
+ case 'right': top = tr.top + (tr.height - tt.height) / 2; left = tr.right + GAP; break
30
+ }
31
+ top = Math.max(MARGIN, Math.min(top, window.innerHeight - tt.height - MARGIN))
32
+ left = Math.max(MARGIN, Math.min(left, window.innerWidth - tt.width - MARGIN))
33
+ return { top, left }
34
+ }
35
+
36
+ export interface TooltipTriggerOptions {
37
+ delay: () => number
38
+ rich?: () => boolean
39
+ visible: () => boolean
40
+ open: () => void
41
+ close: () => void
42
+ /** The tooltip's element while shown: a touch on it doesn't close a rich tooltip */
43
+ tip: () => HTMLElement | null | undefined
44
+ }
45
+
46
+ export function createTooltipTrigger(el: HTMLElement, o: TooltipTriggerOptions) {
47
+ let showTimer: ReturnType<typeof setTimeout> | undefined
48
+ let hideTimer: ReturnType<typeof setTimeout> | undefined
49
+ let press: { id: number, x: number, y: number, timer: ReturnType<typeof setTimeout> } | null = null
50
+ let longPressed = false
51
+ const rich = () => o.rich?.() ?? false
52
+
53
+ function cancel() {
54
+ clearTimeout(showTimer)
55
+ clearTimeout(hideTimer)
56
+ }
57
+ function show() {
58
+ cancel()
59
+ showTimer = setTimeout(o.open, o.delay())
60
+ }
61
+ function hide() {
62
+ cancel()
63
+ if (rich()) hideTimer = setTimeout(o.close, RICH_HIDE_DELAY)
64
+ else o.close()
65
+ }
66
+ function closeNow() {
67
+ cancel()
68
+ o.close()
69
+ }
70
+
71
+ function onPointerEnter(e: PointerEvent) {
72
+ if (e.pointerType === 'mouse') show()
73
+ }
74
+ function onPointerLeave(e: PointerEvent) {
75
+ if (e.pointerType === 'mouse') hide()
76
+ }
77
+
78
+ function endPress() {
79
+ if (press) clearTimeout(press.timer)
80
+ press = null
81
+ window.removeEventListener('pointermove', onPressMove)
82
+ window.removeEventListener('pointerup', onPressUp)
83
+ window.removeEventListener('pointercancel', onPressCancel)
84
+ }
85
+ function onPointerDown(e: PointerEvent) {
86
+ if (e.pointerType === 'mouse') return
87
+ endPress()
88
+ longPressed = false
89
+ press = {
90
+ id: e.pointerId,
91
+ x: e.clientX,
92
+ y: e.clientY,
93
+ timer: setTimeout(() => {
94
+ longPressed = true
95
+ cancel()
96
+ o.open()
97
+ }, LONG_PRESS),
98
+ }
99
+ window.addEventListener('pointermove', onPressMove)
100
+ window.addEventListener('pointerup', onPressUp)
101
+ window.addEventListener('pointercancel', onPressCancel)
102
+ }
103
+ function onPressMove(e: PointerEvent) {
104
+ if (press && e.pointerId === press.id && Math.hypot(e.clientX - press.x, e.clientY - press.y) > 10) endPress()
105
+ }
106
+ function onPressUp(e: PointerEvent) {
107
+ if (!press || e.pointerId !== press.id) return
108
+ endPress()
109
+ if (!longPressed) return
110
+ cancel()
111
+ // A rich tooltip may hold actions to tap: it stays until a touch outside it (Compose's persistent tooltips)
112
+ if (rich()) document.addEventListener('pointerdown', onOutsideTouch, true)
113
+ else hideTimer = setTimeout(o.close, TOUCH_DURATION)
114
+ }
115
+ function onOutsideTouch(e: PointerEvent) {
116
+ const t = e.target as Node
117
+ if (o.tip()?.contains(t) || el.contains(t)) return
118
+ document.removeEventListener('pointerdown', onOutsideTouch, true)
119
+ o.close()
120
+ }
121
+ // The browser took the touch (a scroll)
122
+ function onPressCancel(e: PointerEvent) {
123
+ if (!press || e.pointerId !== press.id) return
124
+ endPress()
125
+ if (longPressed) hide()
126
+ }
127
+ // The click a long press ends in, and the context menu it may open, belong to the tooltip
128
+ function onClickCapture(e: MouseEvent) {
129
+ if (!longPressed) return
130
+ longPressed = false
131
+ e.preventDefault()
132
+ e.stopPropagation()
133
+ }
134
+ function onContextMenu(e: Event) {
135
+ if (press || longPressed) e.preventDefault()
136
+ }
137
+
138
+ function onFocusIn(e: FocusEvent) {
139
+ let keyboard = true
140
+ try { keyboard = (e.target as Element).matches(':focus-visible') } catch { /* no :focus-visible: show */ }
141
+ if (keyboard) show()
142
+ }
143
+ function onKeyDown(e: KeyboardEvent) {
144
+ if (e.key === 'Escape' && o.visible()) {
145
+ // Hiding the tooltip uses the key: a dialog around it stays open
146
+ e.stopPropagation()
147
+ closeNow()
148
+ }
149
+ }
150
+ function onScroll() {
151
+ if (o.visible()) closeNow()
152
+ }
153
+
154
+ el.addEventListener('pointerenter', onPointerEnter)
155
+ el.addEventListener('pointerleave', onPointerLeave)
156
+ el.addEventListener('pointerdown', onPointerDown)
157
+ el.addEventListener('click', onClickCapture, true)
158
+ el.addEventListener('contextmenu', onContextMenu)
159
+ el.addEventListener('focusin', onFocusIn)
160
+ el.addEventListener('focusout', hide)
161
+ el.addEventListener('keydown', onKeyDown)
162
+ window.addEventListener('scroll', onScroll, true)
163
+
164
+ return {
165
+ /** Keeps it open (the pointer moved onto a rich tooltip) */
166
+ cancel,
167
+ /** Closes it at once */
168
+ closeNow,
169
+ destroy() {
170
+ cancel()
171
+ endPress()
172
+ document.removeEventListener('pointerdown', onOutsideTouch, true)
173
+ el.removeEventListener('pointerenter', onPointerEnter)
174
+ el.removeEventListener('pointerleave', onPointerLeave)
175
+ el.removeEventListener('pointerdown', onPointerDown)
176
+ el.removeEventListener('click', onClickCapture, true)
177
+ el.removeEventListener('contextmenu', onContextMenu)
178
+ el.removeEventListener('focusin', onFocusIn)
179
+ el.removeEventListener('focusout', hide)
180
+ el.removeEventListener('keydown', onKeyDown)
181
+ window.removeEventListener('scroll', onScroll, true)
182
+ },
183
+ }
184
+ }
@@ -11,6 +11,8 @@ const stack: (() => void)[] = []
11
11
 
12
12
  function onKeydown(e: KeyboardEvent) {
13
13
  if (e.key !== 'Escape' || !stack.length) return
14
+ // Handled: the browser then doesn't also run a close watcher with it (MContainerTransform's, under a dialog)
15
+ e.preventDefault()
14
16
  stack[stack.length - 1]!()
15
17
  }
16
18
 
@@ -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
+ }