@m3ui-vue/m3ui-vue 1.10.2 → 1.11.1

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 (301) hide show
  1. package/README.md +19 -4
  2. package/dist/API.md +204 -59
  3. package/dist/MButton-BHKF1Tfd.js +284 -0
  4. package/dist/MButton-BHKF1Tfd.js.map +1 -0
  5. package/dist/MColorPickerModal-CNesUJUq.js +466 -0
  6. package/dist/MColorPickerModal-CNesUJUq.js.map +1 -0
  7. package/dist/MDialog-jAYkZ4M8.js +226 -0
  8. package/dist/MDialog-jAYkZ4M8.js.map +1 -0
  9. package/dist/{MIcon-BSsJZhK7.js → MIcon-CkUc9kuQ.js} +10 -4
  10. package/dist/MIcon-CkUc9kuQ.js.map +1 -0
  11. package/dist/MIconButton-DTFOfsTy.js +317 -0
  12. package/dist/MIconButton-DTFOfsTy.js.map +1 -0
  13. package/dist/MListItem-CgdM5sco.js +1306 -0
  14. package/dist/MListItem-CgdM5sco.js.map +1 -0
  15. package/dist/MLoadingIndicator-00XbLQSf.js +115 -0
  16. package/dist/MLoadingIndicator-00XbLQSf.js.map +1 -0
  17. package/dist/{MMenuItem-US0Zbglq.js → MMenuItem-CEIKYvaX.js} +216 -214
  18. package/dist/MMenuItem-CEIKYvaX.js.map +1 -0
  19. package/dist/{MPdfViewer-DL9mRsd2.js → MPdfViewer-KjUIJOIs.js} +674 -671
  20. package/dist/MPdfViewer-KjUIJOIs.js.map +1 -0
  21. package/dist/MProgressBar-BzZMxq7M.js.map +1 -1
  22. package/dist/MSeekBar-B4EEWw3B.js +435 -0
  23. package/dist/MSeekBar-B4EEWw3B.js.map +1 -0
  24. package/dist/{MSegmentedButton-DMou-8sG.js → MSegmentedButton-UOAJAd2i.js} +4 -4
  25. package/dist/{MSegmentedButton-DMou-8sG.js.map → MSegmentedButton-UOAJAd2i.js.map} +1 -1
  26. package/dist/{MSignaturePad-WuvE_Cyl.js → MSignaturePad-HZavgiGB.js} +2 -2
  27. package/dist/{MSignaturePad-WuvE_Cyl.js.map → MSignaturePad-HZavgiGB.js.map} +1 -1
  28. package/dist/{MSlider-7TzhFHKS.js → MSlider-BaQeaozI.js} +4 -4
  29. package/dist/{MSlider-7TzhFHKS.js.map → MSlider-BaQeaozI.js.map} +1 -1
  30. package/dist/{MSpinner-CkIVBuGE.js → MSpinner-CbEMPY4X.js} +2 -2
  31. package/dist/{MSpinner-CkIVBuGE.js.map → MSpinner-CbEMPY4X.js.map} +1 -1
  32. package/dist/{MTextField-B6_iOczK.js → MTextField-B9PwKHlP.js} +136 -134
  33. package/dist/MTextField-B9PwKHlP.js.map +1 -0
  34. package/dist/{_useFieldValidation-COBJ1tWr.js → _useFieldValidation-B7AAfa69.js} +2 -2
  35. package/dist/{_useFieldValidation-COBJ1tWr.js.map → _useFieldValidation-B7AAfa69.js.map} +1 -1
  36. package/dist/api.json +1 -1
  37. package/dist/chart.js +1 -1
  38. package/dist/code-editor.js +3 -3
  39. package/dist/code-editor.js.map +1 -1
  40. package/dist/components/MAlert.vue.d.ts +1 -1
  41. package/dist/components/MAudioPlayer.vue.d.ts +3 -3
  42. package/dist/components/MAudioRecorder.vue.d.ts +2 -2
  43. package/dist/components/MAvatar.vue.d.ts +19 -1
  44. package/dist/components/MButton.vue.d.ts +2 -1
  45. package/dist/components/MChatBubble.vue.d.ts +2 -0
  46. package/dist/components/MCheckbox.vue.d.ts +2 -0
  47. package/dist/components/MDataTable.vue.d.ts +33 -5
  48. package/dist/components/MFlow.vue.d.ts +1 -1
  49. package/dist/components/MHotkeys.vue.d.ts +1 -0
  50. package/dist/components/MIcon.vue.d.ts +6 -0
  51. package/dist/components/MIconButton.vue.d.ts +5 -0
  52. package/dist/components/MJsonViewer.vue.d.ts +2 -0
  53. package/dist/components/MKanban.vue.d.ts +1 -1
  54. package/dist/components/MLink.vue.d.ts +59 -0
  55. package/dist/components/MListItem.vue.d.ts +3 -1
  56. package/dist/components/MMapControl.vue.d.ts +1 -1
  57. package/dist/components/MNotificationCenter.vue.d.ts +1 -1
  58. package/dist/components/MNumberField.vue.d.ts +1 -1
  59. package/dist/components/MPagination.vue.d.ts +14 -1
  60. package/dist/components/MPdfSigner.vue.d.ts +3 -3
  61. package/dist/components/MRadio.vue.d.ts +2 -0
  62. package/dist/components/MRadioGroup.vue.d.ts +2 -0
  63. package/dist/components/MStatCard.vue.d.ts +2 -2
  64. package/dist/components/MSwitch.vue.d.ts +2 -0
  65. package/dist/components/MTable.vue.d.ts +1 -1
  66. package/dist/components/MText.vue.d.ts +4 -2
  67. package/dist/components/MTextField.vue.d.ts +2 -0
  68. package/dist/components/MTicket.vue.d.ts +1 -1
  69. package/dist/components/_MDrawerItemList.vue.d.ts +6 -0
  70. package/dist/composables/_countLabel.d.ts +6 -0
  71. package/dist/composables/_menuGroups.d.ts +10 -1
  72. package/dist/composables/_splitAttrs.d.ts +6 -0
  73. package/dist/composables/_springAnimation.d.ts +2 -2
  74. package/dist/composables/_useFocusTrap.d.ts +15 -0
  75. package/dist/composables/_usePaneResize.d.ts +1 -1
  76. package/dist/composables/_useSpring.d.ts +4 -4
  77. package/dist/composables/dynamicColor.d.ts +9 -1
  78. package/dist/composables/motion.d.ts +63 -0
  79. package/dist/composables/useConfirm.d.ts +28 -0
  80. package/dist/composables/useDevice.d.ts +8 -1
  81. package/dist/composables/useLocale.d.ts +18 -0
  82. package/dist/composables/useScrollReveal.d.ts +1 -1
  83. package/dist/composables/useTheme.d.ts +1 -0
  84. package/dist/composables/useToast.d.ts +7 -0
  85. package/dist/draw.js +556 -556
  86. package/dist/draw.js.map +1 -1
  87. package/dist/flow.js +854 -851
  88. package/dist/flow.js.map +1 -1
  89. package/dist/gantt.js +1118 -1096
  90. package/dist/gantt.js.map +1 -1
  91. package/dist/index.d.ts +8 -5
  92. package/dist/locales/index.d.ts +1 -0
  93. package/dist/locales/index.js +865 -33
  94. package/dist/locales/index.js.map +1 -1
  95. package/dist/locales/pl.d.ts +2 -0
  96. package/dist/m3ui-vue.css +1 -1
  97. package/dist/m3ui.js +10335 -9798
  98. package/dist/m3ui.js.map +1 -1
  99. package/dist/map.js +860 -860
  100. package/dist/map.js.map +1 -1
  101. package/dist/{material-color-utilities-CEFytLsr.js → material-color-utilities-BZsBNIhi.js} +276 -217
  102. package/dist/material-color-utilities-BZsBNIhi.js.map +1 -0
  103. package/dist/media.js +7 -7
  104. package/dist/{motion-BcejVTeX.js → motion-BqYcqcim.js} +15 -5
  105. package/dist/motion-BqYcqcim.js.map +1 -0
  106. package/dist/pdf-sign.js +140 -137
  107. package/dist/pdf-sign.js.map +1 -1
  108. package/dist/pdf.js +1 -1
  109. package/dist/plugin.d.ts +11 -0
  110. package/dist/rich-text-editor.js +7 -7
  111. package/dist/styles/theme.css +40 -0
  112. package/dist/styles.css +1 -1
  113. package/dist/terminal.js +1 -1
  114. package/dist/{useLocale-YRaOT12S.js → useLocale-BAPJ34Pq.js} +64 -8
  115. package/dist/useLocale-BAPJ34Pq.js.map +1 -0
  116. package/dist/{useThemeTokens-DyAdPQB0.js → useThemeTokens-D5nr5KHf.js} +28 -27
  117. package/dist/useThemeTokens-D5nr5KHf.js.map +1 -0
  118. package/package.json +17 -2
  119. package/src/__tests__/MAvatarImage.test.ts +37 -0
  120. package/src/__tests__/MDataTableControlled.test.ts +68 -0
  121. package/src/__tests__/MHotkeysSequence.test.ts +53 -0
  122. package/src/__tests__/MIconAxes.test.ts +16 -0
  123. package/src/__tests__/MIconButtonWidth.test.ts +22 -0
  124. package/src/__tests__/MLink.test.ts +46 -0
  125. package/src/__tests__/MPaginationPages.test.ts +43 -0
  126. package/src/__tests__/MTextEmphasized.test.ts +14 -0
  127. package/src/__tests__/controlDescription.test.ts +34 -0
  128. package/src/__tests__/countLabels.test.ts +66 -0
  129. package/src/__tests__/customColor.test.ts +27 -0
  130. package/src/__tests__/dynamicColor.test.ts +3 -2
  131. package/src/__tests__/focusTrap.test.ts +124 -0
  132. package/src/__tests__/formatMessage.test.ts +20 -0
  133. package/src/__tests__/inputAttrs.test.ts +103 -0
  134. package/src/__tests__/localePresets.test.ts +2 -0
  135. package/src/__tests__/menuGroupsRemount.test.ts +40 -0
  136. package/src/__tests__/menuHydration.test.ts +41 -0
  137. package/src/__tests__/motionPrefs.test.ts +28 -0
  138. package/src/__tests__/ssr.test.ts +11 -0
  139. package/src/__tests__/ssrToast.test.ts +20 -0
  140. package/src/__tests__/toastDetails.test.ts +39 -0
  141. package/src/__tests__/useConfirm.test.ts +47 -0
  142. package/src/__tests__/useTheme.test.ts +14 -0
  143. package/src/__tests__/warningRole.test.ts +22 -0
  144. package/src/components/MAlert.vue +2 -2
  145. package/src/components/MAnimatedNumber.vue +9 -3
  146. package/src/components/MAutocomplete.vue +16 -4
  147. package/src/components/MAvailabilityCalendar.vue +3 -3
  148. package/src/components/MAvatar.vue +32 -5
  149. package/src/components/MAvatarGroup.vue +7 -2
  150. package/src/components/MBottomSheet.vue +18 -2
  151. package/src/components/MButton.vue +18 -5
  152. package/src/components/MCarousel.vue +3 -3
  153. package/src/components/MChatBubble.vue +14 -1
  154. package/src/components/MCheckbox.vue +21 -4
  155. package/src/components/MChip.vue +4 -2
  156. package/src/components/MCollapse.vue +7 -1
  157. package/src/components/MCommandPalette.vue +6 -2
  158. package/src/components/MContextMenu.vue +4 -4
  159. package/src/components/MCreditCardInput.vue +5 -0
  160. package/src/components/MDashboardGrid.vue +2 -1
  161. package/src/components/MDataTable.vue +68 -20
  162. package/src/components/MDialog.vue +21 -3
  163. package/src/components/MDiffViewer.vue +3 -3
  164. package/src/components/MDrawLayers.vue +3 -3
  165. package/src/components/MFabMenu.vue +7 -0
  166. package/src/components/MFloorPlan.vue +3 -3
  167. package/src/components/MFloorPlanInspector.vue +3 -3
  168. package/src/components/MFlow.vue +9 -5
  169. package/src/components/MFlowControls.vue +6 -0
  170. package/src/components/MFormBuilder.vue +1 -1
  171. package/src/components/MGantt.vue +10 -10
  172. package/src/components/MHotkeys.vue +61 -16
  173. package/src/components/MIcon.vue +17 -1
  174. package/src/components/MIconButton.vue +29 -6
  175. package/src/components/MImageCropper.vue +1 -1
  176. package/src/components/MJsonViewer.vue +4 -1
  177. package/src/components/MKanban.vue +2 -1
  178. package/src/components/MLightbox.vue +5 -4
  179. package/src/components/MLink.vue +136 -0
  180. package/src/components/MListDetail.vue +7 -0
  181. package/src/components/MListItem.vue +7 -4
  182. package/src/components/MLoadingIndicator.vue +2 -1
  183. package/src/components/MMap.vue +3 -0
  184. package/src/components/MMapCluster.vue +2 -2
  185. package/src/components/MMapControl.vue +2 -2
  186. package/src/components/MMapMeasure.vue +1 -1
  187. package/src/components/MMaskField.vue +16 -3
  188. package/src/components/MMenu.vue +4 -4
  189. package/src/components/MMenuItem.vue +2 -2
  190. package/src/components/MMeterGroup.vue +3 -2
  191. package/src/components/MMortgageCalculator.vue +3 -3
  192. package/src/components/MMultiAutocomplete.vue +19 -7
  193. package/src/components/MMultiSelect.vue +19 -7
  194. package/src/components/MNavigationDrawer.vue +10 -3
  195. package/src/components/MNavigationRail.vue +5 -1
  196. package/src/components/MNotificationCenter.vue +2 -1
  197. package/src/components/MNotificationHost.vue +3 -3
  198. package/src/components/MNumberField.vue +23 -6
  199. package/src/components/MOdontogram.vue +4 -4
  200. package/src/components/MOrderBook.vue +4 -0
  201. package/src/components/MPagination.vue +91 -12
  202. package/src/components/MPdfSigner.vue +3 -3
  203. package/src/components/MPdfViewer.vue +7 -7
  204. package/src/components/MPhoneInput.vue +17 -4
  205. package/src/components/MProductConfigurator.vue +4 -4
  206. package/src/components/MProgressBar.vue +5 -0
  207. package/src/components/MQuiz.vue +8 -5
  208. package/src/components/MRadio.vue +24 -5
  209. package/src/components/MRadioGroup.vue +3 -0
  210. package/src/components/MReactions.vue +2 -2
  211. package/src/components/MResourceTimeline.vue +3 -3
  212. package/src/components/MResult.vue +1 -1
  213. package/src/components/MScrollField.vue +1 -1
  214. package/src/components/MSearchField.vue +6 -5
  215. package/src/components/MSeatMap.vue +5 -0
  216. package/src/components/MSeekBar.vue +3 -2
  217. package/src/components/MSelect.vue +16 -4
  218. package/src/components/MSideSheet.vue +25 -3
  219. package/src/components/MSimpleCarousel.vue +2 -2
  220. package/src/components/MSnackbar.vue +16 -13
  221. package/src/components/MSparkline.vue +2 -1
  222. package/src/components/MSpinner.vue +8 -0
  223. package/src/components/MSplitter.vue +1 -1
  224. package/src/components/MSpotlightSearch.vue +6 -2
  225. package/src/components/MSpreadsheet.vue +1 -1
  226. package/src/components/MStatCard.vue +2 -1
  227. package/src/components/MSwitch.vue +21 -4
  228. package/src/components/MTable.vue +3 -2
  229. package/src/components/MTabs.vue +2 -1
  230. package/src/components/MTagInput.vue +19 -6
  231. package/src/components/MText.vue +23 -4
  232. package/src/components/MTextField.vue +25 -6
  233. package/src/components/MTimeline.vue +5 -5
  234. package/src/components/MToolbar.vue +2 -2
  235. package/src/components/MTour.vue +3 -0
  236. package/src/components/MTrackingTimeline.vue +6 -0
  237. package/src/components/MTypewriter.vue +7 -1
  238. package/src/components/MWindow.vue +10 -1
  239. package/src/components/_MColorPanel.vue +4 -4
  240. package/src/components/_MComment.vue +3 -2
  241. package/src/components/_MFlowNodeShell.vue +1 -1
  242. package/src/components/_MPdfPage.vue +1 -1
  243. package/src/components/_MTransferPane.vue +10 -0
  244. package/src/composables/_countLabel.ts +10 -0
  245. package/src/composables/_effectCanvas.ts +2 -1
  246. package/src/composables/_menuGroups.ts +10 -1
  247. package/src/composables/_splitAttrs.ts +29 -0
  248. package/src/composables/_springAnimation.ts +3 -3
  249. package/src/composables/_themeTransition.ts +3 -2
  250. package/src/composables/_useFocusTrap.ts +142 -0
  251. package/src/composables/_useMenuNav.ts +3 -3
  252. package/src/composables/_usePaneResize.ts +2 -1
  253. package/src/composables/_useSheetMotion.ts +3 -4
  254. package/src/composables/_useSpring.ts +16 -10
  255. package/src/composables/cron.ts +7 -6
  256. package/src/composables/dynamicColor.ts +21 -2
  257. package/src/composables/motion.ts +27 -0
  258. package/src/composables/useConfirm.ts +116 -0
  259. package/src/composables/useDevice.ts +23 -3
  260. package/src/composables/useFieldBg.ts +4 -0
  261. package/src/composables/useLocale.ts +82 -4
  262. package/src/composables/useNotification.ts +3 -0
  263. package/src/composables/useScrollReveal.ts +3 -3
  264. package/src/composables/useTheme.ts +8 -2
  265. package/src/composables/useToast.ts +27 -4
  266. package/src/directives/vSparkle.ts +2 -1
  267. package/src/index.ts +8 -5
  268. package/src/locales/ar.ts +11 -4
  269. package/src/locales/de.ts +11 -4
  270. package/src/locales/es.ts +11 -4
  271. package/src/locales/fr.ts +11 -4
  272. package/src/locales/index.ts +1 -0
  273. package/src/locales/ja.ts +11 -4
  274. package/src/locales/ko.ts +11 -4
  275. package/src/locales/pl.ts +807 -0
  276. package/src/locales/pt.ts +11 -4
  277. package/src/locales/zh.ts +11 -4
  278. package/src/plugin.ts +16 -0
  279. package/src/styles/theme.css +40 -0
  280. package/dist/MButton-B9RCM06i.js +0 -171
  281. package/dist/MButton-B9RCM06i.js.map +0 -1
  282. package/dist/MColorPickerModal-ChRtcZOo.js +0 -577
  283. package/dist/MColorPickerModal-ChRtcZOo.js.map +0 -1
  284. package/dist/MDialog-dk07tify.js +0 -167
  285. package/dist/MDialog-dk07tify.js.map +0 -1
  286. package/dist/MIcon-BSsJZhK7.js.map +0 -1
  287. package/dist/MIconButton-CrBPZidd.js +0 -288
  288. package/dist/MIconButton-CrBPZidd.js.map +0 -1
  289. package/dist/MListItem-h9H223vx.js +0 -1239
  290. package/dist/MListItem-h9H223vx.js.map +0 -1
  291. package/dist/MLoadingIndicator-YTV1Ov5w.js +0 -114
  292. package/dist/MLoadingIndicator-YTV1Ov5w.js.map +0 -1
  293. package/dist/MMenuItem-US0Zbglq.js.map +0 -1
  294. package/dist/MPdfViewer-DL9mRsd2.js.map +0 -1
  295. package/dist/MSeekBar-JFZcoJ8y.js +0 -434
  296. package/dist/MSeekBar-JFZcoJ8y.js.map +0 -1
  297. package/dist/MTextField-B6_iOczK.js.map +0 -1
  298. package/dist/material-color-utilities-CEFytLsr.js.map +0 -1
  299. package/dist/motion-BcejVTeX.js.map +0 -1
  300. package/dist/useLocale-YRaOT12S.js.map +0 -1
  301. package/dist/useThemeTokens-DyAdPQB0.js.map +0 -1
@@ -2,6 +2,10 @@
2
2
  /**
3
3
  * The standard single- or multi-line text input, filled or outlined, with floating label.
4
4
  *
5
+ * Your `class`, `style` and `data-*` go on the field's box; every other attribute (`id`, `inputmode`, `enterkeyhint`,
6
+ * `maxlength`, `pattern`, `readonly`, `aria-*`, native listeners like `@keydown`) goes on the `<input>` (or
7
+ * `<textarea>`).
8
+ *
5
9
  * @slot trailing Custom trailing content (e.g. an icon button) — replaces the built-in clear button when
6
10
  * present
7
11
  * @event update:modelValue Emitted on every keystroke — powers v-model
@@ -17,8 +21,11 @@ import { useDebounce } from "../composables/useDebounce";
17
21
  import { useLocale } from '../composables/useLocale'
18
22
  import { useFieldValidation } from '../composables/_useFieldValidation'
19
23
  import type { ValidateOn, ValidationRule } from '../composables/validation'
24
+ import { useSplitAttrs } from '../composables/_splitAttrs'
20
25
  import { FIELD_PADDING_END, fieldLabelClasses, vOverflowTitle, type FieldEndInset } from '../composables/_fieldLayout'
21
26
 
27
+ defineOptions({ inheritAttrs: false })
28
+
22
29
  const locale = useLocale()
23
30
  const props = withDefaults(
24
31
  defineProps<{
@@ -26,6 +33,8 @@ const props = withDefaults(
26
33
  modelValue: string | number;
27
34
  /** Field label */
28
35
  label: string;
36
+ /** Placeholder, shown while the field is focused and empty (the label sits above it then, as in M3) */
37
+ placeholder?: string;
29
38
  /** HTML input type */
30
39
  type?: string;
31
40
  /** Visual style */
@@ -86,7 +95,9 @@ const props = withDefaults(
86
95
 
87
96
  const emit = defineEmits<{ "update:modelValue": [string]; debounced: [string]; blur: [FocusEvent]; focus: [FocusEvent] }>();
88
97
 
89
- const id = useId();
98
+ const { rootAttrs, inputAttrs, attrId } = useSplitAttrs();
99
+ const autoId = useId();
100
+ const id = computed(() => attrId() ?? autoId);
90
101
  const slots = useSlots();
91
102
 
92
103
  const fieldBgEl = ref<HTMLElement | null>(null);
@@ -136,6 +147,7 @@ const inputClasses = computed(() => {
136
147
  const size = props.multiline ? (props.autoGrow ? "resize-none min-h-[56px]" : "resize-y min-h-[56px]") : "h-14";
137
148
  const base = [
138
149
  "peer block w-full text-body-large text-on-surface outline-none placeholder:text-transparent",
150
+ props.placeholder ? "focus:placeholder:text-on-surface-variant" : "",
139
151
  "transition-[border-color,border-width] duration-150",
140
152
  "disabled:cursor-not-allowed disabled:text-on-surface/38",
141
153
  hasError.value ? "caret-error" : "caret-primary",
@@ -182,6 +194,11 @@ const labelClasses = computed(() =>
182
194
  }),
183
195
  );
184
196
 
197
+ // Ours (the message below the field) plus any the consumer passed
198
+ function describedBy() {
199
+ return [errorMessage.value || props.hint ? messageId : '', inputAttrs()['aria-describedby']].filter(Boolean).join(' ') || undefined;
200
+ }
201
+
185
202
  function onInput(event: Event) {
186
203
  const target = event.target as HTMLInputElement | HTMLTextAreaElement;
187
204
  emit("update:modelValue", target.value);
@@ -207,7 +224,7 @@ defineExpose({
207
224
  </script>
208
225
 
209
226
  <template>
210
- <div class="flex flex-col gap-1">
227
+ <div class="flex flex-col gap-1" v-bind="rootAttrs()">
211
228
  <!--
212
229
  --field-bg: background behind the floating label in outlined mode, so it
213
230
  "cuts through" the border. Auto-detected from the nearest opaque ancestor
@@ -233,6 +250,7 @@ defineExpose({
233
250
  <textarea
234
251
  v-if="multiline"
235
252
  ref="textareaEl"
253
+ v-bind="inputAttrs()"
236
254
  :id="id"
237
255
  :value="String(modelValue)"
238
256
  :rows="rows"
@@ -240,8 +258,8 @@ defineExpose({
240
258
  :disabled="isDisabled"
241
259
  :required="required"
242
260
  :aria-invalid="hasError || undefined"
243
- :aria-describedby="errorMessage || hint ? messageId : undefined"
244
- placeholder=" "
261
+ :aria-describedby="describedBy()"
262
+ :placeholder="placeholder || ' '"
245
263
  :class="inputClasses"
246
264
  @input="onInput"
247
265
  @blur="onBlur"
@@ -250,6 +268,7 @@ defineExpose({
250
268
  <input
251
269
  v-else
252
270
  ref="inputOnlyEl"
271
+ v-bind="inputAttrs()"
253
272
  :id="id"
254
273
  :type="type"
255
274
  :value="modelValue"
@@ -257,9 +276,9 @@ defineExpose({
257
276
  :disabled="isDisabled"
258
277
  :required="required"
259
278
  :aria-invalid="hasError || undefined"
260
- :aria-describedby="errorMessage || hint ? messageId : undefined"
279
+ :aria-describedby="describedBy()"
261
280
  :autocomplete="autocomplete"
262
- placeholder=" "
281
+ :placeholder="placeholder || ' '"
263
282
  :class="inputClasses"
264
283
  v-overflow-title
265
284
  @input="onInput"
@@ -42,8 +42,8 @@ export type TimelineStatus = NonNullable<TimelineItem["status"]>;
42
42
  import { computed, onBeforeUpdate, onMounted, onUpdated, ref, useSlots } from "vue";
43
43
  import MIcon from "./MIcon.vue";
44
44
  import MButton from "./MButton.vue";
45
- import { useLocale } from "../composables/useLocale";
46
- import { motionSprings } from "../composables/motion";
45
+ import { useLocale, formatMessage } from "../composables/useLocale";
46
+ import { appSprings } from "../composables/motion";
47
47
  import { playSamples, prefersReducedMotion, sampleSpring } from "../composables/_springAnimation";
48
48
 
49
49
  const props = withDefaults(
@@ -123,7 +123,7 @@ const limited = computed(() => props.limit !== undefined && props.items.length >
123
123
  const shown = computed(() => (limited.value && !isExpanded.value ? props.items.slice(0, props.limit) : props.items));
124
124
  const hiddenCount = computed(() => props.items.length - shown.value.length);
125
125
  const toggleLabel = computed(() =>
126
- isExpanded.value ? t.timelineShowLess : t.timelineShowMore.replace("{count}", String(hiddenCount.value)),
126
+ isExpanded.value ? t.timelineShowLess : formatMessage(t.timelineShowMore, { count: String(hiddenCount.value) }, t.lang),
127
127
  );
128
128
  function toggleExpanded() {
129
129
  const next = !isExpanded.value;
@@ -205,7 +205,7 @@ onUpdated(() => {
205
205
  const now = row.getBoundingClientRect();
206
206
  if (!was) {
207
207
  // New: in from a short way back along the timeline, fading in
208
- playSamples(row, sampleSpring(0, 1, 0, motionSprings.standard.defaultSpatial, 0.001), (p) => ({
208
+ playSamples(row, sampleSpring(0, 1, 0, appSprings().defaultSpatial, 0.001), (p) => ({
209
209
  transform: `translate${along}(${(1 - p) * -12}px)`,
210
210
  opacity: String(Math.min(1, p * 1.4)),
211
211
  }));
@@ -214,7 +214,7 @@ onUpdated(() => {
214
214
  const dx = was.left - now.left;
215
215
  const dy = was.top - now.top;
216
216
  if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) continue;
217
- playSamples(row, sampleSpring(1, 0, 0, motionSprings.standard.defaultSpatial, 0.001), (p) => ({
217
+ playSamples(row, sampleSpring(1, 0, 0, appSprings().defaultSpatial, 0.001), (p) => ({
218
218
  transform: `translate(${dx * p}px, ${dy * p}px)`,
219
219
  }));
220
220
  }
@@ -13,7 +13,7 @@
13
13
  * @event update:expanded The toolbar collapsed or expanded on scroll (`collapseOnScroll`)
14
14
  */
15
15
  import { computed, onMounted, onUnmounted, onUpdated, ref, useSlots, watch } from 'vue'
16
- import { motionSprings } from '../composables/motion'
16
+ import { motionSprings, shouldReduceMotion } from '../composables/motion'
17
17
  import MToolbarFab from './_MToolbarFab.vue'
18
18
 
19
19
  const props = withDefaults(defineProps<{
@@ -100,7 +100,7 @@ let last = 0
100
100
  let full = 0
101
101
  let lead = 0
102
102
  let trail = 0
103
- const reduceMotion = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches
103
+ const reduceMotion = () => shouldReduceMotion()
104
104
  const size = () => (isVertical.value ? 'height' : 'width')
105
105
  const measure = (el?: HTMLElement) => (el ? (isVertical.value ? el.offsetHeight : el.offsetWidth) : 0)
106
106
 
@@ -391,6 +391,9 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
391
391
  @media (prefers-reduced-motion: reduce) {
392
392
  .m3-tour-ring { animation: none; }
393
393
  }
394
+ /* createM3UI({ reducedMotion: 'always' }) */
395
+ :root[data-m3-motion='reduce'] .m3-tour-ring { animation: none; }
396
+
394
397
 
395
398
  .m3-tour-enter-active,
396
399
  .m3-tour-leave-active {
@@ -255,4 +255,10 @@ const statusChip = computed(() =>
255
255
  display: none;
256
256
  }
257
257
  }
258
+ /* createM3UI({ reducedMotion: 'always' }) */
259
+ :root[data-m3-motion='reduce'] .m3-tracking-pulse {
260
+ animation: none;
261
+ display: none;
262
+ }
263
+
258
264
  </style>
@@ -11,6 +11,7 @@
11
11
  * @event done Emitted when the last phrase is typed and `loop` is off
12
12
  */
13
13
  import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
14
+ import { shouldReduceMotion } from '../composables/motion'
14
15
 
15
16
  const props = withDefaults(
16
17
  defineProps<{
@@ -61,7 +62,7 @@ const split = (s: string) => (segmenter ? Array.from(segmenter.segment(s), (g) =
61
62
 
62
63
  const shown = ref<string[]>([])
63
64
  const index = ref(0)
64
- const reduced = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
65
+ const reduced = shouldReduceMotion()
65
66
 
66
67
  let timer: ReturnType<typeof setTimeout> | undefined
67
68
  let running = false
@@ -192,4 +193,9 @@ const typed = computed(() => shown.value.join(''))
192
193
  animation: none;
193
194
  }
194
195
  }
196
+ /* createM3UI({ reducedMotion: 'always' }) */
197
+ :root[data-m3-motion='reduce'] .m3-typewriter-cursor {
198
+ animation: none;
199
+ }
200
+
195
201
  </style>
@@ -3,6 +3,7 @@
3
3
  // Kept below the app-level overlay scale (dialogs/spotlight/command palette use z-50)
4
4
  // so windows never render on top of a real modal.
5
5
  import { ref as moduleRef } from 'vue'
6
+ import { shouldReduceMotion } from '../composables/motion'
6
7
 
7
8
  let sharedZIndex = 10
8
9
  let nextId = 0
@@ -246,7 +247,7 @@ function restoreUnderPointer() {
246
247
  maximized.value = false
247
248
  tiled.value = null
248
249
  restoreOnMove = false
249
- const reduced = typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
250
+ const reduced = shouldReduceMotion()
250
251
  if (reduced) {
251
252
  winWidth.value = restoreBox.w
252
253
  winHeight.value = restoreBox.h
@@ -765,4 +766,12 @@ const resizeHandles: { dir: ResizeDirection; class: string; cursor: string }[] =
765
766
  transition: none;
766
767
  }
767
768
  }
769
+ /* createM3UI({ reducedMotion: 'always' }) */
770
+ :root[data-m3-motion='reduce'] .m3-window-geometry,
771
+ :root[data-m3-motion='reduce'] .m3-window-snap-preview,
772
+ :root[data-m3-motion='reduce'] .m3-window-enter-active,
773
+ :root[data-m3-motion='reduce'] .m3-window-leave-active {
774
+ transition: none;
775
+ }
776
+
768
777
  </style>
@@ -249,7 +249,7 @@ defineExpose({ focus: () => areaEl.value?.focus({ preventScroll: true }) })
249
249
  aria-valuemin="0"
250
250
  aria-valuemax="100"
251
251
  :aria-valuetext="`${t.colorSaturation} ${Math.round(s)}%, ${t.colorBrightness} ${Math.round(v)}%`"
252
- class="relative h-40 w-full shrink-0 cursor-crosshair touch-none rounded-md outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
252
+ class="relative h-40 w-full shrink-0 cursor-crosshair touch-none rounded-md outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-secondary"
253
253
  :style="{ background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hueColor})` }"
254
254
  @pointerdown="onPointerDown('area', $event)"
255
255
  @pointermove="onPointerMove('area', $event)"
@@ -320,7 +320,7 @@ defineExpose({ focus: () => areaEl.value?.focus({ preventScroll: true }) })
320
320
  <button
321
321
  v-if="showOriginal"
322
322
  type="button"
323
- class="m3-cp-swatch flex w-12 shrink-0 cursor-pointer items-center justify-center rounded-s-full outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
323
+ class="m3-cp-swatch flex w-12 shrink-0 cursor-pointer items-center justify-center rounded-s-full outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-secondary"
324
324
  :style="{ background: fill(original!) }"
325
325
  :aria-label="t.colorOriginal"
326
326
  v-tooltip="t.colorOriginal"
@@ -341,7 +341,7 @@ defineExpose({ focus: () => areaEl.value?.focus({ preventScroll: true }) })
341
341
  <div class="flex items-start gap-2">
342
342
  <button
343
343
  type="button"
344
- class="flex h-10 shrink-0 cursor-pointer items-center gap-0.5 rounded-full bg-secondary-container pe-2 ps-3 text-label-large text-on-secondary-container outline-none transition-[background-color] duration-150 hover:bg-[color-mix(in_srgb,var(--color-secondary-container),var(--color-on-secondary-container)_8%)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
344
+ class="flex h-10 shrink-0 cursor-pointer items-center gap-0.5 rounded-full bg-secondary-container pe-2 ps-3 text-label-large text-on-secondary-container outline-none transition-[background-color] duration-150 hover:bg-[color-mix(in_srgb,var(--color-secondary-container),var(--color-on-secondary-container)_8%)] focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-secondary"
345
345
  :aria-label="`${t.colorFormat}: ${formatLabel}`"
346
346
  @click="cycleFormat"
347
347
  >
@@ -387,7 +387,7 @@ defineExpose({ focus: () => areaEl.value?.focus({ preventScroll: true }) })
387
387
  v-for="color in group.colors"
388
388
  :key="color"
389
389
  type="button"
390
- class="m3-cp-swatch m3-cp-morph flex aspect-square cursor-pointer items-center justify-center outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary"
390
+ class="m3-cp-swatch m3-cp-morph flex aspect-square cursor-pointer items-center justify-center outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-secondary"
391
391
  :class="{ 'm3-cp-morph-selected': isSelected(color) }"
392
392
  :style="{ background: fill(color) }"
393
393
  :aria-label="color"
@@ -8,6 +8,7 @@ import MReactions from './MReactions.vue'
8
8
  import CommentComposer from './_MCommentComposer.vue'
9
9
  import { COMMENT_THREAD_KEY, type CommentItem } from './_commentThread'
10
10
  import { vRipple } from '../directives/vRipple'
11
+ import { formatMessage } from '../composables/useLocale'
11
12
 
12
13
  defineOptions({ name: 'MComment' })
13
14
 
@@ -38,7 +39,7 @@ const initials = computed(() => {
38
39
  // @mentions in the text stand out
39
40
  const pieces = computed(() => props.comment.text.split(/(@[\p{L}\p{N}_.-]+)/u).map((text) => ({ text, mention: text.startsWith('@') })))
40
41
  const showRepliesLabel = computed(() =>
41
- replies.value.length === 1 ? t.commentShowReply : t.commentShowReplies.replace('{count}', String(replies.value.length)),
42
+ replies.value.length === 1 ? t.commentShowReply : formatMessage(t.commentShowReplies, { count: String(replies.value.length) }, t.lang),
42
43
  )
43
44
 
44
45
  function startReply() {
@@ -113,7 +114,7 @@ function startReply() {
113
114
  <CommentComposer
114
115
  v-if="replying"
115
116
  class="mt-2"
116
- :label="t.commentReplyTo.replace('{name}', comment.author.name)"
117
+ :label="formatMessage(t.commentReplyTo, { name: comment.author.name }, t.lang)"
117
118
  :submit-label="t.commentSend"
118
119
  :mention-sources="ctx.mentionSources.value"
119
120
  cancelable
@@ -64,7 +64,7 @@ onBeforeUnmount(() => flow.registerNodeEl(id, null))
64
64
  <template>
65
65
  <div
66
66
  ref="el"
67
- class="m3-flow-node absolute top-0 left-0 rounded-md outline-none focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-secondary"
67
+ class="m3-flow-node absolute top-0 left-0 rounded-md outline-none focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-secondary"
68
68
  :class="[node.class, draggable && (dragging ? 'cursor-grabbing' : 'cursor-grab')]"
69
69
  :style="{
70
70
  transform: `translate(${pos.x}px, ${pos.y}px)`,
@@ -443,7 +443,7 @@ defineExpose({ root, currentHit })
443
443
  <button
444
444
  v-if="'x' in s"
445
445
  type="button"
446
- class="m3-pdf-note absolute flex size-7 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full shadow-elevation-2 outline-none focus-visible:ring-2 focus-visible:ring-primary"
446
+ class="m3-pdf-note absolute flex size-7 -translate-x-1/2 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full shadow-elevation-2 outline-none focus-visible:ring-2 focus-visible:ring-secondary"
447
447
  :class="{ 'ring-2 ring-primary': s.a.id === selectedId }"
448
448
  :style="{ left: `${s.x}px`, top: `${s.y}px`, backgroundColor: s.a.color }"
449
449
  :aria-label="s.a.text || 'Note'"
@@ -258,4 +258,14 @@ function onRowSpace(e: KeyboardEvent, value: Value) {
258
258
  transition: none;
259
259
  }
260
260
  }
261
+ /* createM3UI({ reducedMotion: 'always' }) */
262
+ :root[data-m3-motion='reduce'] .m3-tl-start-move,
263
+ :root[data-m3-motion='reduce'] .m3-tl-end-move,
264
+ :root[data-m3-motion='reduce'] .m3-tl-start-enter-active,
265
+ :root[data-m3-motion='reduce'] .m3-tl-end-enter-active,
266
+ :root[data-m3-motion='reduce'] .m3-tl-start-leave-active,
267
+ :root[data-m3-motion='reduce'] .m3-tl-end-leave-active {
268
+ transition: none;
269
+ }
270
+
261
271
  </style>
@@ -0,0 +1,10 @@
1
+ import { formatMessage } from './useLocale'
2
+
3
+ /**
4
+ * A count with its noun, e.g. "3 records". `template` is a locale string with `{count}` (and maybe a plural block,
5
+ * see `formatMessage`); a bare word without placeholders, as older locale overrides and props gave, is shown after
6
+ * the number untouched (no English "s" bolted on).
7
+ */
8
+ export function countLabel(template: string, count: number, lang?: string): string {
9
+ return template.includes('{') ? formatMessage(template, { count }, lang) : `${count} ${template}`
10
+ }
@@ -1,3 +1,4 @@
1
+ import { shouldReduceMotion } from './motion'
1
2
  // One canvas over the page shared by the canvas effects (useConfetti, useFireworks): created when the first one
2
3
  // starts, removed when the last one ends. It never takes pointer events and assistive technology ignores it. Each
3
4
  // effect is a layer stepped once per frame in one rAF loop, after the canvas has been cleared.
@@ -86,7 +87,7 @@ export function themeColors(el: Element, roles: string[]) {
86
87
 
87
88
  /** Whether the system asks for reduced motion. */
88
89
  export function reducedMotion() {
89
- return !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
90
+ return shouldReduceMotion()
90
91
  }
91
92
 
92
93
  /** Where an effect starts: the pointer of an event, an element's center, or a point in viewport pixels */
@@ -1,4 +1,4 @@
1
- import { Fragment, type VNode } from 'vue'
1
+ import { Fragment, type FunctionalComponent, type VNode, type VNodeChild } from 'vue'
2
2
  import MMenuDivider from '../components/MMenuDivider.vue'
3
3
 
4
4
  function flattenVNodes(vnodes: VNode[]): VNode[] {
@@ -29,3 +29,12 @@ export function splitMenuGroups(vnodes: VNode[]): VNode[][] {
29
29
  }
30
30
  return result.filter((g) => g.length > 0)
31
31
  }
32
+
33
+ /**
34
+ * Renders VNodes built elsewhere (a menu group, a push submenu's header or content). A stable component type: an
35
+ * inline `<component :is="() => nodes" />` is a new function on every render, so Vue treats it as a different
36
+ * component each time and unmounts and re-creates everything inside it (items lost focus and DOM identity on any
37
+ * re-render of the menu).
38
+ */
39
+ export const RenderNodes: FunctionalComponent<{ nodes?: () => VNodeChild }> = (props) => (props.nodes?.() ?? null) as VNode | null
40
+ RenderNodes.props = ['nodes']
@@ -0,0 +1,29 @@
1
+ import { useAttrs } from 'vue'
2
+
3
+ /**
4
+ * Splits a field's fallthrough attrs between its wrapper and its native control: `class`, `style` and `data-*` stay
5
+ * on the field's box (so `[data-testid] input` style selectors keep working), everything else (`id`, `inputmode`,
6
+ * `maxlength`, `aria-*`, native listeners…) belongs on the `<input>`. Use with `defineOptions({ inheritAttrs: false })`.
7
+ *
8
+ * Returns functions, not computeds: `$attrs` isn't reactive (in production a computed over it never updates), but a
9
+ * component re-renders whenever its attrs change, so calling these from the template always reads the current ones.
10
+ */
11
+ const isRootAttr = (k: string) => k === 'class' || k === 'style' || k.startsWith('data-')
12
+
13
+ export function useSplitAttrs() {
14
+ const attrs = useAttrs()
15
+ return {
16
+ rootAttrs: () => {
17
+ const root: Record<string, unknown> = {}
18
+ for (const k in attrs) if (isRootAttr(k)) root[k] = attrs[k]
19
+ return root
20
+ },
21
+ inputAttrs: () => {
22
+ const rest: Record<string, unknown> = {}
23
+ for (const k in attrs) if (!isRootAttr(k)) rest[k] = attrs[k]
24
+ return rest
25
+ },
26
+ /** The consumer's `id`, if given: the control takes it, so `<label for>` and `getElementById` keep working */
27
+ attrId: () => attrs.id as string | undefined,
28
+ }
29
+ }
@@ -1,4 +1,4 @@
1
- import type { SpringSpec } from './motion'
1
+ import { shouldReduceMotion, type SpringSpec } from './motion'
2
2
 
3
3
  /*
4
4
  * Internal (not exported from index.ts): springs played as Web Animations.
@@ -70,5 +70,5 @@ export function playSamples(
70
70
  return anim
71
71
  }
72
72
 
73
- export const prefersReducedMotion = () =>
74
- typeof window !== 'undefined' && !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
73
+ // The user's setting or createM3UI({ reducedMotion: 'always' })
74
+ export const prefersReducedMotion = shouldReduceMotion
@@ -1,3 +1,4 @@
1
+ import { shouldReduceMotion } from './motion'
1
2
  // Internal: animates a theme change (dark mode, palette, contrast).
2
3
  //
3
4
  // Firefox (and any browser without @property) transitions six color properties on every element
@@ -14,7 +15,7 @@ const COLOR_TOKENS = [
14
15
  'on-surface-variant', 'surface-container-lowest', 'surface-container-low', 'surface-container',
15
16
  'surface-container-high', 'surface-container-highest', 'inverse-surface', 'inverse-on-surface', 'inverse-primary',
16
17
  'outline', 'outline-variant', 'shadow', 'scrim',
17
- ...['primary', 'secondary', 'tertiary', 'error', 'success'].flatMap((c) => [c, `on-${c}`, `${c}-container`, `on-${c}-container`]),
18
+ ...['primary', 'secondary', 'tertiary', 'error', 'success', 'warning'].flatMap((c) => [c, `on-${c}`, `${c}-container`, `on-${c}-container`]),
18
19
  ...['primary', 'secondary', 'tertiary'].flatMap((c) => [`${c}-fixed`, `${c}-fixed-dim`, `on-${c}-fixed`, `on-${c}-fixed-variant`]),
19
20
  ].map((t) => `--color-${t}`)
20
21
 
@@ -41,7 +42,7 @@ let timer: ReturnType<typeof setTimeout> | undefined
41
42
  /** Runs `apply` (the DOM writes of a theme change) with the theme transition. */
42
43
  export function themeTransition(apply: () => void) {
43
44
  if (typeof document === 'undefined') return apply()
44
- const reduced = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
45
+ const reduced = shouldReduceMotion()
45
46
  if (reduced) return apply()
46
47
  const root = document.documentElement
47
48
 
@@ -0,0 +1,142 @@
1
+ import { getCurrentInstance, nextTick, onBeforeUnmount, watch } from 'vue'
2
+
3
+ /*
4
+ * Internal (not exported from index.ts): keyboard focus for modal surfaces (dialogs, modal sheets and drawers), as
5
+ * the ARIA dialog pattern asks:
6
+ * - on open, focus moves inside: to an element marked `autofocus` / `data-autofocus`, else the first focusable
7
+ * one, else the surface itself (made focusable with tabindex -1);
8
+ * - while open, Tab and Shift+Tab cycle inside it (only the top-most surface traps, so a select's modal or a
9
+ * confirm opened from a dialog takes over and hands back);
10
+ * - on close, focus returns to what had it before (the button that opened it), unless the user already moved it
11
+ * somewhere else.
12
+ */
13
+
14
+ const FOCUSABLE = [
15
+ 'a[href]', 'area[href]', 'button:not([disabled])', 'input:not([disabled]):not([type="hidden"])',
16
+ 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'audio[controls]', 'video[controls]',
17
+ '[contenteditable]:not([contenteditable="false"])', '[tabindex]:not([tabindex="-1"])',
18
+ ].join(',')
19
+
20
+ /** The elements Tab reaches inside `root`, in order (skipping inert, hidden and disabled ones) */
21
+ export function focusableIn(root: HTMLElement): HTMLElement[] {
22
+ return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
23
+ (el) => el.tabIndex >= 0 && !el.closest('[inert], [hidden]') && getComputedStyle(el).visibility !== 'hidden',
24
+ )
25
+ }
26
+
27
+ const stack: symbol[] = []
28
+ let listening = false
29
+ const handlers = new Map<symbol, (e: KeyboardEvent) => void>()
30
+
31
+ function onKeydown(e: KeyboardEvent) {
32
+ if (e.key !== 'Tab' || !stack.length) return
33
+ handlers.get(stack[stack.length - 1]!)?.(e)
34
+ }
35
+
36
+ export interface FocusTrapOptions {
37
+ /** What gets focus on open, instead of the first autofocus / focusable element */
38
+ initialFocus?: () => HTMLElement | null | undefined
39
+ /** Return focus to the element that had it before opening (default true) */
40
+ restoreFocus?: boolean
41
+ }
42
+
43
+ /**
44
+ * Traps keyboard focus in `container()` while `active()` is true; see the file comment. `container` is read after
45
+ * the DOM updates, so a surface rendered by the same `v-if` that `active` drives is already there.
46
+ */
47
+ export function useFocusTrap(
48
+ container: () => HTMLElement | null | undefined,
49
+ active: () => boolean,
50
+ options: FocusTrapOptions = {},
51
+ ) {
52
+ const key = Symbol('focus-trap')
53
+ let previous: HTMLElement | null = null
54
+ let held = false
55
+ // The surface as it was while open: on close its ref is already cleared while a leave animation still shows it
56
+ let lastRoot: HTMLElement | null = null
57
+
58
+ function trapTab(e: KeyboardEvent) {
59
+ const root = container()
60
+ if (root) lastRoot = root
61
+ if (!root) return
62
+ const items = focusableIn(root)
63
+ const current = document.activeElement as HTMLElement | null
64
+ if (!items.length) {
65
+ e.preventDefault()
66
+ root.focus()
67
+ return
68
+ }
69
+ const first = items[0]!
70
+ const last = items[items.length - 1]!
71
+ if (!current || !root.contains(current)) {
72
+ // Focus had escaped (a click on the scrim, a teleported popup that closed): bring it back
73
+ e.preventDefault()
74
+ ;(e.shiftKey ? last : first).focus()
75
+ } else if (e.shiftKey && (current === first || current === root)) {
76
+ e.preventDefault()
77
+ last.focus()
78
+ } else if (!e.shiftKey && current === last) {
79
+ e.preventDefault()
80
+ first.focus()
81
+ }
82
+ }
83
+
84
+ function focusInitial() {
85
+ const root = container()
86
+ if (!root) return
87
+ lastRoot = root
88
+ // Something inside already took focus while mounting (an input focusing itself): leave it
89
+ if (root.contains(document.activeElement)) return
90
+ const target =
91
+ options.initialFocus?.() ??
92
+ root.querySelector<HTMLElement>('[autofocus], [data-autofocus]') ??
93
+ focusableIn(root)[0]
94
+ if (target) target.focus({ preventScroll: true })
95
+ else {
96
+ if (!root.hasAttribute('tabindex')) root.setAttribute('tabindex', '-1')
97
+ root.focus({ preventScroll: true })
98
+ }
99
+ }
100
+
101
+ function start() {
102
+ if (held || typeof document === 'undefined') return
103
+ held = true
104
+ previous = document.activeElement as HTMLElement | null
105
+ stack.push(key)
106
+ handlers.set(key, trapTab)
107
+ if (!listening) {
108
+ document.addEventListener('keydown', onKeydown)
109
+ listening = true
110
+ }
111
+ nextTick(focusInitial)
112
+ }
113
+
114
+ function stop() {
115
+ if (!held) return
116
+ held = false
117
+ const i = stack.lastIndexOf(key)
118
+ if (i >= 0) stack.splice(i, 1)
119
+ handlers.delete(key)
120
+ if (!stack.length && listening) {
121
+ document.removeEventListener('keydown', onKeydown)
122
+ listening = false
123
+ }
124
+ const back = previous
125
+ previous = null
126
+ if (options.restoreFocus === false || !back) return
127
+ // Restore only when focus is still ours to give: inside the closing surface, or dropped on <body> because the
128
+ // surface was removed. A click that closed it by landing on another control keeps that control focused.
129
+ nextTick(() => {
130
+ const now = document.activeElement
131
+ const root = container() ?? lastRoot
132
+ lastRoot = null
133
+ const ours = !now || now === document.body || !now.isConnected || (root && root.contains(now))
134
+ if (ours && back.isConnected) back.focus({ preventScroll: true })
135
+ })
136
+ }
137
+
138
+ watch(() => !!active(), (on) => (on ? start() : stop()), { immediate: true, flush: 'post' })
139
+ if (getCurrentInstance()) onBeforeUnmount(stop)
140
+
141
+ return { focusFirst: focusInitial }
142
+ }
@@ -1,5 +1,5 @@
1
1
  import { computed, nextTick, onUnmounted, ref } from 'vue'
2
- import { motionSprings } from './motion'
2
+ import { appSprings } from './motion'
3
3
  import { playSamples, prefersReducedMotion, sampleSpring } from './_springAnimation'
4
4
  import { isRtl } from './_rtl'
5
5
 
@@ -83,7 +83,7 @@ export function useMenuNav(focusFirst: () => void) {
83
83
  nextTick(() => {
84
84
  const to = el.offsetHeight
85
85
  const anim = Math.abs(to - from) < 1 ? null
86
- : playSamples(el, sampleSpring(from, to, 0, motionSprings.standard.defaultSpatial, 0.5), (h) => ({ height: `${h}px` }))
86
+ : playSamples(el, sampleSpring(from, to, 0, appSprings().defaultSpatial, 0.5), (h) => ({ height: `${h}px` }))
87
87
  const slide = new Promise((r) => setTimeout(r, SLIDE_SETTLE_MS))
88
88
  Promise.all([slide, anim?.finished.catch(() => {})]).then(restore)
89
89
  })
@@ -183,7 +183,7 @@ export function useMenuNav(focusFirst: () => void) {
183
183
  level.style.opacity = ''
184
184
  if (prefersReducedMotion() || dx < 1) return
185
185
  const width = navBox.value?.clientWidth || 1
186
- playSamples(level, sampleSpring(dx, 0, 0, motionSprings.standard.defaultSpatial, 0.5), (x) => ({
186
+ playSamples(level, sampleSpring(dx, 0, 0, appSprings().defaultSpatial, 0.5), (x) => ({
187
187
  transform: `translateX(${x * sg}px)`,
188
188
  opacity: String(1 - 0.5 * Math.min(1, x / width)),
189
189
  }))
@@ -1,4 +1,5 @@
1
1
  import { computed, onMounted, onUnmounted, ref, watch, type Ref } from 'vue'
2
+ import { shouldReduceMotion } from './motion'
2
3
  import { isRtl, logicalKey } from './_rtl'
3
4
 
4
5
  /**
@@ -127,7 +128,7 @@ let busy = false // dragging or settling: the watcher below leaves the width alo
127
128
  function animateTo(a: PaneAnchor, velocity = 0) {
128
129
  cancelAnimationFrame(raf)
129
130
  const target = resolve(a)
130
- const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
131
+ const reduced = shouldReduceMotion()
131
132
  if (reduced || !o.pane.value) {
132
133
  busy = false
133
134
  write(target)