@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.
- package/README.md +25 -5
- package/dist/API.md +3661 -0
- package/dist/MIcon-CaEooCmZ.js.map +1 -1
- package/dist/{MMenuItem-5xojJYAL.js → MTextField-pJU1vFaR.js} +374 -364
- package/dist/MTextField-pJU1vFaR.js.map +1 -0
- package/dist/api.json +1 -0
- package/dist/barcode.js +9 -11
- package/dist/barcode.js.map +1 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MAbsolute.vue.d.ts +12 -0
- package/dist/components/MAlert.vue.d.ts +4 -0
- package/dist/components/MAppBar.vue.d.ts +12 -0
- package/dist/components/MAppLayout.vue.d.ts +2 -0
- package/dist/components/MAspectRatio.vue.d.ts +1 -0
- package/dist/components/MAutocomplete.vue.d.ts +18 -0
- package/dist/components/MAvatar.vue.d.ts +3 -0
- package/dist/components/MBadge.vue.d.ts +6 -0
- package/dist/components/MBar.vue.d.ts +5 -0
- package/dist/components/MBarcode.vue.d.ts +9 -0
- package/dist/components/MBottomSheet.vue.d.ts +3 -0
- package/dist/components/MBox.vue.d.ts +6 -0
- package/dist/components/MBreadcrumbs.vue.d.ts +2 -0
- package/dist/components/MButton.vue.d.ts +14 -4
- package/dist/components/MButtonGroup.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +8 -0
- package/dist/components/MCard.vue.d.ts +17 -0
- package/dist/components/MCarousel.vue.d.ts +61 -36
- package/dist/components/MCenter.vue.d.ts +1 -0
- package/dist/components/MChart.vue.d.ts +7 -0
- package/dist/components/MChatBubble.vue.d.ts +10 -0
- package/dist/components/MCheckbox.vue.d.ts +5 -0
- package/dist/components/MChip.vue.d.ts +9 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +7 -0
- package/dist/components/MCodeEditor.vue.d.ts +9 -0
- package/dist/components/MColorPicker.vue.d.ts +8 -0
- package/dist/components/MColorPickerModal.vue.d.ts +4 -0
- package/dist/components/MCommandPalette.vue.d.ts +8 -0
- package/dist/components/MConfirmDialog.vue.d.ts +7 -0
- package/dist/components/MContainer.vue.d.ts +4 -0
- package/dist/components/MContextMenu.vue.d.ts +3 -6
- package/dist/components/MCopyButton.vue.d.ts +10 -0
- package/dist/components/MDataTable.vue.d.ts +33 -12
- package/dist/components/MDatePicker.vue.d.ts +16 -0
- package/dist/components/MDatePickerModal.vue.d.ts +9 -0
- package/dist/components/MDateRangePicker.vue.d.ts +18 -0
- package/dist/components/MDateRangePickerModal.vue.d.ts +9 -0
- package/dist/components/MDialog.vue.d.ts +10 -6
- package/dist/components/MDivider.vue.d.ts +6 -0
- package/dist/components/MDragDropList.vue.d.ts +6 -0
- package/dist/components/MEmoji.vue.d.ts +6 -0
- package/dist/components/MEmojiButton.vue.d.ts +5 -0
- package/dist/components/MEmojiSelector.vue.d.ts +21 -5
- package/dist/components/MEmptyState.vue.d.ts +4 -0
- package/dist/components/MExpansionPanel.vue.d.ts +9 -0
- package/dist/components/MExportButton.vue.d.ts +8 -0
- package/dist/components/MFab.vue.d.ts +9 -0
- package/dist/components/MFabMenu.vue.d.ts +15 -1
- package/dist/components/MFileUpload.vue.d.ts +8 -0
- package/dist/components/MFixed.vue.d.ts +10 -0
- package/dist/components/MFlex.vue.d.ts +7 -1
- package/dist/components/MFooter.vue.d.ts +11 -0
- package/dist/components/MFullscreen.vue.d.ts +2 -0
- package/dist/components/MGrid.vue.d.ts +7 -0
- package/dist/components/MHotkeys.vue.d.ts +4 -0
- package/dist/components/MIcon.vue.d.ts +2 -0
- package/dist/components/MIconButton.vue.d.ts +10 -0
- package/dist/components/MInfiniteScroll.vue.d.ts +6 -0
- package/dist/components/MJsonEditor.vue.d.ts +8 -0
- package/dist/components/MJsonViewer.vue.d.ts +4 -0
- package/dist/components/MKanban.vue.d.ts +2 -0
- package/dist/components/MKbd.vue.d.ts +2 -0
- package/dist/components/MLightbox.vue.d.ts +19 -5
- package/dist/components/MList.vue.d.ts +7 -0
- package/dist/components/MListItem.vue.d.ts +24 -0
- package/dist/components/MListSubheader.vue.d.ts +6 -0
- package/dist/components/MLoadingIndicator.vue.d.ts +10 -0
- package/dist/components/MLoadingOverlay.vue.d.ts +5 -0
- package/dist/components/MMarkdown.vue.d.ts +3 -0
- package/dist/components/MMaskField.vue.d.ts +15 -0
- package/dist/components/MMasonry.vue.d.ts +5 -0
- package/dist/components/MMenu.vue.d.ts +3 -6
- package/dist/components/MMenuDivider.vue.d.ts +4 -0
- package/dist/components/MMenuItem.vue.d.ts +5 -0
- package/dist/components/MMultiAutocomplete.vue.d.ts +20 -0
- package/dist/components/MMultiSelect.vue.d.ts +21 -0
- package/dist/components/MNavigationBar.vue.d.ts +2 -0
- package/dist/components/MNavigationDrawer.vue.d.ts +11 -0
- package/dist/components/MNavigationRail.vue.d.ts +9 -6
- package/dist/components/MNavigationSuite.vue.d.ts +5 -3
- package/dist/components/MNumberField.vue.d.ts +17 -0
- package/dist/components/MOverlay.vue.d.ts +3 -0
- package/dist/components/MPageProgress.vue.d.ts +3 -0
- package/dist/components/MPagination.vue.d.ts +3 -0
- package/dist/components/MPasswordMeter.vue.d.ts +1 -0
- package/dist/components/MPinInput.vue.d.ts +11 -0
- package/dist/components/MProgressBar.vue.d.ts +6 -0
- package/dist/components/MPullToRefresh.vue.d.ts +8 -0
- package/dist/components/MQRCode.vue.d.ts +6 -0
- package/dist/components/MRadio.vue.d.ts +5 -0
- package/dist/components/MRadioGroup.vue.d.ts +6 -0
- package/dist/components/MRating.vue.d.ts +11 -0
- package/dist/components/MRelativeTime.vue.d.ts +1 -0
- package/dist/components/MResponsive.vue.d.ts +3 -0
- package/dist/components/MResult.vue.d.ts +6 -0
- package/dist/components/MRichTextEditor.vue.d.ts +8 -0
- package/dist/components/MScheduler.vue.d.ts +48 -1
- package/dist/components/MScrollable.vue.d.ts +3 -0
- package/dist/components/MSearchBar.vue.d.ts +6 -0
- package/dist/components/MSection.vue.d.ts +5 -0
- package/dist/components/MSegmentedButton.vue.d.ts +5 -0
- package/dist/components/MSelect.vue.d.ts +17 -0
- package/dist/components/MShader.vue.d.ts +1 -0
- package/dist/components/MShape.vue.d.ts +1 -1
- package/dist/components/MShortNavigationBar.vue.d.ts +8 -9
- package/dist/components/MSideSheet.vue.d.ts +3 -0
- package/dist/components/MSignaturePad.vue.d.ts +7 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +12 -2
- package/dist/components/MSkeleton.vue.d.ts +8 -0
- package/dist/components/MSlider.vue.d.ts +15 -1
- package/dist/components/MSnackbar.vue.d.ts +1 -0
- package/dist/components/MSpinner.vue.d.ts +6 -0
- package/dist/components/MSplitButton.vue.d.ts +7 -0
- package/dist/components/MSplitter.vue.d.ts +4 -0
- package/dist/components/MSpotlightSearch.vue.d.ts +18 -0
- package/dist/components/MStack.vue.d.ts +8 -1
- package/dist/components/MStatCard.vue.d.ts +7 -0
- package/dist/components/MStepper.vue.d.ts +7 -0
- package/dist/components/MSticky.vue.d.ts +2 -0
- package/dist/components/MSubtitle.vue.d.ts +4 -0
- package/dist/components/MSwitch.vue.d.ts +5 -6
- package/dist/components/MTable.vue.d.ts +17 -4
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTagInput.vue.d.ts +17 -0
- package/dist/components/MTerminal.vue.d.ts +4 -0
- package/dist/components/MText.vue.d.ts +10 -0
- package/dist/components/MTextField.vue.d.ts +18 -0
- package/dist/components/MTimePicker.vue.d.ts +10 -0
- package/dist/components/MTimePickerModal.vue.d.ts +5 -0
- package/dist/components/MTimeline.vue.d.ts +3 -0
- package/dist/components/MTitle.vue.d.ts +4 -0
- package/dist/components/MToggleButton.vue.d.ts +4 -0
- package/dist/components/MToolbar.vue.d.ts +6 -1
- package/dist/components/MTooltip.vue.d.ts +7 -0
- package/dist/components/MTopAppBar.vue.d.ts +8 -0
- package/dist/components/MTour.vue.d.ts +5 -0
- package/dist/components/MTransferList.vue.d.ts +11 -0
- package/dist/components/MTree.vue.d.ts +11 -0
- package/dist/components/MTreeTable.vue.d.ts +7 -0
- package/dist/components/MVirtualTable.vue.d.ts +6 -0
- package/dist/components/MWindow.vue.d.ts +33 -1
- package/dist/composables/_carouselStrategy.d.ts +101 -0
- package/dist/composables/useLocale.d.ts +21 -0
- package/dist/data/emoji-names/emoji-names-de.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-en.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-es.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-fr.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-ja.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-ko.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-pt.d.ts +2 -0
- package/dist/data/emoji-names/emoji-names-zh.d.ts +2 -0
- package/dist/data/emojis.d.ts +7 -1
- package/dist/emoji-names-de-BphO5XpV.js +1877 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -0
- package/dist/emoji-names-en-9ZvMRvzi.js +1877 -0
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -0
- package/dist/emoji-names-es-DvfWU3Pj.js +1877 -0
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -0
- package/dist/emoji-names-fr-B-jhUlsP.js +1877 -0
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -0
- package/dist/emoji-names-ja-l8cMFJo1.js +1877 -0
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -0
- package/dist/emoji-names-ko-YP-o9G0c.js +1877 -0
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -0
- package/dist/emoji-names-pt-DGj_Js4M.js +1877 -0
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -0
- package/dist/emoji-names-zh-Dzecwtw_.js +1877 -0
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/locales/index.js +140 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +6642 -5160
- package/dist/m3ui.js.map +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/plugin.d.ts +6 -0
- package/dist/qrcode.js.map +1 -1
- package/dist/rich-text-editor.js +10 -10
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/terminal.js +34 -27
- package/dist/terminal.js.map +1 -1
- package/dist/{useLocale-D3ZWZ8jY.js → useLocale-Drihe5G2.js} +33 -11
- package/dist/useLocale-Drihe5G2.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/MCarousel.test.ts +183 -21
- package/src/__tests__/MDialog.test.ts +18 -0
- package/src/__tests__/MEmojiSelector.test.ts +138 -0
- package/src/__tests__/MHotkeys.test.ts +57 -0
- package/src/__tests__/MLightbox.test.ts +313 -5
- package/src/__tests__/MScheduler.test.ts +122 -0
- package/src/__tests__/MTerminal.test.ts +63 -0
- package/src/__tests__/attrsFallthrough.test.ts +65 -0
- package/src/__tests__/hostLocale.test.ts +57 -0
- package/src/__tests__/plugin.test.ts +28 -1
- package/src/components/MAbsolute.vue +18 -0
- package/src/components/MAlert.vue +12 -0
- package/src/components/MAppBar.vue +12 -0
- package/src/components/MAppLayout.vue +11 -0
- package/src/components/MAspectRatio.vue +6 -0
- package/src/components/MAutocomplete.vue +24 -0
- package/src/components/MAvatar.vue +12 -1
- package/src/components/MBadge.vue +11 -0
- package/src/components/MBar.vue +19 -0
- package/src/components/MBarcode.vue +18 -2
- package/src/components/MBottomSheet.vue +13 -1
- package/src/components/MBox.vue +12 -0
- package/src/components/MBreadcrumbs.vue +7 -0
- package/src/components/MButton.vue +22 -4
- package/src/components/MButtonGroup.vue +13 -0
- package/src/components/MCalendar.vue +14 -0
- package/src/components/MCard.vue +26 -0
- package/src/components/MCarousel.vue +542 -200
- package/src/components/MCenter.vue +6 -0
- package/src/components/MChart.vue +12 -0
- package/src/components/MChatBubble.vue +17 -0
- package/src/components/MCheckbox.vue +11 -0
- package/src/components/MChip.vue +17 -0
- package/src/components/MCircleProgressBar.vue +13 -0
- package/src/components/MCodeEditor.vue +18 -2
- package/src/components/MColorPicker.vue +13 -0
- package/src/components/MColorPickerModal.vue +12 -0
- package/src/components/MCommandPalette.vue +17 -1
- package/src/components/MConfirmDialog.vue +15 -0
- package/src/components/MContainer.vue +9 -0
- package/src/components/MContextMenu.vue +20 -7
- package/src/components/MCopyButton.vue +16 -0
- package/src/components/MDataTable.vue +58 -12
- package/src/components/MDatePicker.vue +21 -0
- package/src/components/MDatePickerModal.vue +17 -1
- package/src/components/MDateRangePicker.vue +23 -0
- package/src/components/MDateRangePickerModal.vue +17 -1
- package/src/components/MDialog.vue +43 -10
- package/src/components/MDivider.vue +6 -0
- package/src/components/MDragDropList.vue +18 -0
- package/src/components/MEmoji.vue +6 -0
- package/src/components/MEmojiButton.vue +11 -0
- package/src/components/MEmojiSelector.vue +486 -78
- package/src/components/MEmptyState.vue +9 -0
- package/src/components/MExpansionPanel.vue +17 -0
- package/src/components/MExportButton.vue +15 -0
- package/src/components/MFab.vue +20 -1
- package/src/components/MFabMenu.vue +20 -0
- package/src/components/MFileUpload.vue +19 -0
- package/src/components/MFixed.vue +16 -0
- package/src/components/MFlex.vue +11 -0
- package/src/components/MFooter.vue +11 -0
- package/src/components/MFullscreen.vue +8 -0
- package/src/components/MGrid.vue +12 -0
- package/src/components/MHotkeys.vue +20 -13
- package/src/components/MIcon.vue +10 -1
- package/src/components/MIconButton.vue +13 -0
- package/src/components/MInfiniteScroll.vue +16 -0
- package/src/components/MJsonEditor.vue +13 -0
- package/src/components/MJsonViewer.vue +7 -0
- package/src/components/MKanban.vue +18 -0
- package/src/components/MKbd.vue +6 -0
- package/src/components/MLightbox.vue +766 -268
- package/src/components/MList.vue +15 -0
- package/src/components/MListDetail.vue +11 -0
- package/src/components/MListItem.vue +37 -0
- package/src/components/MListSubheader.vue +6 -0
- package/src/components/MLoadingIndicator.vue +15 -0
- package/src/components/MLoadingOverlay.vue +18 -1
- package/src/components/MMarkdown.vue +7 -0
- package/src/components/MMaskField.vue +21 -0
- package/src/components/MMasonry.vue +11 -0
- package/src/components/MMenu.vue +19 -7
- package/src/components/MMenuDivider.vue +4 -0
- package/src/components/MMenuItem.vue +16 -0
- package/src/components/MMultiAutocomplete.vue +26 -0
- package/src/components/MMultiSelect.vue +27 -0
- package/src/components/MNavigationBar.vue +7 -0
- package/src/components/MNavigationDrawer.vue +30 -1
- package/src/components/MNavigationRail.vue +27 -6
- package/src/components/MNavigationSuite.vue +20 -3
- package/src/components/MNotificationHost.vue +3 -0
- package/src/components/MNumberField.vue +24 -0
- package/src/components/MOverlay.vue +11 -0
- package/src/components/MPageProgress.vue +7 -0
- package/src/components/MPagination.vue +15 -1
- package/src/components/MPasswordMeter.vue +7 -0
- package/src/components/MPinInput.vue +19 -0
- package/src/components/MProgressBar.vue +9 -0
- package/src/components/MPullToRefresh.vue +17 -0
- package/src/components/MQRCode.vue +12 -0
- package/src/components/MRadio.vue +11 -0
- package/src/components/MRadioGroup.vue +11 -0
- package/src/components/MRating.vue +19 -0
- package/src/components/MRelative.vue +8 -0
- package/src/components/MRelativeTime.vue +6 -0
- package/src/components/MResponsive.vue +9 -0
- package/src/components/MResult.vue +14 -0
- package/src/components/MRichTextEditor.vue +14 -0
- package/src/components/MScheduler.vue +303 -115
- package/src/components/MScrollable.vue +8 -0
- package/src/components/MSearchBar.vue +17 -0
- package/src/components/MSection.vue +13 -0
- package/src/components/MSegmentedButton.vue +10 -0
- package/src/components/MSelect.vue +22 -0
- package/src/components/MShader.vue +13 -0
- package/src/components/MShape.vue +6 -0
- package/src/components/MShortNavigationBar.vue +23 -9
- package/src/components/MSideSheet.vue +14 -1
- package/src/components/MSignaturePad.vue +15 -0
- package/src/components/MSimpleCarousel.vue +18 -0
- package/src/components/MSkeleton.vue +8 -0
- package/src/components/MSlider.vue +21 -0
- package/src/components/MSnackbar.vue +5 -0
- package/src/components/MSpacer.vue +6 -0
- package/src/components/MSpinner.vue +10 -0
- package/src/components/MSplitButton.vue +17 -1
- package/src/components/MSplitter.vue +10 -0
- package/src/components/MSpotlightSearch.vue +28 -1
- package/src/components/MStack.vue +12 -0
- package/src/components/MStatCard.vue +13 -0
- package/src/components/MStepper.vue +12 -0
- package/src/components/MSticky.vue +7 -0
- package/src/components/MSubtitle.vue +9 -0
- package/src/components/MSupportingPane.vue +10 -0
- package/src/components/MSwitch.vue +14 -6
- package/src/components/MTable.vue +33 -4
- package/src/components/MTabs.vue +12 -0
- package/src/components/MTagInput.vue +23 -0
- package/src/components/MTerminal.vue +33 -10
- package/src/components/MText.vue +15 -0
- package/src/components/MTextField.vue +26 -0
- package/src/components/MTimePicker.vue +15 -0
- package/src/components/MTimePickerModal.vue +13 -1
- package/src/components/MTimeline.vue +7 -0
- package/src/components/MTitle.vue +9 -0
- package/src/components/MToggleButton.vue +12 -0
- package/src/components/MToolbar.vue +12 -0
- package/src/components/MTooltip.vue +18 -0
- package/src/components/MTopAppBar.vue +18 -0
- package/src/components/MTour.vue +15 -2
- package/src/components/MTransferList.vue +24 -0
- package/src/components/MTree.vue +11 -0
- package/src/components/MTreeTable.vue +15 -0
- package/src/components/MVirtualTable.vue +12 -0
- package/src/components/MWindow.vue +34 -0
- package/src/composables/_carouselStrategy.ts +712 -0
- package/src/composables/useLocale.ts +54 -3
- package/src/data/emoji-names/emoji-names-de.ts +1875 -0
- package/src/data/emoji-names/emoji-names-en.ts +1875 -0
- package/src/data/emoji-names/emoji-names-es.ts +1875 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1875 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1875 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1875 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1875 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1875 -0
- package/src/data/emojis.ts +29 -198
- package/src/index.ts +2 -2
- package/src/locales/de.ts +19 -0
- package/src/locales/es.ts +19 -0
- package/src/locales/fr.ts +19 -0
- package/src/locales/ja.ts +19 -0
- package/src/locales/ko.ts +19 -0
- package/src/locales/pt.ts +19 -0
- package/src/locales/zh.ts +19 -0
- package/src/plugin.ts +14 -2
- package/dist/MMenuItem-5xojJYAL.js.map +0 -1
- package/dist/useLocale-D3ZWZ8jY.js.map +0 -1
|
@@ -1,275 +1,617 @@
|
|
|
1
|
-
<script
|
|
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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
/**
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
interval?: number
|
|
86
|
+
/** Accessible name of the carousel. */
|
|
87
|
+
label?: string
|
|
44
88
|
}>(),
|
|
45
89
|
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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<{
|
|
100
|
+
const emit = defineEmits<{
|
|
101
|
+
'update:modelValue': [index: number]
|
|
102
|
+
itemClick: [item: T, index: number]
|
|
103
|
+
}>()
|
|
58
104
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const activeIndex = ref(0)
|
|
105
|
+
defineSlots<{
|
|
106
|
+
item?: (scope: { item: T; index: number }) => unknown
|
|
107
|
+
}>()
|
|
63
108
|
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
|
75
|
-
const
|
|
76
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
114
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
165
|
-
scrollToItem(i)
|
|
345
|
+
scrollToItem(currentIndex.value + 1)
|
|
166
346
|
}
|
|
347
|
+
|
|
167
348
|
function prev() {
|
|
168
|
-
|
|
169
|
-
|
|
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
|
-
|
|
174
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
183
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
201
|
-
|
|
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
|
|
570
|
+
defineExpose({ scrollToItem, next, prev })
|
|
206
571
|
</script>
|
|
207
572
|
|
|
208
573
|
<template>
|
|
209
574
|
<div
|
|
210
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
:
|
|
220
|
-
|
|
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
|
-
<
|
|
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
|
-
|
|
233
|
-
|
|
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
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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>
|