@m3ui-vue/m3ui-vue 0.8.8 → 0.9.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 (375) hide show
  1. package/README.md +25 -5
  2. package/dist/API.md +3661 -0
  3. package/dist/MIcon-CaEooCmZ.js.map +1 -1
  4. package/dist/{MMenuItem-5xojJYAL.js → MTextField-pJU1vFaR.js} +374 -364
  5. package/dist/MTextField-pJU1vFaR.js.map +1 -0
  6. package/dist/api.json +1 -0
  7. package/dist/barcode.js +9 -11
  8. package/dist/barcode.js.map +1 -1
  9. package/dist/chart.js.map +1 -1
  10. package/dist/code-editor.js +2 -2
  11. package/dist/code-editor.js.map +1 -1
  12. package/dist/components/MAbsolute.vue.d.ts +12 -0
  13. package/dist/components/MAlert.vue.d.ts +4 -0
  14. package/dist/components/MAppBar.vue.d.ts +12 -0
  15. package/dist/components/MAppLayout.vue.d.ts +2 -0
  16. package/dist/components/MAspectRatio.vue.d.ts +1 -0
  17. package/dist/components/MAutocomplete.vue.d.ts +18 -0
  18. package/dist/components/MAvatar.vue.d.ts +3 -0
  19. package/dist/components/MBadge.vue.d.ts +6 -0
  20. package/dist/components/MBar.vue.d.ts +5 -0
  21. package/dist/components/MBarcode.vue.d.ts +9 -0
  22. package/dist/components/MBottomSheet.vue.d.ts +3 -0
  23. package/dist/components/MBox.vue.d.ts +6 -0
  24. package/dist/components/MBreadcrumbs.vue.d.ts +2 -0
  25. package/dist/components/MButton.vue.d.ts +14 -4
  26. package/dist/components/MButtonGroup.vue.d.ts +7 -0
  27. package/dist/components/MCalendar.vue.d.ts +8 -0
  28. package/dist/components/MCard.vue.d.ts +17 -0
  29. package/dist/components/MCarousel.vue.d.ts +61 -36
  30. package/dist/components/MCenter.vue.d.ts +1 -0
  31. package/dist/components/MChart.vue.d.ts +7 -0
  32. package/dist/components/MChatBubble.vue.d.ts +10 -0
  33. package/dist/components/MCheckbox.vue.d.ts +5 -0
  34. package/dist/components/MChip.vue.d.ts +9 -0
  35. package/dist/components/MCircleProgressBar.vue.d.ts +7 -0
  36. package/dist/components/MCodeEditor.vue.d.ts +9 -0
  37. package/dist/components/MColorPicker.vue.d.ts +8 -0
  38. package/dist/components/MColorPickerModal.vue.d.ts +4 -0
  39. package/dist/components/MCommandPalette.vue.d.ts +8 -0
  40. package/dist/components/MConfirmDialog.vue.d.ts +7 -0
  41. package/dist/components/MContainer.vue.d.ts +4 -0
  42. package/dist/components/MContextMenu.vue.d.ts +3 -6
  43. package/dist/components/MCopyButton.vue.d.ts +10 -0
  44. package/dist/components/MDataTable.vue.d.ts +33 -12
  45. package/dist/components/MDatePicker.vue.d.ts +16 -0
  46. package/dist/components/MDatePickerModal.vue.d.ts +9 -0
  47. package/dist/components/MDateRangePicker.vue.d.ts +18 -0
  48. package/dist/components/MDateRangePickerModal.vue.d.ts +9 -0
  49. package/dist/components/MDialog.vue.d.ts +10 -6
  50. package/dist/components/MDivider.vue.d.ts +6 -0
  51. package/dist/components/MDragDropList.vue.d.ts +6 -0
  52. package/dist/components/MEmoji.vue.d.ts +6 -0
  53. package/dist/components/MEmojiButton.vue.d.ts +5 -0
  54. package/dist/components/MEmojiSelector.vue.d.ts +21 -5
  55. package/dist/components/MEmptyState.vue.d.ts +4 -0
  56. package/dist/components/MExpansionPanel.vue.d.ts +9 -0
  57. package/dist/components/MExportButton.vue.d.ts +8 -0
  58. package/dist/components/MFab.vue.d.ts +9 -0
  59. package/dist/components/MFabMenu.vue.d.ts +15 -1
  60. package/dist/components/MFileUpload.vue.d.ts +8 -0
  61. package/dist/components/MFixed.vue.d.ts +10 -0
  62. package/dist/components/MFlex.vue.d.ts +7 -1
  63. package/dist/components/MFooter.vue.d.ts +11 -0
  64. package/dist/components/MFullscreen.vue.d.ts +2 -0
  65. package/dist/components/MGrid.vue.d.ts +7 -0
  66. package/dist/components/MHotkeys.vue.d.ts +4 -0
  67. package/dist/components/MIcon.vue.d.ts +2 -0
  68. package/dist/components/MIconButton.vue.d.ts +10 -0
  69. package/dist/components/MInfiniteScroll.vue.d.ts +6 -0
  70. package/dist/components/MJsonEditor.vue.d.ts +8 -0
  71. package/dist/components/MJsonViewer.vue.d.ts +4 -0
  72. package/dist/components/MKanban.vue.d.ts +2 -0
  73. package/dist/components/MKbd.vue.d.ts +2 -0
  74. package/dist/components/MLightbox.vue.d.ts +19 -5
  75. package/dist/components/MList.vue.d.ts +7 -0
  76. package/dist/components/MListItem.vue.d.ts +24 -0
  77. package/dist/components/MListSubheader.vue.d.ts +6 -0
  78. package/dist/components/MLoadingIndicator.vue.d.ts +10 -0
  79. package/dist/components/MLoadingOverlay.vue.d.ts +5 -0
  80. package/dist/components/MMarkdown.vue.d.ts +3 -0
  81. package/dist/components/MMaskField.vue.d.ts +15 -0
  82. package/dist/components/MMasonry.vue.d.ts +5 -0
  83. package/dist/components/MMenu.vue.d.ts +3 -6
  84. package/dist/components/MMenuDivider.vue.d.ts +4 -0
  85. package/dist/components/MMenuItem.vue.d.ts +5 -0
  86. package/dist/components/MMultiAutocomplete.vue.d.ts +20 -0
  87. package/dist/components/MMultiSelect.vue.d.ts +21 -0
  88. package/dist/components/MNavigationBar.vue.d.ts +2 -0
  89. package/dist/components/MNavigationDrawer.vue.d.ts +11 -0
  90. package/dist/components/MNavigationRail.vue.d.ts +9 -6
  91. package/dist/components/MNavigationSuite.vue.d.ts +5 -3
  92. package/dist/components/MNumberField.vue.d.ts +17 -0
  93. package/dist/components/MOverlay.vue.d.ts +3 -0
  94. package/dist/components/MPageProgress.vue.d.ts +3 -0
  95. package/dist/components/MPagination.vue.d.ts +3 -0
  96. package/dist/components/MPasswordMeter.vue.d.ts +1 -0
  97. package/dist/components/MPinInput.vue.d.ts +11 -0
  98. package/dist/components/MProgressBar.vue.d.ts +6 -0
  99. package/dist/components/MPullToRefresh.vue.d.ts +8 -0
  100. package/dist/components/MQRCode.vue.d.ts +6 -0
  101. package/dist/components/MRadio.vue.d.ts +5 -0
  102. package/dist/components/MRadioGroup.vue.d.ts +6 -0
  103. package/dist/components/MRating.vue.d.ts +11 -0
  104. package/dist/components/MRelativeTime.vue.d.ts +1 -0
  105. package/dist/components/MResponsive.vue.d.ts +3 -0
  106. package/dist/components/MResult.vue.d.ts +6 -0
  107. package/dist/components/MRichTextEditor.vue.d.ts +8 -0
  108. package/dist/components/MScheduler.vue.d.ts +48 -1
  109. package/dist/components/MScrollable.vue.d.ts +3 -0
  110. package/dist/components/MSearchBar.vue.d.ts +6 -0
  111. package/dist/components/MSection.vue.d.ts +5 -0
  112. package/dist/components/MSegmentedButton.vue.d.ts +5 -0
  113. package/dist/components/MSelect.vue.d.ts +17 -0
  114. package/dist/components/MShader.vue.d.ts +1 -0
  115. package/dist/components/MShape.vue.d.ts +1 -1
  116. package/dist/components/MShortNavigationBar.vue.d.ts +8 -9
  117. package/dist/components/MSideSheet.vue.d.ts +3 -0
  118. package/dist/components/MSignaturePad.vue.d.ts +7 -0
  119. package/dist/components/MSimpleCarousel.vue.d.ts +12 -2
  120. package/dist/components/MSkeleton.vue.d.ts +8 -0
  121. package/dist/components/MSlider.vue.d.ts +15 -1
  122. package/dist/components/MSnackbar.vue.d.ts +1 -0
  123. package/dist/components/MSpinner.vue.d.ts +6 -0
  124. package/dist/components/MSplitButton.vue.d.ts +7 -0
  125. package/dist/components/MSplitter.vue.d.ts +4 -0
  126. package/dist/components/MSpotlightSearch.vue.d.ts +18 -0
  127. package/dist/components/MStack.vue.d.ts +8 -1
  128. package/dist/components/MStatCard.vue.d.ts +7 -0
  129. package/dist/components/MStepper.vue.d.ts +7 -0
  130. package/dist/components/MSticky.vue.d.ts +2 -0
  131. package/dist/components/MSubtitle.vue.d.ts +4 -0
  132. package/dist/components/MSwitch.vue.d.ts +5 -6
  133. package/dist/components/MTable.vue.d.ts +17 -4
  134. package/dist/components/MTabs.vue.d.ts +6 -0
  135. package/dist/components/MTagInput.vue.d.ts +17 -0
  136. package/dist/components/MTerminal.vue.d.ts +4 -0
  137. package/dist/components/MText.vue.d.ts +10 -0
  138. package/dist/components/MTextField.vue.d.ts +18 -0
  139. package/dist/components/MTimePicker.vue.d.ts +10 -0
  140. package/dist/components/MTimePickerModal.vue.d.ts +5 -0
  141. package/dist/components/MTimeline.vue.d.ts +3 -0
  142. package/dist/components/MTitle.vue.d.ts +4 -0
  143. package/dist/components/MToggleButton.vue.d.ts +4 -0
  144. package/dist/components/MToolbar.vue.d.ts +6 -1
  145. package/dist/components/MTooltip.vue.d.ts +7 -0
  146. package/dist/components/MTopAppBar.vue.d.ts +8 -0
  147. package/dist/components/MTour.vue.d.ts +5 -0
  148. package/dist/components/MTransferList.vue.d.ts +11 -0
  149. package/dist/components/MTree.vue.d.ts +11 -0
  150. package/dist/components/MTreeTable.vue.d.ts +7 -0
  151. package/dist/components/MVirtualTable.vue.d.ts +6 -0
  152. package/dist/components/MWindow.vue.d.ts +33 -1
  153. package/dist/composables/_carouselStrategy.d.ts +101 -0
  154. package/dist/composables/useLocale.d.ts +21 -0
  155. package/dist/data/emoji-names/emoji-names-de.d.ts +2 -0
  156. package/dist/data/emoji-names/emoji-names-en.d.ts +2 -0
  157. package/dist/data/emoji-names/emoji-names-es.d.ts +2 -0
  158. package/dist/data/emoji-names/emoji-names-fr.d.ts +2 -0
  159. package/dist/data/emoji-names/emoji-names-ja.d.ts +2 -0
  160. package/dist/data/emoji-names/emoji-names-ko.d.ts +2 -0
  161. package/dist/data/emoji-names/emoji-names-pt.d.ts +2 -0
  162. package/dist/data/emoji-names/emoji-names-zh.d.ts +2 -0
  163. package/dist/data/emojis.d.ts +7 -1
  164. package/dist/emoji-names-de-BphO5XpV.js +1877 -0
  165. package/dist/emoji-names-de-BphO5XpV.js.map +1 -0
  166. package/dist/emoji-names-en-9ZvMRvzi.js +1877 -0
  167. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -0
  168. package/dist/emoji-names-es-DvfWU3Pj.js +1877 -0
  169. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -0
  170. package/dist/emoji-names-fr-B-jhUlsP.js +1877 -0
  171. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -0
  172. package/dist/emoji-names-ja-l8cMFJo1.js +1877 -0
  173. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -0
  174. package/dist/emoji-names-ko-YP-o9G0c.js +1877 -0
  175. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -0
  176. package/dist/emoji-names-pt-DGj_Js4M.js +1877 -0
  177. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -0
  178. package/dist/emoji-names-zh-Dzecwtw_.js +1877 -0
  179. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -0
  180. package/dist/index.d.ts +2 -2
  181. package/dist/locales/index.js +140 -7
  182. package/dist/locales/index.js.map +1 -1
  183. package/dist/m3ui-vue.css +1 -1
  184. package/dist/m3ui.js +6642 -5160
  185. package/dist/m3ui.js.map +1 -1
  186. package/dist/markdown.js +1 -1
  187. package/dist/markdown.js.map +1 -1
  188. package/dist/plugin.d.ts +6 -0
  189. package/dist/qrcode.js.map +1 -1
  190. package/dist/rich-text-editor.js +10 -10
  191. package/dist/rich-text-editor.js.map +1 -1
  192. package/dist/styles.css +1 -1
  193. package/dist/terminal.js +34 -27
  194. package/dist/terminal.js.map +1 -1
  195. package/dist/{useLocale-D3ZWZ8jY.js → useLocale-Drihe5G2.js} +33 -11
  196. package/dist/useLocale-Drihe5G2.js.map +1 -0
  197. package/package.json +4 -2
  198. package/src/__tests__/MCarousel.test.ts +183 -21
  199. package/src/__tests__/MDialog.test.ts +18 -0
  200. package/src/__tests__/MEmojiSelector.test.ts +138 -0
  201. package/src/__tests__/MHotkeys.test.ts +57 -0
  202. package/src/__tests__/MLightbox.test.ts +313 -5
  203. package/src/__tests__/MScheduler.test.ts +122 -0
  204. package/src/__tests__/MTerminal.test.ts +63 -0
  205. package/src/__tests__/attrsFallthrough.test.ts +65 -0
  206. package/src/__tests__/hostLocale.test.ts +57 -0
  207. package/src/__tests__/plugin.test.ts +28 -1
  208. package/src/components/MAbsolute.vue +18 -0
  209. package/src/components/MAlert.vue +12 -0
  210. package/src/components/MAppBar.vue +12 -0
  211. package/src/components/MAppLayout.vue +11 -0
  212. package/src/components/MAspectRatio.vue +6 -0
  213. package/src/components/MAutocomplete.vue +24 -0
  214. package/src/components/MAvatar.vue +12 -1
  215. package/src/components/MBadge.vue +11 -0
  216. package/src/components/MBar.vue +19 -0
  217. package/src/components/MBarcode.vue +18 -2
  218. package/src/components/MBottomSheet.vue +13 -1
  219. package/src/components/MBox.vue +12 -0
  220. package/src/components/MBreadcrumbs.vue +7 -0
  221. package/src/components/MButton.vue +22 -4
  222. package/src/components/MButtonGroup.vue +13 -0
  223. package/src/components/MCalendar.vue +14 -0
  224. package/src/components/MCard.vue +26 -0
  225. package/src/components/MCarousel.vue +542 -200
  226. package/src/components/MCenter.vue +6 -0
  227. package/src/components/MChart.vue +12 -0
  228. package/src/components/MChatBubble.vue +17 -0
  229. package/src/components/MCheckbox.vue +11 -0
  230. package/src/components/MChip.vue +17 -0
  231. package/src/components/MCircleProgressBar.vue +13 -0
  232. package/src/components/MCodeEditor.vue +18 -2
  233. package/src/components/MColorPicker.vue +13 -0
  234. package/src/components/MColorPickerModal.vue +12 -0
  235. package/src/components/MCommandPalette.vue +17 -1
  236. package/src/components/MConfirmDialog.vue +15 -0
  237. package/src/components/MContainer.vue +9 -0
  238. package/src/components/MContextMenu.vue +20 -7
  239. package/src/components/MCopyButton.vue +16 -0
  240. package/src/components/MDataTable.vue +58 -12
  241. package/src/components/MDatePicker.vue +21 -0
  242. package/src/components/MDatePickerModal.vue +17 -1
  243. package/src/components/MDateRangePicker.vue +23 -0
  244. package/src/components/MDateRangePickerModal.vue +17 -1
  245. package/src/components/MDialog.vue +43 -10
  246. package/src/components/MDivider.vue +6 -0
  247. package/src/components/MDragDropList.vue +18 -0
  248. package/src/components/MEmoji.vue +6 -0
  249. package/src/components/MEmojiButton.vue +11 -0
  250. package/src/components/MEmojiSelector.vue +486 -78
  251. package/src/components/MEmptyState.vue +9 -0
  252. package/src/components/MExpansionPanel.vue +17 -0
  253. package/src/components/MExportButton.vue +15 -0
  254. package/src/components/MFab.vue +20 -1
  255. package/src/components/MFabMenu.vue +20 -0
  256. package/src/components/MFileUpload.vue +19 -0
  257. package/src/components/MFixed.vue +16 -0
  258. package/src/components/MFlex.vue +11 -0
  259. package/src/components/MFooter.vue +11 -0
  260. package/src/components/MFullscreen.vue +8 -0
  261. package/src/components/MGrid.vue +12 -0
  262. package/src/components/MHotkeys.vue +20 -13
  263. package/src/components/MIcon.vue +10 -1
  264. package/src/components/MIconButton.vue +13 -0
  265. package/src/components/MInfiniteScroll.vue +16 -0
  266. package/src/components/MJsonEditor.vue +13 -0
  267. package/src/components/MJsonViewer.vue +7 -0
  268. package/src/components/MKanban.vue +18 -0
  269. package/src/components/MKbd.vue +6 -0
  270. package/src/components/MLightbox.vue +766 -268
  271. package/src/components/MList.vue +15 -0
  272. package/src/components/MListDetail.vue +11 -0
  273. package/src/components/MListItem.vue +37 -0
  274. package/src/components/MListSubheader.vue +6 -0
  275. package/src/components/MLoadingIndicator.vue +15 -0
  276. package/src/components/MLoadingOverlay.vue +18 -1
  277. package/src/components/MMarkdown.vue +7 -0
  278. package/src/components/MMaskField.vue +21 -0
  279. package/src/components/MMasonry.vue +11 -0
  280. package/src/components/MMenu.vue +19 -7
  281. package/src/components/MMenuDivider.vue +4 -0
  282. package/src/components/MMenuItem.vue +16 -0
  283. package/src/components/MMultiAutocomplete.vue +26 -0
  284. package/src/components/MMultiSelect.vue +27 -0
  285. package/src/components/MNavigationBar.vue +7 -0
  286. package/src/components/MNavigationDrawer.vue +30 -1
  287. package/src/components/MNavigationRail.vue +27 -6
  288. package/src/components/MNavigationSuite.vue +20 -3
  289. package/src/components/MNotificationHost.vue +3 -0
  290. package/src/components/MNumberField.vue +24 -0
  291. package/src/components/MOverlay.vue +11 -0
  292. package/src/components/MPageProgress.vue +7 -0
  293. package/src/components/MPagination.vue +15 -1
  294. package/src/components/MPasswordMeter.vue +7 -0
  295. package/src/components/MPinInput.vue +19 -0
  296. package/src/components/MProgressBar.vue +9 -0
  297. package/src/components/MPullToRefresh.vue +17 -0
  298. package/src/components/MQRCode.vue +12 -0
  299. package/src/components/MRadio.vue +11 -0
  300. package/src/components/MRadioGroup.vue +11 -0
  301. package/src/components/MRating.vue +19 -0
  302. package/src/components/MRelative.vue +8 -0
  303. package/src/components/MRelativeTime.vue +6 -0
  304. package/src/components/MResponsive.vue +9 -0
  305. package/src/components/MResult.vue +14 -0
  306. package/src/components/MRichTextEditor.vue +14 -0
  307. package/src/components/MScheduler.vue +303 -115
  308. package/src/components/MScrollable.vue +8 -0
  309. package/src/components/MSearchBar.vue +17 -0
  310. package/src/components/MSection.vue +13 -0
  311. package/src/components/MSegmentedButton.vue +10 -0
  312. package/src/components/MSelect.vue +22 -0
  313. package/src/components/MShader.vue +13 -0
  314. package/src/components/MShape.vue +6 -0
  315. package/src/components/MShortNavigationBar.vue +23 -9
  316. package/src/components/MSideSheet.vue +14 -1
  317. package/src/components/MSignaturePad.vue +15 -0
  318. package/src/components/MSimpleCarousel.vue +18 -0
  319. package/src/components/MSkeleton.vue +8 -0
  320. package/src/components/MSlider.vue +21 -0
  321. package/src/components/MSnackbar.vue +5 -0
  322. package/src/components/MSpacer.vue +6 -0
  323. package/src/components/MSpinner.vue +10 -0
  324. package/src/components/MSplitButton.vue +17 -1
  325. package/src/components/MSplitter.vue +10 -0
  326. package/src/components/MSpotlightSearch.vue +28 -1
  327. package/src/components/MStack.vue +12 -0
  328. package/src/components/MStatCard.vue +13 -0
  329. package/src/components/MStepper.vue +12 -0
  330. package/src/components/MSticky.vue +7 -0
  331. package/src/components/MSubtitle.vue +9 -0
  332. package/src/components/MSupportingPane.vue +10 -0
  333. package/src/components/MSwitch.vue +14 -6
  334. package/src/components/MTable.vue +33 -4
  335. package/src/components/MTabs.vue +12 -0
  336. package/src/components/MTagInput.vue +23 -0
  337. package/src/components/MTerminal.vue +33 -10
  338. package/src/components/MText.vue +15 -0
  339. package/src/components/MTextField.vue +26 -0
  340. package/src/components/MTimePicker.vue +15 -0
  341. package/src/components/MTimePickerModal.vue +13 -1
  342. package/src/components/MTimeline.vue +7 -0
  343. package/src/components/MTitle.vue +9 -0
  344. package/src/components/MToggleButton.vue +12 -0
  345. package/src/components/MToolbar.vue +12 -0
  346. package/src/components/MTooltip.vue +18 -0
  347. package/src/components/MTopAppBar.vue +18 -0
  348. package/src/components/MTour.vue +15 -2
  349. package/src/components/MTransferList.vue +24 -0
  350. package/src/components/MTree.vue +11 -0
  351. package/src/components/MTreeTable.vue +15 -0
  352. package/src/components/MVirtualTable.vue +12 -0
  353. package/src/components/MWindow.vue +34 -0
  354. package/src/composables/_carouselStrategy.ts +712 -0
  355. package/src/composables/useLocale.ts +54 -3
  356. package/src/data/emoji-names/emoji-names-de.ts +1875 -0
  357. package/src/data/emoji-names/emoji-names-en.ts +1875 -0
  358. package/src/data/emoji-names/emoji-names-es.ts +1875 -0
  359. package/src/data/emoji-names/emoji-names-fr.ts +1875 -0
  360. package/src/data/emoji-names/emoji-names-ja.ts +1875 -0
  361. package/src/data/emoji-names/emoji-names-ko.ts +1875 -0
  362. package/src/data/emoji-names/emoji-names-pt.ts +1875 -0
  363. package/src/data/emoji-names/emoji-names-zh.ts +1875 -0
  364. package/src/data/emojis.ts +29 -198
  365. package/src/index.ts +2 -2
  366. package/src/locales/de.ts +19 -0
  367. package/src/locales/es.ts +19 -0
  368. package/src/locales/fr.ts +19 -0
  369. package/src/locales/ja.ts +19 -0
  370. package/src/locales/ko.ts +19 -0
  371. package/src/locales/pt.ts +19 -0
  372. package/src/locales/zh.ts +19 -0
  373. package/src/plugin.ts +14 -2
  374. package/dist/MMenuItem-5xojJYAL.js.map +0 -1
  375. package/dist/useLocale-D3ZWZ8jY.js.map +0 -1
@@ -1,275 +1,617 @@
1
- <script setup lang="ts">
2
- import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
3
- import MIcon from './MIcon.vue'
4
-
1
+ <script lang="ts">
5
2
  export interface CarouselItem {
6
3
  src: string
7
4
  alt?: string
8
5
  label?: string
9
6
  }
10
7
 
8
+ export type CarouselVariant = 'multi-browse' | 'uncontained' | 'hero' | 'full-screen'
9
+ export type CarouselFlingBehavior = 'single-advance' | 'multi-browse' | 'no-snap'
10
+ </script>
11
+
12
+ <script setup lang="ts" generic="T = CarouselItem">
13
+ /**
14
+ * The Material 3 carousel, with its four layouts. Items keep one size and are laid out side by side; as you
15
+ * scroll, each one is masked down to the space it has, so items grow as they reach the focal position and
16
+ * shrink as they leave. Drag it (touch or mouse), scroll it with a trackpad or a horizontal wheel, or focus it
17
+ * and use the arrow keys. For fixed-width slides with arrows and autoplay, see MSimpleCarousel.
18
+ *
19
+ * @slot item Content of each item, filling its full (unmasked) box. Replaces the default image and label
20
+ * @event update:modelValue The current item changed
21
+ * @event itemClick An item was clicked (not dragged). A partly visible item also scrolls into focus
22
+ */
11
23
  /*
12
- * Ported from the real M3 `HorizontalMultiBrowseCarousel` (Carousel.kt/Keylines.kt), not the
13
- * "flat fixed-width items" look this library's old MCarousel had (now MSimpleCarousel). The real
14
- * spec's signature behavior: one large "focal" item at rest, with neighbors progressively masked
15
- * down toward a small "peek" size the further they are from the focal position — items grow/shrink
16
- * continuously as you scroll, they're not just fixed-size slides.
24
+ * M3 carousel, ported from Compose Material3 (carousel/Carousel.kt and the keyline engine in
25
+ * ../composables/_carouselStrategy.ts). Like Compose's pager-based Carousel, every item has the
26
+ * same size (the strategy's focal size) and they're laid out end to end; what changes while
27
+ * scrolling is only how each one looks: it's clipped to a mask, centered in the item, the size of
28
+ * the keyline it sits on, and translated so masked items touch. The scroll geometry never changes,
29
+ * which is what the old flex/width-based version got wrong (resizing items mid-scroll fought the
30
+ * browser's scroll and scroll-snap).
17
31
  *
18
- * Real defaults ported exactly: minSmallItemWidth = MinSmallItemSize = 40dp, maxSmallItemWidth =
19
- * MaxSmallItemSize = 56dp, itemSpacing = 0dp, targetSmallSize = clamp(largeSize/3, min, max), and
20
- * the left-aligned focal convention (createLeftAlignedKeylineList — the focal item sits at the
21
- * scroll container's left edge, not centered).
32
+ * Variants: 'multi-browse' (HorizontalMultiBrowseCarousel), 'uncontained'
33
+ * (HorizontalUncontainedCarousel), 'hero' (HorizontalCenteredHeroCarousel) and 'full-screen'
34
+ * (MDC-Android's FullScreenCarouselStrategy: one item filling the container, usually vertical).
22
35
  *
23
- * Deliberately NOT ported: the real `Arrangement.findLowestCostArrangement` combinatorial search
24
- * that decides exactly how many large/medium/small items fit a given width to the pixel. That's a
25
- * large amount of code for a difference only visible at unusual width/item-count combinations —
26
- * this uses a direct triangular falloff from the focal position instead, which converges to the
27
- * same large-focal-item-with-shrinking-neighbors look for realistic carousels.
36
+ * Scrolling is our own (Pointer Events + wheel + keys), driven in a rAF loop that writes
37
+ * transform/clip-path straight to each item, never through a reactive :style binding. Release
38
+ * behavior follows CarouselDefaults: singleAdvanceFlingBehavior (at most one item per fling) for
39
+ * multi-browse/hero/full-screen, noSnapFlingBehavior for uncontained, and the snap animation is
40
+ * spring(stiffness = StiffnessMediumLow = 400, dampingRatio = 1). The fling decay itself is an
41
+ * exponential friction curve, an approximation of Android's spline decay.
28
42
  */
43
+ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
44
+ import { useLocale } from '../composables/useLocale'
45
+ import {
46
+ Strategy,
47
+ fullScreenKeylineList,
48
+ heroKeylineList,
49
+ maxScrollOffset,
50
+ multiBrowseKeylineList,
51
+ placeItem,
52
+ snapScrollOffset,
53
+ uncontainedKeylineList,
54
+ } from '../composables/_carouselStrategy'
55
+
29
56
  const props = withDefaults(
30
57
  defineProps<{
31
- items: CarouselItem[]
32
- /** Target width of the large, fully-visible focal item, in px (preferredItemWidth). */
33
- itemWidth?: number
34
- /** Spacing between item slots, in px. Real default (CarouselDefaults.ItemSpacing) is 0. */
58
+ /** Items to render, required. CarouselItem by default; any type with an #item slot */
59
+ items: T[]
60
+ /** Index of the current (snapped) item; use with v-model to follow or drive it. */
61
+ modelValue?: number
62
+ /** Carousel layout */
63
+ variant?: CarouselVariant
64
+ /** Scroll axis */
65
+ orientation?: 'horizontal' | 'vertical'
66
+ /**
67
+ * Size of large items along the scroll axis, in px. Multi-browse and hero treat it as the
68
+ * preferred size (the arrangement that fits best wins); uncontained uses it as is. Hero
69
+ * without it fills the container minus its small items; full-screen ignores it.
70
+ */
71
+ itemSize?: number
72
+ /** Space between items, in px (M3 uses 8). */
35
73
  itemSpacing?: number
36
- /** Real default (CarouselDefaults.MinSmallItemSize) is 40. */
37
- minSmallItemWidth?: number
38
- /** Real default (CarouselDefaults.MaxSmallItemSize) is 56. */
39
- maxSmallItemWidth?: number
74
+ /** Padding at both ends of the scroll axis, in px. Items scroll under it. */
75
+ contentPadding?: number
76
+ /** Smallest size a small item can take (multi-browse, hero) */
77
+ minSmallItemSize?: number
78
+ /** Largest size a small item can take (multi-browse, hero) */
79
+ maxSmallItemSize?: number
80
+ /** What a release does. Defaults to 'no-snap' for uncontained, 'single-advance' otherwise. */
81
+ flingBehavior?: CarouselFlingBehavior
82
+ /** Allow dragging, wheel and keyboard scrolling */
83
+ userScrollEnabled?: boolean
84
+ /** Height of the carousel. Defaults to 205px for a horizontal carousel that isn't full-screen. */
40
85
  height?: string
41
- showArrows?: boolean
42
- autoplay?: boolean
43
- interval?: number
86
+ /** Accessible name of the carousel. */
87
+ label?: string
44
88
  }>(),
45
89
  {
46
- itemWidth: 280,
47
- itemSpacing: 0,
48
- minSmallItemWidth: 40,
49
- maxSmallItemWidth: 56,
50
- height: '220px',
51
- showArrows: true,
52
- autoplay: false,
53
- interval: 5000,
90
+ variant: 'multi-browse',
91
+ orientation: 'horizontal',
92
+ itemSpacing: 8,
93
+ contentPadding: 0,
94
+ minSmallItemSize: 40,
95
+ maxSmallItemSize: 56,
96
+ userScrollEnabled: true,
54
97
  },
55
98
  )
56
99
 
57
- const emit = defineEmits<{ change: [index: number] }>()
100
+ const emit = defineEmits<{
101
+ 'update:modelValue': [index: number]
102
+ itemClick: [item: T, index: number]
103
+ }>()
58
104
 
59
- const trackEl = ref<HTMLElement | null>(null)
60
- const itemEls = ref<(HTMLElement | null)[]>([])
61
- const containerWidth = ref(0)
62
- const activeIndex = ref(0)
105
+ defineSlots<{
106
+ item?: (scope: { item: T; index: number }) => unknown
107
+ }>()
63
108
 
64
- function setItemRef(el: unknown, i: number) {
65
- itemEls.value[i] = (el as HTMLElement) ?? null
66
- }
109
+ const t = useLocale()
110
+
111
+ const SPRING_STIFFNESS = 400
112
+ const SPRING_DAMPING = 1
113
+ const MIN_FLING_VELOCITY = 400
114
+ const FLING_FRICTION = 4
115
+ const DEFAULT_ITEM_SIZE = 186
116
+
117
+ const rootEl = ref<HTMLElement | null>(null)
118
+ const itemEls: (HTMLElement | null)[] = []
119
+ const labelEls: (HTMLElement | null)[] = []
120
+ let labelWidths: number[] = []
121
+ const mainSize = ref(0)
122
+ const currentIndex = ref(clampIndex(props.modelValue ?? 0, props.items.length))
67
123
 
68
- const targetLarge = computed(() => Math.min(props.itemWidth, containerWidth.value || props.itemWidth))
69
- const targetSmall = computed(() => {
70
- const raw = targetLarge.value / 3
71
- return Math.min(Math.max(raw, props.minSmallItemWidth), props.maxSmallItemWidth)
124
+ const horizontal = computed(() => props.orientation === 'horizontal')
125
+ let rtl = false
126
+
127
+ // Only the number of items matters to the geometry: depending on the array itself would rebuild
128
+ // the strategy (and re-snap) whenever a consumer passes a fresh inline array on re-render.
129
+ const itemCount = computed(() => props.items.length)
130
+
131
+ const strategy = computed(() => {
132
+ const size = mainSize.value
133
+ const count = itemCount.value
134
+ const spacing = props.itemSpacing
135
+ const keylines =
136
+ props.variant === 'uncontained'
137
+ ? uncontainedKeylineList(size, props.itemSize ?? DEFAULT_ITEM_SIZE, spacing)
138
+ : props.variant === 'hero'
139
+ ? heroKeylineList(size, props.itemSize ?? null, spacing, count, true, props.minSmallItemSize, props.maxSmallItemSize)
140
+ : props.variant === 'full-screen'
141
+ ? fullScreenKeylineList(size, spacing)
142
+ : multiBrowseKeylineList(size, props.itemSize ?? DEFAULT_ITEM_SIZE, spacing, count, props.minSmallItemSize, props.maxSmallItemSize)
143
+ return new Strategy(keylines, size, spacing, props.contentPadding, props.contentPadding)
72
144
  })
73
145
 
74
- const maskWidths = ref<number[]>([])
75
- const imgOffsets = ref<number[]>([])
76
- let rafId = 0
146
+ const itemMainSize = computed(() => (strategy.value.isValid ? strategy.value.itemMainAxisSize : 0))
147
+ const snaps = computed(() => Array.from({ length: itemCount.value }, (_, i) => snapScrollOffset(strategy.value, i, itemCount.value)))
148
+ const maxScroll = computed(() => (strategy.value.isValid ? maxScrollOffset(strategy.value, itemCount.value) : 0))
77
149
 
78
- function onScroll() {
79
- if (rafId) return
80
- rafId = requestAnimationFrame(() => {
81
- rafId = 0
82
- updateMasks()
83
- })
150
+ const resolvedFling = computed<CarouselFlingBehavior>(
151
+ () => props.flingBehavior ?? (props.variant === 'uncontained' ? 'no-snap' : 'single-advance'),
152
+ )
153
+
154
+ const resolvedHeight = computed(
155
+ () => props.height ?? (horizontal.value && props.variant !== 'full-screen' ? '205px' : undefined),
156
+ )
157
+
158
+ function itemLabel(i: number) {
159
+ return t.carouselItem.replace('{index}', String(i + 1)).replace('{count}', String(props.items.length))
84
160
  }
85
161
 
86
- function updateMasks() {
87
- if (!trackEl.value) return
88
- const trackLeft = trackEl.value.getBoundingClientRect().left
89
- const large = targetLarge.value
90
- const small = targetSmall.value
91
- const widths: number[] = []
92
- const offsets: number[] = []
93
- let closest = 0
94
- let closestDist = Infinity
95
-
96
- for (let i = 0; i < itemEls.value.length; i++) {
97
- const el = itemEls.value[i]
98
- if (!el) { widths.push(large); offsets.push(0); continue }
99
- const offset = el.getBoundingClientRect().left - trackLeft
100
-
101
- let width: number
102
- let imgOffset: number
103
- if (offset <= 0) {
104
- // Exiting (or resting) on the left: mask grows in from the left, keep the right portion
105
- // of the image visible (matches the real maskStart clipping from the item's start edge).
106
- width = Math.max(large + offset, small)
107
- imgOffset = -(large - width)
108
- } else {
109
- // Upcoming on the right: mask shrinks from the right, keep the left portion visible.
110
- width = Math.max(large - offset, small)
111
- imgOffset = 0
162
+ function clampIndex(i: number, count: number) {
163
+ return Math.min(Math.max(i, 0), Math.max(count - 1, 0))
164
+ }
165
+
166
+ function nearestIndex(pos: number) {
167
+ let best = 0
168
+ let bestDist = Infinity
169
+ snaps.value.forEach((s, i) => {
170
+ const d = Math.abs(s - pos)
171
+ if (d < bestDist - 0.5) {
172
+ best = i
173
+ bestDist = d
112
174
  }
113
- widths.push(width)
114
- offsets.push(imgOffset)
175
+ })
176
+ return best
177
+ }
178
+
179
+ // ── Per-frame state, outside Vue's reactivity ───────────────────────────────────────────────
180
+
181
+ let scroll = 0
182
+ let velocity = 0
183
+ let anim: { kind: 'spring'; target: number } | { kind: 'decay' } | null = null
184
+ let animFrame = 0
185
+ let lastTime = 0
186
+ let renderFrame = 0
187
+
188
+ const round = (v: number) => Math.round(v * 100) / 100
115
189
 
116
- const dist = Math.abs(offset)
117
- if (dist < closestDist) { closestDist = dist; closest = i }
190
+ function clampScroll(v: number) {
191
+ return Math.min(Math.max(v, 0), maxScroll.value)
192
+ }
193
+
194
+ function render() {
195
+ const s = strategy.value
196
+ const count = props.items.length
197
+ if (!s.isValid) return
198
+ const size = s.itemMainAxisSize
199
+ const viewport = mainSize.value
200
+ const max = maxScroll.value
201
+ const isHorizontal = horizontal.value
202
+
203
+ const index = nearestIndex(scroll)
204
+ if (index !== currentIndex.value) {
205
+ currentIndex.value = index
206
+ emit('update:modelValue', index)
118
207
  }
119
208
 
120
- maskWidths.value = widths
121
- imgOffsets.value = offsets
209
+ for (let i = 0; i < count; i++) {
210
+ const el = itemEls[i]
211
+ if (!el) continue
212
+ const p = placeItem(s, i, scroll, max)
213
+ const visibleStart = p.offset + p.maskStart
214
+ const visibleEnd = visibleStart + p.maskSize
215
+ el.style.visibility = visibleEnd <= 0 || visibleStart >= viewport ? 'hidden' : ''
216
+ const pos = round(isHorizontal && rtl ? viewport - p.offset - size : p.offset)
217
+ el.style.transform = isHorizontal ? `translate3d(${pos}px, 0, 0)` : `translate3d(0, ${pos}px, 0)`
218
+ const start = round(p.maskStart)
219
+ const end = round(size - p.maskStart - p.maskSize)
220
+ el.style.clipPath = isHorizontal
221
+ ? `inset(0 ${end}px 0 ${start}px round var(--radius-xl))`
222
+ : `inset(${start}px 0 ${end}px 0 round var(--radius-xl))`
223
+ // The current item is in front and the others descend with their distance from it.
224
+ el.style.zIndex = String(count - Math.abs(i - index))
225
+ el.style.setProperty('--m3-carousel-mask-start', `${start}px`)
226
+ el.style.setProperty('--m3-carousel-mask-size', `${round(p.maskSize)}px`)
122
227
 
123
- if (closest !== activeIndex.value) {
124
- activeIndex.value = closest
125
- emit('change', closest)
228
+ // Default label: fades in once the mask is wide enough to show it whole (the Compose
229
+ // FadingHorizontalMultiBrowseCarouselSample formula).
230
+ const label = labelEls[i]
231
+ const labelWidth = labelWidths[i] ?? 0
232
+ if (label && labelWidth > 0) {
233
+ label.style.opacity = String(Math.max(labelWidth - s.maxItemSize + p.maskSize, 0) / labelWidth)
234
+ }
126
235
  }
127
236
  }
128
237
 
129
- // The item element's own width IS the animated mask width — not a fixed-width outer "slot"
130
- // with a shrinking element inside it. That was the first cut of this component, and it was
131
- // wrong: shrinking an inner element while its outer flex-item stayed at the full large width
132
- // just left dead space where the flex item used to be, instead of letting flex naturally close
133
- // the gap by reflowing the next item up against it (exactly what the real component's keyline
134
- // masking achieves, just via a different mechanism — Compose positions items directly from
135
- // keyline offsets rather than relying on flow layout, but the visual result needs to be the same:
136
- // no gaps between items regardless of their current mask size).
137
- function itemStyle(i: number) {
138
- return {
139
- width: `${maskWidths.value[i] ?? targetLarge.value}px`,
140
- height: '100%',
141
- flexShrink: '0',
142
- overflow: 'hidden',
143
- position: 'relative' as const,
238
+ function scheduleRender() {
239
+ if (renderFrame) return
240
+ renderFrame = requestAnimationFrame(() => {
241
+ renderFrame = 0
242
+ render()
243
+ })
244
+ }
245
+
246
+ function stopAnimation() {
247
+ anim = null
248
+ if (animFrame) cancelAnimationFrame(animFrame)
249
+ animFrame = 0
250
+ }
251
+
252
+ function startAnimation(next: NonNullable<typeof anim>) {
253
+ anim = next
254
+ if (animFrame) return
255
+ lastTime = performance.now()
256
+ animFrame = requestAnimationFrame(step)
257
+ }
258
+
259
+ function step(now: number) {
260
+ animFrame = 0
261
+ if (!anim) return
262
+ const dt = Math.min((now - lastTime) / 1000, 1 / 30)
263
+ lastTime = now
264
+
265
+ if (anim.kind === 'spring') {
266
+ const target = anim.target
267
+ // Semi-implicit Euler in fixed substeps, like _useSheetMotion.
268
+ const h = 0.004
269
+ for (let left = dt; left > 0; left -= h) {
270
+ const sub = Math.min(h, left)
271
+ const accel = -SPRING_STIFFNESS * (scroll - target) - 2 * SPRING_DAMPING * Math.sqrt(SPRING_STIFFNESS) * velocity
272
+ velocity += accel * sub
273
+ scroll += velocity * sub
274
+ }
275
+ if (Math.abs(scroll - target) < 0.5 && Math.abs(velocity) < 10) {
276
+ scroll = target
277
+ velocity = 0
278
+ anim = null
279
+ }
280
+ } else {
281
+ velocity *= Math.exp(-FLING_FRICTION * dt)
282
+ const next = clampScroll(scroll + velocity * dt)
283
+ if (next !== scroll + velocity * dt) velocity = 0
284
+ scroll = next
285
+ if (Math.abs(velocity) < 20) {
286
+ velocity = 0
287
+ anim = null
288
+ }
144
289
  }
290
+
291
+ render()
292
+ if (anim) animFrame = requestAnimationFrame(step)
293
+ }
294
+
295
+ function springTo(index: number) {
296
+ const target = snaps.value[clampIndex(index, props.items.length)]
297
+ if (target === undefined) return
298
+ startAnimation({ kind: 'spring', target })
145
299
  }
146
300
 
147
- function imgStyle(i: number) {
148
- return {
149
- width: `${targetLarge.value}px`,
150
- height: '100%',
151
- position: 'absolute' as const,
152
- left: `${imgOffsets.value[i] ?? 0}px`,
153
- top: '0',
301
+ /** A release with `v` px/s along the scroll offset (positive = towards later items). */
302
+ function fling(v: number, startIndex: number) {
303
+ if (resolvedFling.value === 'no-snap') {
304
+ velocity = v
305
+ if (Math.abs(v) >= MIN_FLING_VELOCITY / 4) startAnimation({ kind: 'decay' })
306
+ return
154
307
  }
308
+ velocity = v
309
+ if (resolvedFling.value === 'multi-browse') {
310
+ springTo(nearestIndex(clampScroll(scroll + v / FLING_FRICTION)))
311
+ return
312
+ }
313
+ // single-advance: PagerSnapDistance.atMost(1) from the item the gesture started on.
314
+ let target = nearestIndex(scroll)
315
+ if (Math.abs(v) >= MIN_FLING_VELOCITY) {
316
+ const list = snaps.value
317
+ if (v > 0) {
318
+ const i = list.findIndex((s) => s > scroll + 0.5)
319
+ if (i !== -1) target = i
320
+ } else {
321
+ for (let i = list.length - 1; i >= 0; i--) {
322
+ if (list[i]! < scroll - 0.5) { target = i; break }
323
+ }
324
+ }
325
+ target = Math.min(Math.max(target, startIndex - 1), startIndex + 1)
326
+ }
327
+ springTo(target)
155
328
  }
156
329
 
157
- function scrollToItem(index: number) {
158
- const el = itemEls.value[index]
159
- if (!el || !trackEl.value) return
160
- trackEl.value.scrollTo({ left: el.offsetLeft, behavior: 'smooth' })
330
+ function scrollToItem(index: number, animate = true) {
331
+ const i = clampIndex(index, props.items.length)
332
+ const target = snaps.value[i]
333
+ if (target === undefined) return
334
+ if (animate) {
335
+ springTo(i)
336
+ } else {
337
+ stopAnimation()
338
+ scroll = target
339
+ velocity = 0
340
+ render()
341
+ }
161
342
  }
162
343
 
163
344
  function next() {
164
- const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
165
- scrollToItem(i)
345
+ scrollToItem(currentIndex.value + 1)
166
346
  }
347
+
167
348
  function prev() {
168
- const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
169
- scrollToItem(i)
349
+ scrollToItem(currentIndex.value - 1)
350
+ }
351
+
352
+ // ── Pointer dragging ────────────────────────────────────────────────────────────────────────
353
+
354
+ interface Press {
355
+ id: number
356
+ x: number
357
+ y: number
358
+ base: number
359
+ startScroll: number
360
+ startIndex: number
361
+ slop: number
362
+ active: boolean
363
+ samples: { t: number; s: number }[]
364
+ wasAnimating: boolean
365
+ }
366
+ let press: Press | null = null
367
+ let suppressClick = false
368
+
369
+ function onPointerDown(e: PointerEvent) {
370
+ if (!props.userScrollEnabled || e.button !== 0 || !strategy.value.isValid) return
371
+ if ((e.target as Element).closest('input, textarea, select, [contenteditable]')) return
372
+ const wasAnimating = anim !== null
373
+ stopAnimation()
374
+ press = {
375
+ id: e.pointerId,
376
+ x: e.clientX,
377
+ y: e.clientY,
378
+ base: 0,
379
+ startScroll: scroll,
380
+ startIndex: currentIndex.value,
381
+ slop: e.pointerType === 'touch' ? 8 : 4,
382
+ active: false,
383
+ samples: [],
384
+ wasAnimating,
385
+ }
386
+ window.addEventListener('pointermove', onPointerMove)
387
+ window.addEventListener('pointerup', onPointerUp)
388
+ window.addEventListener('pointercancel', onPointerCancel)
389
+ }
390
+
391
+ function onPointerMove(e: PointerEvent) {
392
+ if (!press || e.pointerId !== press.id) return
393
+ const dx = e.clientX - press.x
394
+ const dy = e.clientY - press.y
395
+ const main = horizontal.value ? dx : dy
396
+ const cross = horizontal.value ? dy : dx
397
+ if (!press.active) {
398
+ if (Math.abs(cross) > press.slop && Math.abs(cross) > Math.abs(main)) {
399
+ endPress()
400
+ return
401
+ }
402
+ if (Math.abs(main) <= press.slop) return
403
+ press.active = true
404
+ press.base = main
405
+ try { rootEl.value?.setPointerCapture(e.pointerId) } catch { /* not capturable */ }
406
+ document.body.style.userSelect = 'none'
407
+ }
408
+ const sign = horizontal.value && rtl ? 1 : -1
409
+ scroll = clampScroll(press.startScroll + sign * (main - press.base))
410
+ const now = performance.now()
411
+ press.samples.push({ t: now, s: scroll })
412
+ while (press.samples.length > 2 && now - press.samples[0]!.t > 100) press.samples.shift()
413
+ scheduleRender()
414
+ }
415
+
416
+ function releaseVelocity(p: Press) {
417
+ const first = p.samples[0]
418
+ const last = p.samples[p.samples.length - 1]
419
+ if (!first || !last || last.t - first.t < 1 || performance.now() - last.t > 80) return 0
420
+ return ((last.s - first.s) / (last.t - first.t)) * 1000
421
+ }
422
+
423
+ function onPointerUp(e: PointerEvent) {
424
+ if (!press || e.pointerId !== press.id) return
425
+ const p = press
426
+ endPress()
427
+ if (p.active) {
428
+ suppressClick = true
429
+ setTimeout(() => (suppressClick = false), 0)
430
+ fling(releaseVelocity(p), p.startIndex)
431
+ } else if (p.wasAnimating) {
432
+ // A tap that caught a moving carousel: settle it instead of leaving it mid-way.
433
+ fling(0, currentIndex.value)
434
+ }
435
+ }
436
+
437
+ function onPointerCancel(e: PointerEvent) {
438
+ if (!press || e.pointerId !== press.id) return
439
+ const p = press
440
+ endPress()
441
+ if (p.active || p.wasAnimating) fling(0, p.startIndex)
442
+ }
443
+
444
+ function endPress() {
445
+ press = null
446
+ document.body.style.userSelect = ''
447
+ window.removeEventListener('pointermove', onPointerMove)
448
+ window.removeEventListener('pointerup', onPointerUp)
449
+ window.removeEventListener('pointercancel', onPointerCancel)
450
+ }
451
+
452
+ function onClickCapture(e: MouseEvent) {
453
+ if (!suppressClick) return
454
+ e.stopPropagation()
455
+ e.preventDefault()
456
+ }
457
+
458
+ function onItemClick(item: T, index: number) {
459
+ emit('itemClick', item, index)
460
+ const s = strategy.value
461
+ if (!s.isValid) return
462
+ const p = placeItem(s, index, scroll, maxScroll.value)
463
+ const start = p.offset + p.maskStart
464
+ const fullyVisible = p.maskSize >= s.itemMainAxisSize - 0.5 && start >= -0.5 && start + p.maskSize <= mainSize.value + 0.5
465
+ if (!fullyVisible) scrollToItem(index)
466
+ }
467
+
468
+ // ── Wheel and keyboard ──────────────────────────────────────────────────────────────────────
469
+
470
+ let wheelTimer: ReturnType<typeof setTimeout> | null = null
471
+
472
+ function onWheel(e: WheelEvent) {
473
+ if (!props.userScrollEnabled || !strategy.value.isValid) return
474
+ let delta = 0
475
+ if (horizontal.value) {
476
+ if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = e.deltaX
477
+ else if (e.shiftKey) delta = e.deltaY
478
+ if (rtl) delta = -delta
479
+ } else {
480
+ delta = e.deltaY
481
+ }
482
+ if (e.deltaMode === 1) delta *= 16
483
+ if (!delta) return
484
+ const next = clampScroll(scroll + delta)
485
+ // At an edge, let the page scroll instead.
486
+ if (next === scroll) return
487
+ e.preventDefault()
488
+ stopAnimation()
489
+ scroll = next
490
+ velocity = 0
491
+ scheduleRender()
492
+ if (wheelTimer) clearTimeout(wheelTimer)
493
+ wheelTimer = setTimeout(() => {
494
+ wheelTimer = null
495
+ if (resolvedFling.value !== 'no-snap') springTo(nearestIndex(scroll))
496
+ }, 120)
170
497
  }
171
498
 
172
499
  function onKeydown(e: KeyboardEvent) {
173
- if (e.key === 'ArrowRight') next()
174
- else if (e.key === 'ArrowLeft') prev()
500
+ const forward = horizontal.value ? (rtl ? 'ArrowLeft' : 'ArrowRight') : 'ArrowDown'
501
+ const backward = horizontal.value ? (rtl ? 'ArrowRight' : 'ArrowLeft') : 'ArrowUp'
502
+ let target: number | null = null
503
+ if (e.key === forward) target = currentIndex.value + 1
504
+ else if (e.key === backward) target = currentIndex.value - 1
505
+ else if (e.key === 'Home') target = 0
506
+ else if (e.key === 'End') target = props.items.length - 1
507
+ if (target === null) return
508
+ e.preventDefault()
509
+ scrollToItem(target)
175
510
  }
176
511
 
177
- let autoTimer: ReturnType<typeof setInterval> | null = null
178
- function startAutoplay() {
179
- stopAutoplay()
180
- if (props.autoplay && props.items.length > 1) autoTimer = setInterval(next, props.interval)
512
+ // ── Measuring and lifecycle ─────────────────────────────────────────────────────────────────
513
+
514
+ function measure() {
515
+ const el = rootEl.value
516
+ if (!el) return
517
+ rtl = getComputedStyle(el).direction === 'rtl'
518
+ mainSize.value = horizontal.value ? el.clientWidth : el.clientHeight
181
519
  }
182
- function stopAutoplay() {
183
- if (autoTimer) { clearInterval(autoTimer); autoTimer = null }
520
+
521
+ function measureLabels() {
522
+ labelWidths = labelEls.map((el) => el?.offsetWidth ?? 0)
184
523
  }
185
524
 
525
+ // Resizes, prop changes and item-count changes rebuild the strategy: keep the current item snapped.
526
+ watch(
527
+ strategy,
528
+ () => {
529
+ stopAnimation()
530
+ velocity = 0
531
+ currentIndex.value = clampIndex(currentIndex.value, props.items.length)
532
+ scroll = resolvedFling.value === 'no-snap' ? clampScroll(scroll) : (snaps.value[currentIndex.value] ?? 0)
533
+ measureLabels()
534
+ render()
535
+ },
536
+ { flush: 'post' },
537
+ )
538
+
539
+ watch(
540
+ () => props.modelValue,
541
+ (v) => {
542
+ if (v !== undefined && v !== currentIndex.value) scrollToItem(v)
543
+ },
544
+ )
545
+
186
546
  let resizeObserver: ResizeObserver | null = null
547
+
187
548
  onMounted(() => {
188
- if (trackEl.value) {
189
- containerWidth.value = trackEl.value.clientWidth
190
- resizeObserver = new ResizeObserver(() => {
191
- if (trackEl.value) containerWidth.value = trackEl.value.clientWidth
192
- updateMasks()
193
- })
194
- resizeObserver.observe(trackEl.value)
195
- }
196
- nextTick(updateMasks)
197
- startAutoplay()
549
+ const el = rootEl.value!
550
+ el.addEventListener('wheel', onWheel, { passive: false })
551
+ resizeObserver = new ResizeObserver(measure)
552
+ resizeObserver.observe(el)
553
+ measure()
554
+ nextTick(() => {
555
+ measureLabels()
556
+ scroll = snaps.value[currentIndex.value] ?? 0
557
+ render()
558
+ })
198
559
  })
560
+
199
561
  onBeforeUnmount(() => {
200
- stopAutoplay()
201
- if (rafId) cancelAnimationFrame(rafId)
562
+ stopAnimation()
563
+ endPress()
564
+ if (renderFrame) cancelAnimationFrame(renderFrame)
565
+ if (wheelTimer) clearTimeout(wheelTimer)
202
566
  resizeObserver?.disconnect()
567
+ rootEl.value?.removeEventListener('wheel', onWheel)
203
568
  })
204
569
 
205
- defineExpose({ next, prev, scrollToItem })
570
+ defineExpose({ scrollToItem, next, prev })
206
571
  </script>
207
572
 
208
573
  <template>
209
574
  <div
210
- class="group relative overflow-hidden"
575
+ ref="rootEl"
576
+ class="m3-carousel relative overflow-hidden outline-none focus-visible:outline-3 focus-visible:outline-offset-2 focus-visible:outline-secondary"
577
+ :class="horizontal ? 'touch-pan-y' : 'touch-pan-x'"
578
+ :style="{ height: resolvedHeight }"
579
+ role="region"
580
+ :aria-roledescription="t.carousel"
581
+ :aria-label="label"
211
582
  tabindex="0"
583
+ @pointerdown="onPointerDown"
584
+ @click.capture="onClickCapture"
585
+ @dragstart.prevent
212
586
  @keydown="onKeydown"
213
- @mouseenter="stopAutoplay"
214
- @mouseleave="startAutoplay"
215
587
  >
216
588
  <div
217
- ref="trackEl"
218
- class="carousel-track flex overflow-x-auto"
219
- :style="{ height, gap: `${itemSpacing}px` }"
220
- @scroll.passive="onScroll"
589
+ v-for="(item, i) in items"
590
+ :key="i"
591
+ :ref="(el) => (itemEls[i] = el as HTMLElement | null)"
592
+ class="absolute left-0 top-0 overflow-hidden bg-surface-container-highest"
593
+ :style="horizontal ? { width: `${itemMainSize}px`, height: '100%' } : { width: '100%', height: `${itemMainSize}px` }"
594
+ role="group"
595
+ :aria-label="itemLabel(i)"
596
+ data-carousel-item
597
+ @click="onItemClick(item, i)"
221
598
  >
222
- <div
223
- v-for="(item, i) in items"
224
- :key="i"
225
- :ref="(el) => setItemRef(el, i)"
226
- class="rounded-2xl"
227
- :style="itemStyle(i)"
228
- >
599
+ <slot name="item" :item="item" :index="i">
229
600
  <img
230
- :src="item.src"
231
- :alt="item.alt ?? item.label ?? ''"
232
- class="pointer-events-none object-cover"
233
- :style="imgStyle(i)"
601
+ :src="(item as CarouselItem).src"
602
+ :alt="(item as CarouselItem).alt ?? (item as CarouselItem).label ?? ''"
603
+ draggable="false"
604
+ class="pointer-events-none size-full select-none object-cover"
234
605
  />
235
- <div
236
- v-if="item.label"
237
- class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-4 pb-3 pt-8"
238
- >
239
- <p class="text-title-medium font-medium text-white">{{ item.label }}</p>
240
- </div>
241
- </div>
606
+ <template v-if="(item as CarouselItem).label">
607
+ <div class="pointer-events-none absolute inset-x-0 bottom-0 h-24 bg-gradient-to-t from-black/60 to-transparent" />
608
+ <span
609
+ :ref="(el) => (labelEls[i] = el as HTMLElement | null)"
610
+ class="pointer-events-none absolute bottom-4 whitespace-nowrap text-title-medium text-white"
611
+ style="inset-inline-start: calc(var(--m3-carousel-mask-start, 0px) + 16px)"
612
+ >{{ (item as CarouselItem).label }}</span>
613
+ </template>
614
+ </slot>
242
615
  </div>
243
-
244
- <template v-if="showArrows && items.length > 1">
245
- <button
246
- type="button"
247
- class="absolute left-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
248
- @click="prev"
249
- >
250
- <MIcon name="chevron_left" :size="24" />
251
- </button>
252
- <button
253
- type="button"
254
- class="absolute right-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
255
- @click="next"
256
- >
257
- <MIcon name="chevron_right" :size="24" />
258
- </button>
259
- </template>
260
616
  </div>
261
617
  </template>
262
-
263
- <style scoped>
264
- .carousel-track {
265
- scroll-snap-type: x mandatory;
266
- -webkit-overflow-scrolling: touch;
267
- scrollbar-width: none;
268
- }
269
- .carousel-track::-webkit-scrollbar {
270
- display: none;
271
- }
272
- .carousel-track > * {
273
- scroll-snap-align: start;
274
- }
275
- </style>