akar 2.0.10 → 2.0.12
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/dist/AlertDialog/AlertDialogRoot.cjs +4 -0
- package/dist/AlertDialog/AlertDialogRoot.cjs.map +1 -1
- package/dist/AlertDialog/AlertDialogRoot.js +4 -0
- package/dist/AlertDialog/AlertDialogRoot.js.map +1 -1
- package/dist/Collection/Collection.cjs +2 -1
- package/dist/Collection/Collection.cjs.map +1 -1
- package/dist/Collection/Collection.js +2 -1
- package/dist/Collection/Collection.js.map +1 -1
- package/dist/Combobox/ComboboxContent.cjs +4 -0
- package/dist/Combobox/ComboboxContent.cjs.map +1 -1
- package/dist/Combobox/ComboboxContent.js +4 -0
- package/dist/Combobox/ComboboxContent.js.map +1 -1
- package/dist/Combobox/ComboboxContentImpl.cjs +4 -0
- package/dist/Combobox/ComboboxContentImpl.cjs.map +1 -1
- package/dist/Combobox/ComboboxContentImpl.js +4 -0
- package/dist/Combobox/ComboboxContentImpl.js.map +1 -1
- package/dist/DatePicker/DatePickerContent.cjs +4 -0
- package/dist/DatePicker/DatePickerContent.cjs.map +1 -1
- package/dist/DatePicker/DatePickerContent.js +4 -0
- package/dist/DatePicker/DatePickerContent.js.map +1 -1
- package/dist/DateRangePicker/DateRangePickerContent.cjs +4 -0
- package/dist/DateRangePicker/DateRangePickerContent.cjs.map +1 -1
- package/dist/DateRangePicker/DateRangePickerContent.js +4 -0
- package/dist/DateRangePicker/DateRangePickerContent.js.map +1 -1
- package/dist/Dialog/DialogContent.cjs +14 -9
- package/dist/Dialog/DialogContent.cjs.map +1 -1
- package/dist/Dialog/DialogContent.js +15 -10
- package/dist/Dialog/DialogContent.js.map +1 -1
- package/dist/Dialog/DialogContentImpl.cjs +8 -1
- package/dist/Dialog/DialogContentImpl.cjs.map +1 -1
- package/dist/Dialog/DialogContentImpl.js +8 -1
- package/dist/Dialog/DialogContentImpl.js.map +1 -1
- package/dist/Dialog/DialogContentModal.cjs +20 -3
- package/dist/Dialog/DialogContentModal.cjs.map +1 -1
- package/dist/Dialog/DialogContentModal.js +21 -4
- package/dist/Dialog/DialogContentModal.js.map +1 -1
- package/dist/Dialog/DialogContentNonModal.cjs +18 -2
- package/dist/Dialog/DialogContentNonModal.cjs.map +1 -1
- package/dist/Dialog/DialogContentNonModal.js +19 -3
- package/dist/Dialog/DialogContentNonModal.js.map +1 -1
- package/dist/Dialog/DialogOverlay.cjs +12 -6
- package/dist/Dialog/DialogOverlay.cjs.map +1 -1
- package/dist/Dialog/DialogOverlay.js +13 -7
- package/dist/Dialog/DialogOverlay.js.map +1 -1
- package/dist/Dialog/DialogOverlayImpl.cjs +10 -1
- package/dist/Dialog/DialogOverlayImpl.cjs.map +1 -1
- package/dist/Dialog/DialogOverlayImpl.js +11 -2
- package/dist/Dialog/DialogOverlayImpl.js.map +1 -1
- package/dist/Dialog/DialogRoot.cjs +7 -1
- package/dist/Dialog/DialogRoot.cjs.map +1 -1
- package/dist/Dialog/DialogRoot.js +7 -1
- package/dist/Dialog/DialogRoot.js.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.cjs +20 -4
- package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.js +20 -4
- package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
- package/dist/Drawer/DrawerClose.cjs +48 -0
- package/dist/Drawer/DrawerClose.cjs.map +1 -0
- package/dist/Drawer/DrawerClose.js +42 -0
- package/dist/Drawer/DrawerClose.js.map +1 -0
- package/dist/Drawer/DrawerContent.cjs +139 -0
- package/dist/Drawer/DrawerContent.cjs.map +1 -0
- package/dist/Drawer/DrawerContent.js +133 -0
- package/dist/Drawer/DrawerContent.js.map +1 -0
- package/dist/Drawer/DrawerContentImpl.cjs +298 -0
- package/dist/Drawer/DrawerContentImpl.cjs.map +1 -0
- package/dist/Drawer/DrawerContentImpl.js +292 -0
- package/dist/Drawer/DrawerContentImpl.js.map +1 -0
- package/dist/Drawer/DrawerDescription.cjs +45 -0
- package/dist/Drawer/DrawerDescription.cjs.map +1 -0
- package/dist/Drawer/DrawerDescription.js +39 -0
- package/dist/Drawer/DrawerDescription.js.map +1 -0
- package/dist/Drawer/DrawerHandle.cjs +48 -0
- package/dist/Drawer/DrawerHandle.cjs.map +1 -0
- package/dist/Drawer/DrawerHandle.js +42 -0
- package/dist/Drawer/DrawerHandle.js.map +1 -0
- package/dist/Drawer/DrawerIndent.cjs +78 -0
- package/dist/Drawer/DrawerIndent.cjs.map +1 -0
- package/dist/Drawer/DrawerIndent.js +72 -0
- package/dist/Drawer/DrawerIndent.js.map +1 -0
- package/dist/Drawer/DrawerIndentBackground.cjs +49 -0
- package/dist/Drawer/DrawerIndentBackground.cjs.map +1 -0
- package/dist/Drawer/DrawerIndentBackground.js +43 -0
- package/dist/Drawer/DrawerIndentBackground.js.map +1 -0
- package/dist/Drawer/DrawerOverlay.cjs +66 -0
- package/dist/Drawer/DrawerOverlay.cjs.map +1 -0
- package/dist/Drawer/DrawerOverlay.js +60 -0
- package/dist/Drawer/DrawerOverlay.js.map +1 -0
- package/dist/Drawer/DrawerOverlayImpl.cjs +69 -0
- package/dist/Drawer/DrawerOverlayImpl.cjs.map +1 -0
- package/dist/Drawer/DrawerOverlayImpl.js +63 -0
- package/dist/Drawer/DrawerOverlayImpl.js.map +1 -0
- package/dist/Drawer/DrawerPortal.cjs +47 -0
- package/dist/Drawer/DrawerPortal.cjs.map +1 -0
- package/dist/Drawer/DrawerPortal.js +41 -0
- package/dist/Drawer/DrawerPortal.js.map +1 -0
- package/dist/Drawer/DrawerProvider.cjs +82 -0
- package/dist/Drawer/DrawerProvider.cjs.map +1 -0
- package/dist/Drawer/DrawerProvider.js +70 -0
- package/dist/Drawer/DrawerProvider.js.map +1 -0
- package/dist/Drawer/DrawerRoot.cjs +197 -0
- package/dist/Drawer/DrawerRoot.cjs.map +1 -0
- package/dist/Drawer/DrawerRoot.js +185 -0
- package/dist/Drawer/DrawerRoot.js.map +1 -0
- package/dist/Drawer/DrawerSwipeArea.cjs +87 -0
- package/dist/Drawer/DrawerSwipeArea.cjs.map +1 -0
- package/dist/Drawer/DrawerSwipeArea.js +81 -0
- package/dist/Drawer/DrawerSwipeArea.js.map +1 -0
- package/dist/Drawer/DrawerTitle.cjs +45 -0
- package/dist/Drawer/DrawerTitle.cjs.map +1 -0
- package/dist/Drawer/DrawerTitle.js +39 -0
- package/dist/Drawer/DrawerTitle.js.map +1 -0
- package/dist/Drawer/DrawerTrigger.cjs +64 -0
- package/dist/Drawer/DrawerTrigger.cjs.map +1 -0
- package/dist/Drawer/DrawerTrigger.js +58 -0
- package/dist/Drawer/DrawerTrigger.js.map +1 -0
- package/dist/Drawer/DrawerViewport.cjs +49 -0
- package/dist/Drawer/DrawerViewport.cjs.map +1 -0
- package/dist/Drawer/DrawerViewport.js +43 -0
- package/dist/Drawer/DrawerViewport.js.map +1 -0
- package/dist/Drawer/utils.cjs +185 -0
- package/dist/Drawer/utils.cjs.map +1 -0
- package/dist/Drawer/utils.js +149 -0
- package/dist/Drawer/utils.js.map +1 -0
- package/dist/FocusScope/FocusScope.cjs +31 -11
- package/dist/FocusScope/FocusScope.cjs.map +1 -1
- package/dist/FocusScope/FocusScope.js +32 -12
- package/dist/FocusScope/FocusScope.js.map +1 -1
- package/dist/HoverCard/HoverCardContent.cjs +4 -0
- package/dist/HoverCard/HoverCardContent.cjs.map +1 -1
- package/dist/HoverCard/HoverCardContent.js +4 -0
- package/dist/HoverCard/HoverCardContent.js.map +1 -1
- package/dist/HoverCard/HoverCardContentImpl.cjs +4 -0
- package/dist/HoverCard/HoverCardContentImpl.cjs.map +1 -1
- package/dist/HoverCard/HoverCardContentImpl.js +4 -0
- package/dist/HoverCard/HoverCardContentImpl.js.map +1 -1
- package/dist/Popover/PopoverContent.cjs +4 -0
- package/dist/Popover/PopoverContent.cjs.map +1 -1
- package/dist/Popover/PopoverContent.js +4 -0
- package/dist/Popover/PopoverContent.js.map +1 -1
- package/dist/Popover/PopoverContentImpl.cjs +4 -0
- package/dist/Popover/PopoverContentImpl.cjs.map +1 -1
- package/dist/Popover/PopoverContentImpl.js +4 -0
- package/dist/Popover/PopoverContentImpl.js.map +1 -1
- package/dist/Popover/PopoverContentModal.cjs +4 -0
- package/dist/Popover/PopoverContentModal.cjs.map +1 -1
- package/dist/Popover/PopoverContentModal.js +4 -0
- package/dist/Popover/PopoverContentModal.js.map +1 -1
- package/dist/Popover/PopoverContentNonModal.cjs +4 -0
- package/dist/Popover/PopoverContentNonModal.cjs.map +1 -1
- package/dist/Popover/PopoverContentNonModal.js +4 -0
- package/dist/Popover/PopoverContentNonModal.js.map +1 -1
- package/dist/Popper/PopperContent.cjs +14 -4
- package/dist/Popper/PopperContent.cjs.map +1 -1
- package/dist/Popper/PopperContent.js +14 -4
- package/dist/Popper/PopperContent.js.map +1 -1
- package/dist/Popper/utils.cjs +10 -5
- package/dist/Popper/utils.cjs.map +1 -1
- package/dist/Popper/utils.js +10 -5
- package/dist/Popper/utils.js.map +1 -1
- package/dist/Rating/RatingItem.cjs +66 -0
- package/dist/Rating/RatingItem.cjs.map +1 -0
- package/dist/Rating/RatingItem.js +54 -0
- package/dist/Rating/RatingItem.js.map +1 -0
- package/dist/Rating/RatingItemIndicator.cjs +89 -0
- package/dist/Rating/RatingItemIndicator.cjs.map +1 -0
- package/dist/Rating/RatingItemIndicator.js +83 -0
- package/dist/Rating/RatingItemIndicator.js.map +1 -0
- package/dist/Rating/RatingRoot.cjs +136 -0
- package/dist/Rating/RatingRoot.cjs.map +1 -0
- package/dist/Rating/RatingRoot.js +124 -0
- package/dist/Rating/RatingRoot.js.map +1 -0
- package/dist/Select/SelectContent.cjs +4 -0
- package/dist/Select/SelectContent.cjs.map +1 -1
- package/dist/Select/SelectContent.js +4 -0
- package/dist/Select/SelectContent.js.map +1 -1
- package/dist/Select/SelectContentImpl.cjs +4 -0
- package/dist/Select/SelectContentImpl.cjs.map +1 -1
- package/dist/Select/SelectContentImpl.js +4 -0
- package/dist/Select/SelectContentImpl.js.map +1 -1
- package/dist/Select/SelectPopperPosition.cjs +4 -0
- package/dist/Select/SelectPopperPosition.cjs.map +1 -1
- package/dist/Select/SelectPopperPosition.js +4 -0
- package/dist/Select/SelectPopperPosition.js.map +1 -1
- package/dist/composables/useDrawerSnapPoints.cjs +130 -0
- package/dist/composables/useDrawerSnapPoints.cjs.map +1 -0
- package/dist/composables/useDrawerSnapPoints.js +124 -0
- package/dist/composables/useDrawerSnapPoints.js.map +1 -0
- package/dist/composables/useSwipeDismiss.cjs +401 -0
- package/dist/composables/useSwipeDismiss.cjs.map +1 -0
- package/dist/composables/useSwipeDismiss.js +395 -0
- package/dist/composables/useSwipeDismiss.js.map +1 -0
- package/dist/constant/components.cjs +20 -0
- package/dist/constant/components.cjs.map +1 -1
- package/dist/constant/components.js +20 -0
- package/dist/constant/components.js.map +1 -1
- package/dist/constant.d.cts +2 -0
- package/dist/constant.d.cts.map +1 -1
- package/dist/constant.d.ts +2 -0
- package/dist/constant.d.ts.map +1 -1
- package/dist/index.cjs +44 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +23 -2
- package/dist/index2.d.cts.map +1 -1
- package/dist/index3.d.cts +5 -9
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +1 -5
- package/dist/index3.d.ts.map +1 -1
- package/dist/index4.d.cts +1647 -1216
- package/dist/index4.d.cts.map +1 -1
- package/dist/index4.d.ts +1635 -1204
- package/dist/index4.d.ts.map +1 -1
- package/dist/internal.cjs +0 -1
- package/dist/internal.d.cts +3 -3
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +3 -3
- package/dist/internal.js +0 -1
- package/dist/namespaced/index.cjs +22 -0
- package/dist/namespaced/index.d.cts +22 -2
- package/dist/namespaced/index.d.mts +22 -2
- package/dist/namespaced/index.mjs +22 -2
- package/dist/nuxt/index.d.cts +2 -1
- package/dist/nuxt/index.d.mts +2 -1
- package/dist/resolver/index.d.cts +2 -1
- package/dist/resolver/index.d.mts +2 -1
- package/dist/shared/useSize.cjs +6 -2
- package/dist/shared/useSize.cjs.map +1 -1
- package/dist/shared/useSize.js +7 -3
- package/dist/shared/useSize.js.map +1 -1
- package/dist/shared.cjs +0 -2
- package/dist/shared.d.cts +2 -2
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +1 -2
- package/dist/utils/style.cjs +1 -1
- package/dist/utils/style.cjs.map +1 -1
- package/dist/utils/style.js +1 -1
- package/dist/utils/style.js.map +1 -1
- package/package.json +1 -1
- package/src/Collection/Collection.ts +2 -1
- package/src/Dialog/DialogContent.vue +9 -1
- package/src/Dialog/DialogContentImpl.vue +9 -2
- package/src/Dialog/DialogContentModal.vue +21 -3
- package/src/Dialog/DialogContentNonModal.vue +22 -3
- package/src/Dialog/DialogOverlay.vue +4 -0
- package/src/Dialog/DialogOverlayImpl.vue +8 -2
- package/src/Dialog/DialogRoot.vue +10 -1
- package/src/DismissableLayer/DismissableLayer.vue +44 -8
- package/src/Drawer/DrawerClose.vue +25 -0
- package/src/Drawer/DrawerContent.vue +102 -0
- package/src/Drawer/DrawerContentImpl.vue +395 -0
- package/src/Drawer/DrawerDescription.vue +24 -0
- package/src/Drawer/DrawerHandle.vue +25 -0
- package/src/Drawer/DrawerIndent.vue +64 -0
- package/src/Drawer/DrawerIndentBackground.vue +26 -0
- package/src/Drawer/DrawerOverlay.vue +42 -0
- package/src/Drawer/DrawerOverlayImpl.vue +55 -0
- package/src/Drawer/DrawerPortal.vue +17 -0
- package/src/Drawer/DrawerProvider.vue +95 -0
- package/src/Drawer/DrawerRoot.vue +252 -0
- package/src/Drawer/DrawerSwipeArea.vue +74 -0
- package/src/Drawer/DrawerTitle.vue +24 -0
- package/src/Drawer/DrawerTrigger.vue +45 -0
- package/src/Drawer/DrawerViewport.vue +34 -0
- package/src/Drawer/composables/useDrawerSnapPoints.ts +207 -0
- package/src/Drawer/composables/useSwipeDismiss.ts +586 -0
- package/src/Drawer/index.ts +74 -0
- package/src/Drawer/utils.ts +205 -0
- package/src/FocusScope/FocusScope.vue +82 -20
- package/src/Popper/PopperContent.vue +11 -3
- package/src/Popper/utils.ts +21 -11
- package/src/Rating/RatingItem.vue +1 -0
- package/src/Rating/RatingItemIndicator.vue +3 -2
- package/src/Rating/RatingRoot.vue +6 -2
- package/src/Rating/index.ts +3 -3
- package/src/Splitter/utils/style.ts +1 -1
- package/src/Tree/TreeRoot.vue +2 -2
- package/src/index.ts +2 -0
- package/src/shared/index.ts +0 -1
- package/src/shared/useEmitAsProps.test-d.ts +0 -1
- package/src/shared/useSize.ts +9 -4
- package/dist/shared/trap-focus.cjs +0 -35
- package/dist/shared/trap-focus.cjs.map +0 -1
- package/dist/shared/trap-focus.js +0 -30
- package/dist/shared/trap-focus.js.map +0 -1
- package/src/shared/trap-focus.ts +0 -44
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import type { MaybeRef, Ref } from 'vue';
|
|
2
|
+
import type { SwipeDirection } from '../utils';
|
|
3
|
+
import { useEventListener } from '@vueuse/core';
|
|
4
|
+
import { computed, onUnmounted, ref, toValue, watch } from 'vue';
|
|
5
|
+
import { getDisplacement, getElementTransform } from '../utils';
|
|
6
|
+
|
|
7
|
+
export interface SwipeProgressDetails {
|
|
8
|
+
deltaX: number;
|
|
9
|
+
deltaY: number;
|
|
10
|
+
direction: SwipeDirection | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UseSwipeDismissOptions {
|
|
14
|
+
enabled: MaybeRef<boolean>;
|
|
15
|
+
elementRef: Ref<HTMLElement | null | undefined>;
|
|
16
|
+
directions: MaybeRef<Array<SwipeDirection>>;
|
|
17
|
+
movementCssVars: { x: string; y: string };
|
|
18
|
+
swipeThreshold?: number | ((opts: { element: HTMLElement; direction: SwipeDirection }) => number);
|
|
19
|
+
ignoreScrollableAncestors?: boolean;
|
|
20
|
+
canStart?: () => boolean;
|
|
21
|
+
onDismiss?: () => void;
|
|
22
|
+
onProgress?: (progress: number, details?: SwipeProgressDetails) => void;
|
|
23
|
+
onCancel?: () => void;
|
|
24
|
+
onSwipeStart?: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Fired on release with the measured velocity vector. Return `true` to signal
|
|
27
|
+
* that the callback fully owns the open/close + transform outcome (e.g. the
|
|
28
|
+
* snap-point release math), so `finishSwipe` skips its own dismiss-vs-cancel
|
|
29
|
+
* decision (no `data-swipe-dismissed`, no `onDismiss`/`onCancel`).
|
|
30
|
+
*/
|
|
31
|
+
onRelease?: (velocity: { x: number; y: number }) => boolean | void;
|
|
32
|
+
onSwipingChange?: (swiping: boolean) => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DEFAULT_SWIPE_THRESHOLD = 40;
|
|
36
|
+
const REVERSE_CANCEL_THRESHOLD = 10;
|
|
37
|
+
const MIN_DRAG_THRESHOLD = 1;
|
|
38
|
+
const MIN_RELEASE_VELOCITY_DURATION_MS = 16;
|
|
39
|
+
const MAX_RELEASE_VELOCITY_AGE_MS = 80;
|
|
40
|
+
const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
|
|
41
|
+
|
|
42
|
+
function findScrollableAncestor(
|
|
43
|
+
el: Element | null,
|
|
44
|
+
axis: 'vertical' | 'horizontal',
|
|
45
|
+
): HTMLElement | null {
|
|
46
|
+
if (!el || el === document.body) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const style = window.getComputedStyle(el as HTMLElement);
|
|
50
|
+
const overflow = axis === 'vertical'
|
|
51
|
+
? style.overflowY
|
|
52
|
+
: style.overflowX;
|
|
53
|
+
if (
|
|
54
|
+
(overflow === 'auto' || overflow === 'scroll')
|
|
55
|
+
&& (axis === 'vertical'
|
|
56
|
+
? (el as HTMLElement).scrollHeight > (el as HTMLElement).clientHeight
|
|
57
|
+
: (el as HTMLElement).scrollWidth > (el as HTMLElement).clientWidth)
|
|
58
|
+
) {
|
|
59
|
+
return el as HTMLElement;
|
|
60
|
+
}
|
|
61
|
+
return findScrollableAncestor(el.parentElement, axis);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns whether the user can start a swipe dismiss from a scrollable element
|
|
66
|
+
* based on the scroll position and drag direction.
|
|
67
|
+
* Ported from BaseUI `useSwipeDismiss.ts:canSwipeFromScrollEdgeOnPendingMove`.
|
|
68
|
+
*
|
|
69
|
+
* Returns:
|
|
70
|
+
* true → swipe is allowed (scroll is at the relevant edge)
|
|
71
|
+
* false → swipe is blocked (user is scrolling, not dismissing)
|
|
72
|
+
* null → the drag is not along a recognized axis; caller should fall through
|
|
73
|
+
*/
|
|
74
|
+
function canSwipeFromScrollEdge(
|
|
75
|
+
scrollTarget: HTMLElement,
|
|
76
|
+
deltaX: number,
|
|
77
|
+
deltaY: number,
|
|
78
|
+
flags: { hasVertical: boolean; hasHorizontal: boolean; allowUp: boolean; allowDown: boolean; allowLeft: boolean; allowRight: boolean },
|
|
79
|
+
): boolean | null {
|
|
80
|
+
const absDx = Math.abs(deltaX);
|
|
81
|
+
const absDy = Math.abs(deltaY);
|
|
82
|
+
const useVerticalAxis
|
|
83
|
+
= flags.hasVertical && deltaY !== 0 && (!flags.hasHorizontal || absDy >= absDx);
|
|
84
|
+
|
|
85
|
+
if (useVerticalAxis) {
|
|
86
|
+
const maxScrollTop = Math.max(0, scrollTarget.scrollHeight - scrollTarget.clientHeight);
|
|
87
|
+
const atTop = scrollTarget.scrollTop <= 0;
|
|
88
|
+
const atBottom = scrollTarget.scrollTop >= maxScrollTop;
|
|
89
|
+
const movingDown = deltaY > 0;
|
|
90
|
+
const movingUp = deltaY < 0;
|
|
91
|
+
// A 'down'-dismiss drawer starts dismiss on a downward pull from the top.
|
|
92
|
+
// An 'up'-dismiss drawer starts dismiss on an upward pull from the bottom.
|
|
93
|
+
const canSwipeDown = movingDown && atTop && flags.allowDown;
|
|
94
|
+
const canSwipeUp = movingUp && atBottom && flags.allowUp;
|
|
95
|
+
return canSwipeDown || canSwipeUp;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const useHorizontalAxis
|
|
99
|
+
= flags.hasHorizontal && deltaX !== 0 && (!flags.hasVertical || absDx > absDy);
|
|
100
|
+
if (useHorizontalAxis) {
|
|
101
|
+
const maxScrollLeft = Math.max(0, scrollTarget.scrollWidth - scrollTarget.clientWidth);
|
|
102
|
+
const atLeft = scrollTarget.scrollLeft <= 0;
|
|
103
|
+
const atRight = scrollTarget.scrollLeft >= maxScrollLeft;
|
|
104
|
+
const movingRight = deltaX > 0;
|
|
105
|
+
const movingLeft = deltaX < 0;
|
|
106
|
+
const canSwipeRight = movingRight && atLeft && flags.allowRight;
|
|
107
|
+
const canSwipeLeft = movingLeft && atRight && flags.allowLeft;
|
|
108
|
+
return canSwipeRight || canSwipeLeft;
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
114
|
+
const {
|
|
115
|
+
elementRef,
|
|
116
|
+
directions,
|
|
117
|
+
movementCssVars,
|
|
118
|
+
swipeThreshold: swipeThresholdProp,
|
|
119
|
+
canStart,
|
|
120
|
+
onDismiss,
|
|
121
|
+
onProgress,
|
|
122
|
+
onCancel,
|
|
123
|
+
onSwipeStart,
|
|
124
|
+
onRelease,
|
|
125
|
+
onSwipingChange,
|
|
126
|
+
} = options;
|
|
127
|
+
|
|
128
|
+
const hasVertical = computed(() => toValue(directions).includes('up') || toValue(directions).includes('down'));
|
|
129
|
+
const hasHorizontal = computed(() => toValue(directions).includes('left') || toValue(directions).includes('right'));
|
|
130
|
+
const allowUp = computed(() => toValue(directions).includes('up'));
|
|
131
|
+
const allowDown = computed(() => toValue(directions).includes('down'));
|
|
132
|
+
const allowLeft = computed(() => toValue(directions).includes('left'));
|
|
133
|
+
const allowRight = computed(() => toValue(directions).includes('right'));
|
|
134
|
+
|
|
135
|
+
const isSwiping = ref(false);
|
|
136
|
+
const swipeDirection = ref<SwipeDirection | undefined>(undefined);
|
|
137
|
+
const dragOffset = ref({ x: 0, y: 0 });
|
|
138
|
+
|
|
139
|
+
// Internal state (not reactive -- use plain vars for perf)
|
|
140
|
+
let dragStartPos = { x: 0, y: 0 };
|
|
141
|
+
let intendedDirection: SwipeDirection | undefined;
|
|
142
|
+
let maxDisplacement = 0;
|
|
143
|
+
let cancelledSwipe = false;
|
|
144
|
+
let isFirstMove = false;
|
|
145
|
+
let pendingSwipe = false;
|
|
146
|
+
let pendingSwipeStartPos: { x: number; y: number } | null = null;
|
|
147
|
+
let swipeFromScrollable = false;
|
|
148
|
+
let scrollableAncestor: HTMLElement | null = null;
|
|
149
|
+
let elementSize = { width: 0, height: 0 };
|
|
150
|
+
let swipeProgress = 0;
|
|
151
|
+
let lastDragSample: { x: number; y: number; time: number } | null = null;
|
|
152
|
+
let lastVelocity = { x: 0, y: 0 };
|
|
153
|
+
let lockedAxis: 'horizontal' | 'vertical' | null = null;
|
|
154
|
+
let activePointerId: number | null = null;
|
|
155
|
+
let pointerStarted = false;
|
|
156
|
+
|
|
157
|
+
function getThreshold(el: HTMLElement, dir: SwipeDirection): number {
|
|
158
|
+
if (typeof swipeThresholdProp === 'function') {
|
|
159
|
+
return Math.max(0, swipeThresholdProp({ element: el, direction: dir }));
|
|
160
|
+
}
|
|
161
|
+
return typeof swipeThresholdProp === 'number' ? swipeThresholdProp : DEFAULT_SWIPE_THRESHOLD;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function setSwiping(next: boolean) {
|
|
165
|
+
if (isSwiping.value === next) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
isSwiping.value = next;
|
|
169
|
+
onSwipingChange?.(next);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function recordSample(offset: { x: number; y: number }, time: number) {
|
|
173
|
+
if (lastDragSample && time > lastDragSample.time) {
|
|
174
|
+
const dt = Math.max(time - lastDragSample.time, MIN_RELEASE_VELOCITY_DURATION_MS);
|
|
175
|
+
lastVelocity = {
|
|
176
|
+
x: (offset.x - lastDragSample.x) / dt,
|
|
177
|
+
y: (offset.y - lastDragSample.y) / dt,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
lastDragSample = { x: offset.x, y: offset.y, time };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function setCssVars(el: HTMLElement, x: number, y: number) {
|
|
184
|
+
el.style.setProperty(movementCssVars.x, `${x}px`);
|
|
185
|
+
el.style.setProperty(movementCssVars.y, `${y}px`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function clearCssVars(el: HTMLElement) {
|
|
189
|
+
el.style.setProperty(movementCssVars.x, '0px');
|
|
190
|
+
el.style.setProperty(movementCssVars.y, '0px');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function reset() {
|
|
194
|
+
setSwiping(false);
|
|
195
|
+
swipeDirection.value = undefined;
|
|
196
|
+
dragOffset.value = { x: 0, y: 0 };
|
|
197
|
+
dragStartPos = { x: 0, y: 0 };
|
|
198
|
+
intendedDirection = undefined;
|
|
199
|
+
maxDisplacement = 0;
|
|
200
|
+
cancelledSwipe = false;
|
|
201
|
+
isFirstMove = false;
|
|
202
|
+
pendingSwipe = false;
|
|
203
|
+
pendingSwipeStartPos = null;
|
|
204
|
+
swipeFromScrollable = false;
|
|
205
|
+
scrollableAncestor = null;
|
|
206
|
+
elementSize = { width: 0, height: 0 };
|
|
207
|
+
swipeProgress = 0;
|
|
208
|
+
lastDragSample = null;
|
|
209
|
+
lastVelocity = { x: 0, y: 0 };
|
|
210
|
+
lockedAxis = null;
|
|
211
|
+
activePointerId = null;
|
|
212
|
+
pointerStarted = false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function startSwipe(el: HTMLElement, pos: { x: number; y: number }) {
|
|
216
|
+
// Capture the element's current transform so we can account for it
|
|
217
|
+
getElementTransform(el);
|
|
218
|
+
dragStartPos = pos;
|
|
219
|
+
pendingSwipeStartPos = pos;
|
|
220
|
+
elementSize = { width: el.offsetWidth, height: el.offsetHeight };
|
|
221
|
+
isFirstMove = true;
|
|
222
|
+
pendingSwipe = true;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Applies sqrt-damping to any axis moving in a disallowed direction.
|
|
227
|
+
* Axes moving in an allowed direction pass through linearly.
|
|
228
|
+
* Ported from BaseUI `useSwipeDismiss.ts:applyDirectionalDamping`.
|
|
229
|
+
*/
|
|
230
|
+
function applyDirectionalDamping(deltaX: number, deltaY: number) {
|
|
231
|
+
const exponent = (value: number) => (value >= 0 ? value ** 0.5 : -((Math.abs(value)) ** 0.5));
|
|
232
|
+
const dampAxis = (delta: number, allowNegative: boolean, allowPositive: boolean) => {
|
|
233
|
+
if (!allowNegative && delta < 0) {
|
|
234
|
+
return exponent(delta);
|
|
235
|
+
}
|
|
236
|
+
if (!allowPositive && delta > 0) {
|
|
237
|
+
return exponent(delta);
|
|
238
|
+
}
|
|
239
|
+
return delta;
|
|
240
|
+
};
|
|
241
|
+
const newDx = hasHorizontal.value
|
|
242
|
+
? dampAxis(deltaX, allowLeft.value, allowRight.value)
|
|
243
|
+
: exponent(deltaX);
|
|
244
|
+
const newDy = hasVertical.value
|
|
245
|
+
? dampAxis(deltaY, allowUp.value, allowDown.value)
|
|
246
|
+
: exponent(deltaY);
|
|
247
|
+
return { x: newDx, y: newDy };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function processMove(el: HTMLElement, pos: { x: number; y: number }, time: number) {
|
|
251
|
+
const rawDx = pos.x - dragStartPos.x;
|
|
252
|
+
const rawDy = pos.y - dragStartPos.y;
|
|
253
|
+
|
|
254
|
+
// Determine direction lock on first move
|
|
255
|
+
if (isFirstMove) {
|
|
256
|
+
isFirstMove = false;
|
|
257
|
+
const absX = Math.abs(rawDx);
|
|
258
|
+
const absY = Math.abs(rawDy);
|
|
259
|
+
if (hasVertical.value && hasHorizontal.value) {
|
|
260
|
+
lockedAxis = absX > absY ? 'horizontal' : 'vertical';
|
|
261
|
+
} else if (hasVertical.value) {
|
|
262
|
+
lockedAxis = 'vertical';
|
|
263
|
+
} else {
|
|
264
|
+
lockedAxis = 'horizontal';
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Axis-locked deltas for direction detection
|
|
269
|
+
const dx = lockedAxis === 'vertical' ? 0 : rawDx;
|
|
270
|
+
const dy = lockedAxis === 'horizontal' ? 0 : rawDy;
|
|
271
|
+
|
|
272
|
+
const dir: SwipeDirection | undefined = toValue(directions).find((d) => getDisplacement(d, dx, dy) > 0);
|
|
273
|
+
|
|
274
|
+
if (pendingSwipe && pendingSwipeStartPos) {
|
|
275
|
+
// Only promote to an active swipe when we've identified an allowed
|
|
276
|
+
// direction. If the user is dragging against the dismiss direction
|
|
277
|
+
// (dir === undefined), bail out so we don't steal scroll/drag from
|
|
278
|
+
// one-direction drawers.
|
|
279
|
+
if (!dir) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const pending = getDisplacement(
|
|
283
|
+
dir,
|
|
284
|
+
pos.x - pendingSwipeStartPos.x,
|
|
285
|
+
pos.y - pendingSwipeStartPos.y,
|
|
286
|
+
);
|
|
287
|
+
if (Math.abs(pending) < MIN_DRAG_THRESHOLD) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
pendingSwipe = false;
|
|
291
|
+
intendedDirection = dir;
|
|
292
|
+
swipeDirection.value = dir;
|
|
293
|
+
setSwiping(true);
|
|
294
|
+
onSwipeStart?.();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!isSwiping.value) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const currentDir = intendedDirection ?? toValue(directions)[0];
|
|
302
|
+
const displacement = getDisplacement(currentDir, dx, dy);
|
|
303
|
+
|
|
304
|
+
// Detect reversal (cancel swipe)
|
|
305
|
+
if (!cancelledSwipe) {
|
|
306
|
+
maxDisplacement = Math.max(maxDisplacement, displacement);
|
|
307
|
+
if (
|
|
308
|
+
maxDisplacement > DEFAULT_SWIPE_THRESHOLD / 2
|
|
309
|
+
&& maxDisplacement - displacement > REVERSE_CANCEL_THRESHOLD
|
|
310
|
+
) {
|
|
311
|
+
cancelledSwipe = true;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Apply directional damping to raw deltas (BaseUI parity).
|
|
316
|
+
// Allowed-direction axes pass through linearly; disallowed directions
|
|
317
|
+
// sqrt-damp. No manual single-axis sign reconstruction.
|
|
318
|
+
const damped = applyDirectionalDamping(dx, dy);
|
|
319
|
+
|
|
320
|
+
dragOffset.value = { x: damped.x, y: damped.y };
|
|
321
|
+
setCssVars(el, damped.x, damped.y);
|
|
322
|
+
recordSample({ x: damped.x, y: damped.y }, time);
|
|
323
|
+
|
|
324
|
+
// Progress: 0 = closed/start, 1 = fully dismissed
|
|
325
|
+
const currentEl = elementRef.value;
|
|
326
|
+
if (currentEl) {
|
|
327
|
+
const dim = (currentDir === 'up' || currentDir === 'down')
|
|
328
|
+
? elementSize.height || currentEl.offsetHeight
|
|
329
|
+
: elementSize.width || currentEl.offsetWidth;
|
|
330
|
+
const threshold = getThreshold(currentEl, currentDir);
|
|
331
|
+
const p = Math.min(1, Math.max(0, displacement / (dim + threshold)));
|
|
332
|
+
if (p !== swipeProgress) {
|
|
333
|
+
swipeProgress = p;
|
|
334
|
+
onProgress?.(p, { deltaX: damped.x, deltaY: damped.y, direction: currentDir });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function finishSwipe(el: HTMLElement) {
|
|
340
|
+
if (!isSwiping.value) {
|
|
341
|
+
reset();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const displacement = getDisplacement(
|
|
346
|
+
intendedDirection ?? toValue(directions)[0],
|
|
347
|
+
dragOffset.value.x,
|
|
348
|
+
dragOffset.value.y,
|
|
349
|
+
);
|
|
350
|
+
const threshold = getThreshold(el, intendedDirection ?? toValue(directions)[0]);
|
|
351
|
+
|
|
352
|
+
const now = performance.now();
|
|
353
|
+
const velAge = lastDragSample ? now - lastDragSample.time : Infinity;
|
|
354
|
+
const velocity = velAge > MAX_RELEASE_VELOCITY_AGE_MS ? { x: 0, y: 0 } : lastVelocity;
|
|
355
|
+
|
|
356
|
+
// When onRelease returns true (snap-point release), it owns the open/close
|
|
357
|
+
// and transform outcome — don't run the dismiss-vs-cancel branch, which
|
|
358
|
+
// would otherwise set a stray `data-swipe-dismissed` on a drawer that
|
|
359
|
+
// actually snapped to a point, or clear CSS vars onRelease already wrote.
|
|
360
|
+
const releaseHandled = onRelease?.(velocity) === true;
|
|
361
|
+
|
|
362
|
+
if (!releaseHandled) {
|
|
363
|
+
const velInDirection = getDisplacement(
|
|
364
|
+
intendedDirection ?? toValue(directions)[0],
|
|
365
|
+
velocity.x,
|
|
366
|
+
velocity.y,
|
|
367
|
+
);
|
|
368
|
+
const shouldDismiss = !cancelledSwipe
|
|
369
|
+
&& (displacement >= threshold || velInDirection > 0.3);
|
|
370
|
+
|
|
371
|
+
if (shouldDismiss) {
|
|
372
|
+
// BaseUI parity: on dismiss, keep the drag transform in place so the
|
|
373
|
+
// close animation runs smoothly from the dragged position. Clearing the
|
|
374
|
+
// CSS vars here would cause a one-frame snap-back to resting before the
|
|
375
|
+
// closing transition begins (visible as a flicker).
|
|
376
|
+
el.setAttribute('data-swipe-dismissed', '');
|
|
377
|
+
onDismiss?.();
|
|
378
|
+
} else {
|
|
379
|
+
// On cancel, reset the drag transform so the drawer animates back to rest.
|
|
380
|
+
clearCssVars(el);
|
|
381
|
+
onCancel?.();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
reset();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// -- Pointer Events (mouse + pen) --
|
|
389
|
+
|
|
390
|
+
function onPointerDown(e: PointerEvent) {
|
|
391
|
+
if (!toValue(options.enabled)) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (e.pointerType === 'touch') {
|
|
395
|
+
return;
|
|
396
|
+
} // handled by touch events
|
|
397
|
+
if (e.button !== 0) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (canStart && !canStart()) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const target = e.target as HTMLElement;
|
|
405
|
+
if (target?.closest(DEFAULT_IGNORE_SELECTOR)) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const el = elementRef.value;
|
|
410
|
+
if (!el) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
startSwipe(el, { x: e.clientX, y: e.clientY });
|
|
415
|
+
activePointerId = e.pointerId;
|
|
416
|
+
pointerStarted = true;
|
|
417
|
+
try {
|
|
418
|
+
el.setPointerCapture(e.pointerId);
|
|
419
|
+
} catch {}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function onPointerMove(e: PointerEvent) {
|
|
423
|
+
if (!pointerStarted || e.pointerId !== activePointerId) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const el = elementRef.value;
|
|
427
|
+
if (!el) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if ((e.buttons & 1) === 0) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
processMove(el, { x: e.clientX, y: e.clientY }, e.timeStamp);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function onPointerUp(e: PointerEvent) {
|
|
437
|
+
if (!pointerStarted || e.pointerId !== activePointerId) {
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const el = elementRef.value;
|
|
441
|
+
if (!el) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
finishSwipe(el);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// -- Touch Events (mobile) --
|
|
448
|
+
|
|
449
|
+
function onTouchStart(e: TouchEvent) {
|
|
450
|
+
if (!toValue(options.enabled)) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
if (canStart && !canStart()) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const target = e.target as HTMLElement;
|
|
458
|
+
if (target?.closest(DEFAULT_IGNORE_SELECTOR)) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
const el = elementRef.value;
|
|
463
|
+
if (!el) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (!options.ignoreScrollableAncestors) {
|
|
468
|
+
const axis = hasVertical.value ? 'vertical' : 'horizontal';
|
|
469
|
+
const scrollable = findScrollableAncestor(target, axis);
|
|
470
|
+
if (scrollable) {
|
|
471
|
+
swipeFromScrollable = true;
|
|
472
|
+
scrollableAncestor = scrollable;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const t = e.touches[0];
|
|
477
|
+
if (!t) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
startSwipe(el, { x: t.clientX, y: t.clientY });
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function onTouchMove(e: TouchEvent) {
|
|
484
|
+
const el = elementRef.value;
|
|
485
|
+
if (!el || (!pendingSwipe && !isSwiping.value)) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const t = e.touches[0];
|
|
490
|
+
if (!t) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const pos = { x: t.clientX, y: t.clientY };
|
|
495
|
+
|
|
496
|
+
if (swipeFromScrollable && pendingSwipe && scrollableAncestor) {
|
|
497
|
+
const dx = pos.x - dragStartPos.x;
|
|
498
|
+
const dy = pos.y - dragStartPos.y;
|
|
499
|
+
// BaseUI-style scroll-edge allowance: only cancel if the user is genuinely
|
|
500
|
+
// scrolling (not at the edge in the dismiss direction). If they are at the
|
|
501
|
+
// relevant edge, let the swipe proceed.
|
|
502
|
+
const allowed = canSwipeFromScrollEdge(scrollableAncestor, dx, dy, {
|
|
503
|
+
hasVertical: hasVertical.value,
|
|
504
|
+
hasHorizontal: hasHorizontal.value,
|
|
505
|
+
allowUp: allowUp.value,
|
|
506
|
+
allowDown: allowDown.value,
|
|
507
|
+
allowLeft: allowLeft.value,
|
|
508
|
+
allowRight: allowRight.value,
|
|
509
|
+
});
|
|
510
|
+
if (allowed === false) {
|
|
511
|
+
reset();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (allowed === true) {
|
|
515
|
+
// Scroll edge reached in the swipe direction → clear the guard so
|
|
516
|
+
// subsequent moves go through the normal swipe path.
|
|
517
|
+
swipeFromScrollable = false;
|
|
518
|
+
scrollableAncestor = null;
|
|
519
|
+
}
|
|
520
|
+
// allowed === null → axis unclear, fall through to processMove which
|
|
521
|
+
// will lock the axis and retry the decision on the next frame.
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Capture swiping state BEFORE processMove — that function is what sets
|
|
525
|
+
// isSwiping.value = true on the move that crosses the drag threshold, so
|
|
526
|
+
// we need to preventDefault on that same event (not the next one) to avoid
|
|
527
|
+
// a visible scroll hitch on the first frame of the gesture on mobile.
|
|
528
|
+
const wasSwiping = isSwiping.value;
|
|
529
|
+
processMove(el, pos, e.timeStamp);
|
|
530
|
+
if (wasSwiping || isSwiping.value) {
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function onTouchEnd() {
|
|
536
|
+
const el = elementRef.value;
|
|
537
|
+
if (!el) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
finishSwipe(el);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// -- Attach listeners --
|
|
544
|
+
|
|
545
|
+
const cleanups: Array<() => void> = [];
|
|
546
|
+
|
|
547
|
+
watch(
|
|
548
|
+
() => elementRef.value,
|
|
549
|
+
(el) => {
|
|
550
|
+
cleanups.forEach((fn) => {
|
|
551
|
+
fn();
|
|
552
|
+
});
|
|
553
|
+
cleanups.length = 0;
|
|
554
|
+
|
|
555
|
+
if (!el) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
cleanups.push(
|
|
560
|
+
useEventListener(el, 'pointerdown', onPointerDown as EventListener),
|
|
561
|
+
useEventListener(el, 'pointermove', onPointerMove as EventListener),
|
|
562
|
+
useEventListener(el, 'pointerup', onPointerUp as EventListener),
|
|
563
|
+
useEventListener(el, 'pointercancel', onPointerUp as EventListener),
|
|
564
|
+
useEventListener(el, 'touchstart', onTouchStart as EventListener, { passive: true }),
|
|
565
|
+
useEventListener(el, 'touchmove', onTouchMove as EventListener, { passive: false }),
|
|
566
|
+
useEventListener(el, 'touchend', onTouchEnd as EventListener),
|
|
567
|
+
useEventListener(el, 'touchcancel', onTouchEnd as EventListener),
|
|
568
|
+
);
|
|
569
|
+
},
|
|
570
|
+
{ immediate: true },
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
onUnmounted(() => {
|
|
574
|
+
cleanups.forEach((fn) => {
|
|
575
|
+
fn();
|
|
576
|
+
});
|
|
577
|
+
cleanups.length = 0;
|
|
578
|
+
reset();
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
return {
|
|
582
|
+
isSwiping,
|
|
583
|
+
swipeDirection,
|
|
584
|
+
dragOffset,
|
|
585
|
+
};
|
|
586
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export {
|
|
2
|
+
default as DrawerClose,
|
|
3
|
+
type DrawerCloseProps,
|
|
4
|
+
} from './DrawerClose.vue'
|
|
5
|
+
export {
|
|
6
|
+
default as DrawerContent,
|
|
7
|
+
type DrawerContentEmits,
|
|
8
|
+
type DrawerContentProps,
|
|
9
|
+
} from './DrawerContent.vue'
|
|
10
|
+
// Base UI alias: Drawer.Popup === DrawerContent
|
|
11
|
+
export {
|
|
12
|
+
default as DrawerPopup,
|
|
13
|
+
type DrawerContentEmits as DrawerPopupEmits,
|
|
14
|
+
type DrawerContentProps as DrawerPopupProps,
|
|
15
|
+
} from './DrawerContent.vue'
|
|
16
|
+
export {
|
|
17
|
+
default as DrawerDescription,
|
|
18
|
+
type DrawerDescriptionProps,
|
|
19
|
+
} from './DrawerDescription.vue'
|
|
20
|
+
export {
|
|
21
|
+
default as DrawerHandle,
|
|
22
|
+
type DrawerHandleProps,
|
|
23
|
+
} from './DrawerHandle.vue'
|
|
24
|
+
export {
|
|
25
|
+
default as DrawerIndent,
|
|
26
|
+
type DrawerIndentProps,
|
|
27
|
+
} from './DrawerIndent.vue'
|
|
28
|
+
export {
|
|
29
|
+
default as DrawerIndentBackground,
|
|
30
|
+
type DrawerIndentBackgroundProps,
|
|
31
|
+
} from './DrawerIndentBackground.vue'
|
|
32
|
+
export {
|
|
33
|
+
default as DrawerOverlay,
|
|
34
|
+
type DrawerOverlayProps,
|
|
35
|
+
} from './DrawerOverlay.vue'
|
|
36
|
+
// Base UI alias: Drawer.Backdrop === DrawerOverlay
|
|
37
|
+
export {
|
|
38
|
+
default as DrawerBackdrop,
|
|
39
|
+
type DrawerOverlayProps as DrawerBackdropProps,
|
|
40
|
+
} from './DrawerOverlay.vue'
|
|
41
|
+
export {
|
|
42
|
+
default as DrawerPortal,
|
|
43
|
+
type DrawerPortalProps,
|
|
44
|
+
} from './DrawerPortal.vue'
|
|
45
|
+
export {
|
|
46
|
+
default as DrawerProvider,
|
|
47
|
+
} from './DrawerProvider.vue'
|
|
48
|
+
export {
|
|
49
|
+
type DrawerModal,
|
|
50
|
+
type DrawerOpenChangeDetails,
|
|
51
|
+
type DrawerOpenChangeReason,
|
|
52
|
+
default as DrawerRoot,
|
|
53
|
+
type DrawerRootEmits,
|
|
54
|
+
type DrawerRootProps,
|
|
55
|
+
// Public advanced-composition contract: lets consumers read the Drawer root
|
|
56
|
+
// context to build custom parts (mirrors `injectDialogRootContext`).
|
|
57
|
+
injectDrawerRootContext,
|
|
58
|
+
} from './DrawerRoot.vue'
|
|
59
|
+
export {
|
|
60
|
+
default as DrawerSwipeArea,
|
|
61
|
+
type DrawerSwipeAreaProps,
|
|
62
|
+
} from './DrawerSwipeArea.vue'
|
|
63
|
+
export {
|
|
64
|
+
default as DrawerTitle,
|
|
65
|
+
type DrawerTitleProps,
|
|
66
|
+
} from './DrawerTitle.vue'
|
|
67
|
+
export {
|
|
68
|
+
default as DrawerTrigger,
|
|
69
|
+
type DrawerTriggerProps,
|
|
70
|
+
} from './DrawerTrigger.vue'
|
|
71
|
+
export {
|
|
72
|
+
default as DrawerViewport,
|
|
73
|
+
type DrawerViewportProps,
|
|
74
|
+
} from './DrawerViewport.vue'
|