@jobber/components 8.24.1 → 8.24.2-visual-reg-d5e3ec5.19

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 (73) hide show
  1. package/ProgressIndicator.d.ts +1 -0
  2. package/{DescriptionList.js → ProgressIndicator.js} +3 -3
  3. package/dist/AtlantisThemeContext/AtlantisThemeContext.d.ts +1 -1
  4. package/dist/AtlantisThemeContext/index.cjs +1 -2
  5. package/dist/AtlantisThemeContext/index.mjs +1 -2
  6. package/dist/AtlantisThemeContext/themeStore.d.ts +11 -0
  7. package/dist/AtlantisThemeContext/types.d.ts +14 -0
  8. package/dist/AtlantisThemeContext/updateTheme.d.ts +1 -1
  9. package/dist/AtlantisThemeContext-cjs.js +58 -17
  10. package/dist/AtlantisThemeContext-es.js +60 -20
  11. package/dist/BottomSheet-cjs.js +8 -7
  12. package/dist/BottomSheet-es.js +9 -8
  13. package/dist/ComboboxChipRemove-es.js +2 -2
  14. package/dist/DatePicker-es.js +1 -1
  15. package/dist/Dialog/Dialog.d.ts +47 -3
  16. package/dist/Dialog/Dialog.types.d.ts +1 -15
  17. package/dist/Dialog/DialogBottomSheet.d.ts +12 -13
  18. package/dist/Dialog/DialogModal.d.ts +11 -11
  19. package/dist/Dialog/dialogComposableShared.d.ts +13 -3
  20. package/dist/DrawerDescription-cjs.js +4 -97
  21. package/dist/DrawerDescription-es.js +6 -98
  22. package/dist/InputNumberExperimental-cjs.js +21 -25
  23. package/dist/InputNumberExperimental-es.js +22 -26
  24. package/dist/MenuSubmenuTrigger-es.js +3 -3
  25. package/dist/Modal/index.cjs +12 -2
  26. package/dist/Modal/index.mjs +13 -3
  27. package/dist/ProgressBar/ProgressBar.d.ts +7 -0
  28. package/dist/ProgressBar-cjs.js +4 -0
  29. package/dist/ProgressBar-es.js +4 -0
  30. package/dist/ProgressIndicator/ProgressIndicator.d.ts +60 -0
  31. package/dist/ProgressIndicator/index.cjs +9 -0
  32. package/dist/ProgressIndicator/index.d.ts +1 -0
  33. package/dist/ProgressIndicator/index.mjs +3 -0
  34. package/dist/ProgressIndicator-cjs.js +43 -0
  35. package/dist/ProgressIndicator-es.js +41 -0
  36. package/dist/ScrollAreaViewport-cjs.js +2122 -12
  37. package/dist/ScrollAreaViewport-es.js +2118 -13
  38. package/dist/dialogReturnFocus-cjs.js +64 -35
  39. package/dist/dialogReturnFocus-es.js +66 -37
  40. package/dist/docs/AtlantisThemeContext/AtlantisThemeContext.md +41 -0
  41. package/dist/docs/DataTable/DataTable.md +0 -4
  42. package/dist/docs/Dialog/Dialog.md +1006 -0
  43. package/dist/docs/Icon/Icon.md +60 -53
  44. package/dist/docs/InputNumberExperimental/InputNumberExperimental.md +578 -0
  45. package/dist/docs/ProgressBar/ProgressBar.md +9 -0
  46. package/dist/docs/ProgressIndicator/ProgressIndicator.md +105 -0
  47. package/dist/docs/Table/Table.md +1 -3
  48. package/dist/docs/index.md +3 -1
  49. package/dist/index.cjs +3 -4
  50. package/dist/index.d.mts +1 -1
  51. package/dist/index.d.ts +1 -1
  52. package/dist/index.mjs +2 -3
  53. package/dist/isTypedArray-es.js +1 -1
  54. package/dist/primitives/InputNumberExperimental/InputNumberExperimental.d.ts +31 -15
  55. package/dist/primitives/InputNumberExperimental/types.d.ts +0 -1
  56. package/dist/styles.css +172 -51
  57. package/dist/unstyledPrimitives/index.cjs +218 -2230
  58. package/dist/unstyledPrimitives/index.mjs +224 -2236
  59. package/dist/useButton-es.js +1 -1
  60. package/dist/useScrollLock-es.js +2 -2
  61. package/dist/useScrollToActive-es.js +1 -1
  62. package/dist/utils/meta/meta.json +1 -1
  63. package/package.json +7 -7
  64. package/DescriptionList.d.ts +0 -1
  65. package/dist/DescriptionList/DescriptionList.d.ts +0 -11
  66. package/dist/DescriptionList/index.cjs +0 -10
  67. package/dist/DescriptionList/index.d.ts +0 -1
  68. package/dist/DescriptionList/index.mjs +0 -4
  69. package/dist/DescriptionList-cjs.js +0 -14
  70. package/dist/DescriptionList-es.js +0 -12
  71. package/dist/docs/DescriptionList/DescriptionList.md +0 -25
  72. package/dist/updateTheme-cjs.js +0 -20
  73. package/dist/updateTheme-es.js +0 -18
@@ -2,18 +2,18 @@ import * as React from 'react';
2
2
  import { A as useCoreFilter, B as AriaCombobox, D as useComboboxInputValueContext, e as ComboboxTrigger, d as ComboboxInputGroup, p as ComboboxItem, l as ComboboxArrow, i as ComboboxBackdrop, x as ComboboxClear, v as ComboboxCollection, w as ComboboxEmpty, n as ComboboxGroup, o as ComboboxGroupLabel, m as ComboboxIcon, c as ComboboxInput, f as ComboboxList, k as ComboboxPopup, h as ComboboxPortal, j as ComboboxPositioner, u as ComboboxRow, g as ComboboxStatus, z as useFilteredItems, s as ComboboxChip, t as ComboboxChipRemove, r as ComboboxChips, q as ComboboxItemIndicator, a as ComboboxLabel, C as ComboboxRoot, b as ComboboxValue, y as useComboboxFilter } from '../ComboboxChipRemove-es.js';
3
3
  import { a as stringifyAsLabel, l as getDefaultLabelId } from '../resolveAriaLabelledBy-es.js';
4
4
  import { jsx, jsxs } from 'react/jsx-runtime';
5
- import { af as pointer, a as useIsoLayoutEffect, b as useStableCallback, o as ownerDocument, q as contains, g as getTarget, h as useTimeout, u as useBaseUiId, d as createChangeEventDetails, ag as swipe, n as useAnimationFrame, B as addEventListener, p as activeElement, ad as TransitionStatusDataAttributes, z as useControlled, V as itemPress, k as useTransitionStatus, f as useOpenChangeComplete, a2 as useAnimationsFinished, ah as scrub, J as createGenericEventDetails, t as transitionStatusMapping } from '../useButton-es.js';
5
+ import { ag as pointer, a as useIsoLayoutEffect, b as useStableCallback, h as useTimeout, u as useBaseUiId, d as createChangeEventDetails, a6 as swipe, n as useAnimationFrame, o as ownerDocument, B as addEventListener, p as activeElement, q as contains, g as getTarget, z as useControlled, V as itemPress, k as useTransitionStatus, f as useOpenChangeComplete, a0 as useAnimationsFinished, ah as scrub, J as createGenericEventDetails, t as transitionStatusMapping } from '../useButton-es.js';
6
6
  import { S as Separator } from '../Separator-es.js';
7
- import { a as DialogBackdrop, d as DialogDescription, f as DialogHandle, c as DialogPopup, b as DialogViewport, e as createDialogHandle, D as DrawerDescription } from '../DrawerDescription-es.js';
7
+ import { a as DialogBackdrop, c as DialogDescription, e as DialogHandle, b as DialogPopup, d as createDialogHandle, D as DrawerDescription } from '../DrawerDescription-es.js';
8
8
  import { c as DialogClose, b as DialogTitle, a as DrawerClose, D as DrawerTitle } from '../DrawerTitle-es.js';
9
- import { i as DialogPortal, g as DialogRoot, h as DialogTrigger, m as useDrawerProviderContext, n as DrawerBackdropCssVars, o as DrawerPopupCssVars, q as DrawerProviderContext, u as useDialogRootContext, r as useDrawerRootContext, s as DrawerPopupDataAttributes, t as useDrawerSnapPoints, v as getSnapPointSwipeMovement, w as DrawerViewportContext, x as DRAWER_CONTENT_ATTRIBUTE, c as DrawerBackdrop, f as DrawerContent, d as DrawerPopup, b as DrawerPortal, a as DrawerRoot, D as DrawerTrigger, y as useScrollAreaRootContext, z as getOffset, A as ScrollAreaRootCssVars, B as scrollAreaStateAttributesMapping, C as useScrollAreaViewportContext, S as ScrollAreaRoot, e as ScrollAreaViewport } from '../ScrollAreaViewport-es.js';
10
- import { u as useRenderElement, m as mergeProps, f as formatErrorMessage, N as NOOP, E as EMPTY_OBJECT } from '../useRenderElement-es.js';
11
- import { a as isHTMLElement, d as isLastTraversableNode, e as getParentNode, f as getComputedStyle, o as getWindow, b as isElement } from '../floating-ui.utils.dom-es.js';
9
+ import { l as DialogPortal, j as DialogRoot, k as DialogTrigger, m as DialogViewport, o as useDrawerProviderContext, q as DrawerBackdropCssVars, r as DrawerPopupCssVars, s as DrawerProviderContext, u as useDialogRootContext, t as useDrawerRootContext, v as useSwipeDismiss, w as getDisplacement, x as DrawerPopupDataAttributes, y as getElementTransform, z as DrawerVirtualKeyboardContext, A as getElementAtPoint, B as findScrollableTouchTarget, c as DrawerBackdrop, g as DrawerContent, e as DrawerPopup, b as DrawerPortal, a as DrawerRoot, D as DrawerTrigger, d as DrawerViewport, C as useScrollAreaRootContext, E as getOffset, F as ScrollAreaRootCssVars, G as scrollAreaStateAttributesMapping, H as useScrollAreaViewportContext, S as ScrollAreaRoot, f as ScrollAreaViewport } from '../ScrollAreaViewport-es.js';
10
+ import { u as useRenderElement, f as formatErrorMessage, N as NOOP, E as EMPTY_OBJECT } from '../useRenderElement-es.js';
11
+ import { C as CommonPopupDataAttributes, ae as useTriggerRegistration, Q as isInteractiveElement, p as popupStateMapping, r as useDirection, G as inertValue, K as mergeCleanups, am as gecko, J as webkit, w as useStore, af as triggerOpenStateMapping } from '../useScrollLock-es.js';
12
+ import { o as getWindow, f as getComputedStyle, a as isHTMLElement, e as getParentNode } from '../floating-ui.utils.dom-es.js';
12
13
  import { c as clamp } from '../clamp-es.js';
13
- import { C as CommonPopupDataAttributes, aj as useTriggerRegistration, am as BASE_UI_SWIPE_IGNORE_SELECTOR, a0 as isInteractiveElement, p as popupStateMapping, r as useDirection, G as inertValue, X as mergeCleanups, al as gecko, J as webkit, w as useStore, W as triggerOpenStateMapping } from '../useScrollLock-es.js';
14
- import * as ReactDOM from 'react-dom';
15
14
  import { u as useMenuRootContext, o as useMenuPositionerContext, p as useMenuItem, R as REGULAR_ITEM, q as itemMapping, r as MenuStore, h as MenuBackdrop, l as MenuGroup, n as MenuGroupLabel, b as MenuItem, a as MenuLinkItem, j as MenuPopup, g as MenuPortal, i as MenuPositioner, k as MenuRadioGroup, c as MenuRadioItem, d as MenuRadioItemIndicator, f as MenuRoot, m as MenuSubmenuRoot, e as MenuSubmenuTrigger, M as MenuTrigger } from '../MenuSubmenuTrigger-es.js';
16
15
  import { h as useCompositeListItem } from '../useCompositeListItem-es.js';
16
+ import * as ReactDOM from 'react-dom';
17
17
  import { u as usePreviousValue, l as useSelectRootContext, s as selectors, m as useSelectPositionerContext, j as SelectGroup, k as SelectGroupLabel, g as SelectItem, i as SelectItemIndicator, h as SelectItemText, f as SelectList, e as SelectPopup, a as SelectPortal, d as SelectPositioner, S as SelectRoot, b as SelectTrigger, c as SelectValue } from '../SelectGroupLabel-es.js';
18
18
  import { v as round } from '../floating-ui.utils-es.js';
19
19
  import { u as useNumberFieldRootContext, s as stateAttributesMapping$6, d as NumberFieldDecrement, a as NumberFieldGroup, c as NumberFieldIncrement, b as NumberFieldInput, N as NumberFieldRoot } from '../NumberFieldInput-es.js';
@@ -397,1191 +397,181 @@ function createVisualStateStore() {
397
397
  };
398
398
  }
399
399
 
400
- function isScrollable(element, axis,
401
- // When true, a container that overflows only once extra space is added (e.g. drawer
402
- // keyboard scroll slack) still counts, as long as it has layout size on the axis.
403
- allowOverflowIntent = false) {
404
- const style = getComputedStyle(element);
405
- if (axis === 'vertical') {
406
- const overflowY = style.overflowY;
407
- if (overflowY !== 'auto' && overflowY !== 'scroll') {
408
- return false;
409
- }
410
- return allowOverflowIntent ? element.clientHeight > 0 : element.scrollHeight > element.clientHeight;
411
- }
412
- const overflowX = style.overflowX;
413
- if (overflowX !== 'auto' && overflowX !== 'scroll') {
414
- return false;
415
- }
416
- return allowOverflowIntent ? element.clientWidth > 0 : element.scrollWidth > element.clientWidth;
417
- }
418
- function hasScrollableAncestor(target, root, axes) {
419
- // `getParentNode` crosses shadow boundaries (and slots), so a target inside a shadow root
420
- // still walks up to scrollable ancestors in the light DOM.
421
- let node = target;
422
- while (isHTMLElement(node) && node !== root && !isLastTraversableNode(node)) {
423
- for (const axis of axes) {
424
- if (isScrollable(node, axis)) {
425
- return true;
426
- }
427
- }
428
- node = getParentNode(node);
429
- }
430
- return false;
431
- }
432
- function findScrollableTouchTarget(target, root, axis = 'vertical', allowOverflowIntent = false) {
433
- // `getParentNode` crosses shadow boundaries (and slots), so a target inside a shadow root
434
- // still reaches a scrollable ancestor in the light DOM.
435
- let node = isHTMLElement(target) ? target : null;
436
- while (isHTMLElement(node) && node !== root && !isLastTraversableNode(node)) {
437
- if (isScrollable(node, axis, allowOverflowIntent)) {
438
- return node;
439
- }
440
- node = getParentNode(node);
441
- }
442
- return isScrollable(root, axis, allowOverflowIntent) ? root : null;
443
- }
444
-
445
- function getElementAtPoint(doc, x, y) {
446
- return typeof doc?.elementFromPoint === 'function' ? doc.elementFromPoint(x, y) : null;
447
- }
400
+ let DrawerSwipeAreaDataAttributes = function (DrawerSwipeAreaDataAttributes) {
401
+ /**
402
+ * Present when the drawer is open.
403
+ */
404
+ DrawerSwipeAreaDataAttributes[DrawerSwipeAreaDataAttributes["open"] = CommonPopupDataAttributes.open] = "open";
405
+ /**
406
+ * Present when the drawer is closed.
407
+ */
408
+ DrawerSwipeAreaDataAttributes[DrawerSwipeAreaDataAttributes["closed"] = CommonPopupDataAttributes.closed] = "closed";
409
+ /**
410
+ * Present when the swipe area is disabled.
411
+ */
412
+ DrawerSwipeAreaDataAttributes["disabled"] = "data-disabled";
413
+ /**
414
+ * Indicates the swipe direction.
415
+ * @type {'up' | 'down' | 'left' | 'right'}
416
+ */
417
+ DrawerSwipeAreaDataAttributes["swipeDirection"] = "data-swipe-direction";
418
+ /**
419
+ * Present when the drawer is being swiped.
420
+ */
421
+ DrawerSwipeAreaDataAttributes["swiping"] = "data-swiping";
422
+ return DrawerSwipeAreaDataAttributes;
423
+ }({});
448
424
 
449
- const DEFAULT_SWIPE_THRESHOLD = 40;
450
- const REVERSE_CANCEL_THRESHOLD = 10;
451
- const MIN_DRAG_THRESHOLD = 1;
452
- const MIN_VELOCITY_DURATION_MS = 50;
453
- const MIN_RELEASE_VELOCITY_DURATION_MS = 16;
454
- const MAX_RELEASE_VELOCITY_AGE_MS = 80;
455
- const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
456
- function getDisplacement(direction, deltaX, deltaY) {
457
- switch (direction) {
458
- case 'up':
459
- return -deltaY;
460
- case 'down':
461
- return deltaY;
462
- case 'left':
463
- return -deltaX;
464
- case 'right':
465
- return deltaX;
466
- default:
467
- return 0;
468
- }
469
- }
470
- function getElementTransform(element) {
471
- const computedStyle = getWindow(element).getComputedStyle(element);
472
- const transform = computedStyle.transform;
473
- let translateX = 0;
474
- let translateY = 0;
475
- let scale = 1;
476
- if (transform && transform !== 'none') {
477
- const matrix = transform.match(/matrix(?:3d)?\(([^)]+)\)/);
478
- if (matrix) {
479
- const values = matrix[1].split(', ').map(parseFloat);
480
- if (values.length === 6) {
481
- translateX = values[4];
482
- translateY = values[5];
483
- scale = Math.sqrt(values[0] * values[0] + values[1] * values[1]);
484
- } else if (values.length === 16) {
485
- translateX = values[12];
486
- translateY = values[13];
487
- scale = values[0];
488
- }
489
- }
490
- }
491
- return {
492
- x: translateX,
493
- y: translateY,
494
- scale
495
- };
496
- }
497
- function getValidTimeStamp(timeStamp) {
498
- return Number.isFinite(timeStamp) && timeStamp > 0 ? timeStamp : null;
499
- }
500
- function getDragTransform(dragOffset, scale) {
501
- return `translate3d(${dragOffset.x}px,${dragOffset.y}px,0) scale(${scale})`;
502
- }
503
- function hasPrimaryMouseButton(buttons) {
504
- return buttons % 2 === 1;
505
- }
506
- function safelyChangePointerCapture(element, pointerId, method) {
507
- const pointerCaptureMethod = element[method];
508
- if (typeof pointerCaptureMethod !== 'function') {
509
- return;
510
- }
511
- try {
512
- pointerCaptureMethod.call(element, pointerId);
513
- } catch (error) {
514
- if (error && typeof error === 'object' && 'name' in error && error.name === 'NotFoundError') {
515
- return;
516
- }
517
- throw error;
425
+ const DEFAULT_SWIPE_OPEN_RATIO = 0.5;
426
+ const MIN_SWIPE_START_DISTANCE = 1;
427
+ const VELOCITY_THRESHOLD = 0.1;
428
+ const FALLBACK_SWIPE_OPEN_THRESHOLD = 40;
429
+ const SWIPE_AREA_OPEN_HOOK = {
430
+ [DrawerSwipeAreaDataAttributes.open]: ''
431
+ };
432
+ const SWIPE_AREA_CLOSED_HOOK = {
433
+ [DrawerSwipeAreaDataAttributes.closed]: ''
434
+ };
435
+ const SWIPE_AREA_SWIPING_HOOK = {
436
+ [DrawerSwipeAreaDataAttributes.swiping]: ''
437
+ };
438
+ const SWIPE_AREA_DISABLED_HOOK = {
439
+ [DrawerSwipeAreaDataAttributes.disabled]: ''
440
+ };
441
+ const stateAttributesMapping$3 = {
442
+ open(value) {
443
+ return value ? SWIPE_AREA_OPEN_HOOK : SWIPE_AREA_CLOSED_HOOK;
444
+ },
445
+ swiping(value) {
446
+ return value ? SWIPE_AREA_SWIPING_HOOK : null;
447
+ },
448
+ swipeDirection(value) {
449
+ return value ? {
450
+ [DrawerSwipeAreaDataAttributes.swipeDirection]: value
451
+ } : null;
452
+ },
453
+ disabled(value) {
454
+ return value ? SWIPE_AREA_DISABLED_HOOK : null;
518
455
  }
456
+ };
457
+ const oppositeSwipeDirection = {
458
+ up: 'down',
459
+ down: 'up',
460
+ left: 'right',
461
+ right: 'left'
462
+ };
463
+ function resolveTouchAction(direction) {
464
+ return direction === 'left' || direction === 'right' ? 'pan-y' : 'pan-x';
519
465
  }
520
- function useSwipeDismiss(options) {
466
+
467
+ /**
468
+ * An invisible area that listens for swipe gestures to open the drawer.
469
+ * Renders a `<div>` element.
470
+ *
471
+ * Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
472
+ */
473
+ const DrawerSwipeArea = /*#__PURE__*/React.forwardRef(function DrawerSwipeArea(componentProps, forwardedRef) {
521
474
  const {
522
- enabled,
523
- directions,
524
- elementRef,
525
- movementCssVars,
526
- canStart,
527
- ignoreSelectorWhenTouch = true,
528
- ignoreScrollableAncestors = false,
529
- swipeThreshold: swipeThresholdProp,
530
- onDismiss,
531
- onProgress,
532
- onCancel,
533
- onSwipeStart,
534
- onRelease,
535
- onSwipingChange,
536
- trackDrag = true
537
- } = options;
538
- const ignoreSelector = DEFAULT_IGNORE_SELECTOR;
539
- const primaryDirection = directions.length === 1 ? directions[0] : undefined;
540
- const swipeThresholdDefault = Math.max(0, typeof swipeThresholdProp === 'number' ? swipeThresholdProp : DEFAULT_SWIPE_THRESHOLD);
541
- const allowLeft = directions.includes('left');
542
- const allowRight = directions.includes('right');
543
- const allowUp = directions.includes('up');
544
- const allowDown = directions.includes('down');
545
- const hasHorizontal = allowLeft || allowRight;
546
- const hasVertical = allowUp || allowDown;
547
- const scrollAxes = React.useMemo(() => {
548
- const axes = [];
549
- if (hasVertical) {
550
- axes.push('vertical');
551
- }
552
- if (hasHorizontal) {
553
- axes.push('horizontal');
554
- }
555
- return axes;
556
- }, [hasHorizontal, hasVertical]);
557
- const [currentSwipeDirection, setCurrentSwipeDirection] = React.useState(undefined);
558
- const [isSwiping, setIsSwiping] = React.useState(false);
559
- const [dragDismissed, setDragDismissed] = React.useState(false);
560
- const dragStartPosRef = React.useRef({
561
- x: 0,
562
- y: 0
563
- });
564
- const dragOffsetRef = React.useRef({
565
- x: 0,
566
- y: 0
567
- });
568
- const lastMovePosRef = React.useRef(null);
569
- const initialTransformRef = React.useRef({
570
- x: 0,
571
- y: 0,
572
- scale: 1
573
- });
574
- const intendedSwipeDirectionRef = React.useRef(undefined);
575
- const maxSwipeDisplacementRef = React.useRef(0);
576
- const cancelledSwipeRef = React.useRef(false);
577
- const swipeCancelBaselineRef = React.useRef({
578
- x: 0,
579
- y: 0
580
- });
581
- const lockedDirectionRef = React.useRef(null);
582
- const isFirstPointerMoveRef = React.useRef(false);
583
- const pendingSwipeRef = React.useRef(false);
584
- const pendingSwipeStartPosRef = React.useRef(null);
585
- const swipeFromScrollableRef = React.useRef(false);
586
- const sawPrimaryButtonsOnMoveRef = React.useRef(false);
587
- const elementSizeRef = React.useRef({
588
- width: 0,
589
- height: 0
590
- });
591
- const swipeProgressRef = React.useRef(0);
592
- const swipeThresholdRef = React.useRef(swipeThresholdDefault);
593
- const swipeStartTimeRef = React.useRef(null);
594
- const lastDragSampleRef = React.useRef(null);
595
- const lastDragVelocityRef = React.useRef({
475
+ render,
476
+ className,
477
+ style,
478
+ disabled = false,
479
+ swipeDirection: swipeDirectionProp,
480
+ ...elementProps
481
+ } = componentProps;
482
+ const {
483
+ store
484
+ } = useDialogRootContext();
485
+ const {
486
+ swipeDirection,
487
+ frontmostHeight
488
+ } = useDrawerRootContext();
489
+ const providerContext = useDrawerProviderContext();
490
+ const [swipeActive, setSwipeActive] = React.useState(false);
491
+ const releaseDismissTimeout = useTimeout();
492
+ const swipeAreaRef = React.useRef(null);
493
+ const swipeStartEventRef = React.useRef(null);
494
+ const openedBySwipeRef = React.useRef(false);
495
+ const dragDeltaRef = React.useRef({
596
496
  x: 0,
597
497
  y: 0
598
498
  });
599
- const lastProgressDetailsRef = React.useRef(null);
600
- const isSwipingRef = React.useRef(false);
601
- const dragStyleSnapshotRef = React.useRef(null);
602
- const setSwiping = useStableCallback(nextSwiping => {
603
- if (isSwipingRef.current === nextSwiping) {
604
- return;
605
- }
606
- isSwipingRef.current = nextSwiping;
607
- setIsSwiping(nextSwiping);
608
- onSwipingChange?.(nextSwiping);
499
+ const closedOffsetRef = React.useRef(null);
500
+ const appliedSwipeStylesRef = React.useRef(false);
501
+ const popupTransitionRef = React.useRef(null);
502
+ const swipeAreaId = useBaseUiId(componentProps.id);
503
+ const registerTrigger = useTriggerRegistration(swipeAreaId, store);
504
+ const open = store.useState('open');
505
+ const resetDragDelta = useStableCallback(() => {
506
+ dragDeltaRef.current.x = 0;
507
+ dragDeltaRef.current.y = 0;
609
508
  });
610
- function resolveSwipeThreshold(direction) {
611
- if (!direction) {
612
- return;
613
- }
614
- if (typeof swipeThresholdProp !== 'function') {
615
- swipeThresholdRef.current = swipeThresholdDefault;
616
- return;
617
- }
618
- const element = elementRef.current;
619
- if (!element) {
620
- return;
621
- }
622
- const value = swipeThresholdProp({
623
- element,
624
- direction
509
+ const resolvedSwipeDirection = swipeDirectionProp ?? oppositeSwipeDirection[swipeDirection];
510
+ const dismissDirection = oppositeSwipeDirection[resolvedSwipeDirection];
511
+ const enabled = !disabled && (!open || swipeActive);
512
+ function disableDismissForSwipe() {
513
+ releaseDismissTimeout.clear();
514
+ store.context.outsidePressEnabledRef.current = false;
515
+ }
516
+ function enableDismissAfterRelease() {
517
+ // Safari can dispatch outside-press for the same swipe-open gesture
518
+ // after release, so defer re-enabling dismissal to the next macrotask.
519
+ releaseDismissTimeout.start(0, () => {
520
+ store.context.outsidePressEnabledRef.current = true;
625
521
  });
626
- swipeThresholdRef.current = Math.max(0, value);
627
522
  }
628
- const updateSwipeProgress = useStableCallback((progress, details) => {
629
- const nextProgress = Number.isFinite(progress) ? clamp(progress, 0, 1) : 0;
630
- const progressChanged = nextProgress !== swipeProgressRef.current;
631
- let detailsChanged = false;
632
- if (details) {
633
- const lastDetails = lastProgressDetailsRef.current;
634
- detailsChanged = !lastDetails || lastDetails.deltaX !== details.deltaX || lastDetails.deltaY !== details.deltaY || lastDetails.direction !== details.direction;
635
- }
636
- if (!progressChanged && !detailsChanged) {
637
- return;
638
- }
639
- swipeProgressRef.current = nextProgress;
640
- if (details) {
641
- lastProgressDetailsRef.current = details;
642
- } else if (progressChanged) {
643
- lastProgressDetailsRef.current = null;
644
- }
645
- onProgress?.(nextProgress, details);
646
- });
647
- const syncDragStyles = useStableCallback(swiping => {
648
- const element = elementRef.current;
649
- if (!trackDrag || !element) {
650
- if (!swiping) {
651
- dragStyleSnapshotRef.current = null;
652
- }
653
- return;
654
- }
655
- const style = element.style;
656
- const dragStyleSnapshot = dragStyleSnapshotRef.current;
657
- if (swiping) {
658
- if (!dragStyleSnapshot) {
659
- dragStyleSnapshotRef.current = [style.transition, style.transform];
660
- }
661
- style.transition = 'none';
662
- } else if (dragStyleSnapshot) {
663
- [style.transition, style.transform] = dragStyleSnapshot;
664
- dragStyleSnapshotRef.current = null;
665
- }
666
- const dragOffset = dragOffsetRef.current;
667
- const initialTransform = initialTransformRef.current;
668
- const deltaX = dragOffset.x - initialTransform.x;
669
- const deltaY = dragOffset.y - initialTransform.y;
670
- if (swiping) {
671
- style.transform = getDragTransform(dragOffset, initialTransform.scale);
672
- }
673
- style.setProperty(movementCssVars.x, `${deltaX}px`);
674
- style.setProperty(movementCssVars.y, `${deltaY}px`);
675
- });
676
- function recordDragSample(offset, timeStamp) {
677
- if (timeStamp === null) {
678
- return;
523
+ function resolvePopupSize() {
524
+ const popupElement = store.context.popupRef.current;
525
+ if (!popupElement) {
526
+ return null;
679
527
  }
680
- const lastSample = lastDragSampleRef.current;
681
- if (lastSample && timeStamp > lastSample.time) {
682
- const durationMs = Math.max(timeStamp - lastSample.time, MIN_RELEASE_VELOCITY_DURATION_MS);
683
- lastDragVelocityRef.current = {
684
- x: (offset.x - lastSample.x) / durationMs,
685
- y: (offset.y - lastSample.y) / durationMs
686
- };
528
+ const isHorizontal = dismissDirection === 'left' || dismissDirection === 'right';
529
+ const size = isHorizontal ? popupElement.offsetWidth : popupElement.offsetHeight;
530
+ if (size <= 0) {
531
+ return null;
687
532
  }
688
- lastDragSampleRef.current = {
689
- x: offset.x,
690
- y: offset.y,
691
- time: timeStamp
692
- };
533
+ return size;
693
534
  }
694
- const reset = React.useCallback(() => {
695
- setCurrentSwipeDirection(undefined);
696
- setSwiping(false);
697
- setDragDismissed(false);
698
- updateSwipeProgress(0);
699
- swipeThresholdRef.current = swipeThresholdDefault;
700
- dragStartPosRef.current = {
701
- x: 0,
702
- y: 0
703
- };
704
- dragOffsetRef.current = {
705
- x: 0,
706
- y: 0
707
- };
708
- initialTransformRef.current = {
709
- x: 0,
710
- y: 0,
711
- scale: 1
712
- };
713
- intendedSwipeDirectionRef.current = undefined;
714
- maxSwipeDisplacementRef.current = 0;
715
- cancelledSwipeRef.current = false;
716
- swipeCancelBaselineRef.current = {
717
- x: 0,
718
- y: 0
719
- };
720
- lockedDirectionRef.current = null;
721
- isFirstPointerMoveRef.current = false;
722
- lastMovePosRef.current = null;
723
- pendingSwipeRef.current = false;
724
- pendingSwipeStartPosRef.current = null;
725
- swipeFromScrollableRef.current = false;
726
- sawPrimaryButtonsOnMoveRef.current = false;
727
- elementSizeRef.current = {
728
- width: 0,
729
- height: 0
730
- };
731
- swipeStartTimeRef.current = null;
732
- lastDragSampleRef.current = null;
733
- lastDragVelocityRef.current = {
734
- x: 0,
735
- y: 0
736
- };
737
- lastProgressDetailsRef.current = null;
738
- syncDragStyles(false);
739
- }, [setSwiping, swipeThresholdDefault, syncDragStyles, updateSwipeProgress]);
740
- React.useEffect(() => {
741
- if (typeof swipeThresholdProp !== 'function') {
742
- swipeThresholdRef.current = swipeThresholdDefault;
535
+ function resolveClosedOffset() {
536
+ const offset = resolvePopupSize();
537
+ if (offset == null) {
538
+ return null;
743
539
  }
744
- }, [swipeThresholdDefault, swipeThresholdProp]);
745
- function getPrimaryPointerPosition(event) {
746
- if ('touches' in event) {
747
- const touch = event.touches[0];
748
- return touch ? {
749
- x: touch.clientX,
750
- y: touch.clientY
751
- } : null;
540
+ const popupElement = store.context.popupRef.current;
541
+ if (!popupElement) {
542
+ return offset;
752
543
  }
753
- return {
754
- x: event.clientX,
755
- y: event.clientY
756
- };
757
- }
758
- function isTouchLikeEvent(event) {
759
- if ('touches' in event) {
760
- return true;
544
+ const isHorizontal = dismissDirection === 'left' || dismissDirection === 'right';
545
+ const transform = getElementTransform(popupElement);
546
+ const transformOffset = isHorizontal ? transform.x : transform.y;
547
+ if (Number.isFinite(transformOffset) && Math.abs(transformOffset) > 0.5) {
548
+ return Math.min(offset, Math.abs(transformOffset));
761
549
  }
762
- return event.pointerType === 'touch';
763
- }
764
- function getTargetAtPoint(position, nativeEvent) {
765
- const doc = ownerDocument(elementRef.current);
766
- const elementAtPoint = getElementAtPoint(doc, position.x, position.y);
767
- const target = elementAtPoint ?? getTarget(nativeEvent);
768
- return target;
550
+ return offset;
769
551
  }
770
- function findGestureScrollableTouchTarget(target, root) {
771
- if (hasHorizontal && !hasVertical) {
772
- return findScrollableTouchTarget(target, root, 'horizontal');
773
- }
774
- if (hasVertical && !hasHorizontal) {
775
- return findScrollableTouchTarget(target, root, 'vertical');
552
+ function resolveSwipeOpenThreshold() {
553
+ const popupSize = resolvePopupSize();
554
+ if (popupSize == null) {
555
+ return FALLBACK_SWIPE_OPEN_THRESHOLD;
776
556
  }
777
- return findScrollableTouchTarget(target, root, 'vertical') ?? findScrollableTouchTarget(target, root, 'horizontal');
557
+ return popupSize * DEFAULT_SWIPE_OPEN_RATIO;
778
558
  }
779
- function startSwipeAtPosition(event, position, startOptions) {
780
- swipeFromScrollableRef.current = false;
781
- const touchLike = isTouchLikeEvent(event);
782
- const target = getTargetAtPoint(position, event.nativeEvent);
783
- const doc = ownerDocument(elementRef.current);
784
- const body = doc.body;
785
- const scrollableTarget = touchLike && body ? findGestureScrollableTouchTarget(target, body) : null;
786
- const ignoreScrollableTarget = startOptions?.ignoreScrollableTarget ?? false;
787
- if (scrollableTarget && !ignoreScrollableTarget) {
788
- return false;
559
+ function applySwipeMovement() {
560
+ if (!swipeActive) {
561
+ return;
789
562
  }
790
- swipeFromScrollableRef.current = Boolean(scrollableTarget && ignoreScrollableTarget);
791
- const isInteractiveElement = target ? target.closest(ignoreSelector) : false;
792
- if (isInteractiveElement && (!touchLike || ignoreSelectorWhenTouch)) {
793
- return false;
563
+ const popupElement = store.context.popupRef.current;
564
+ if (!popupElement) {
565
+ return;
794
566
  }
795
- const element = elementRef.current;
796
- if (ignoreScrollableAncestors && element && target && scrollAxes.length > 0) {
797
- const ignoreAncestors = startOptions?.ignoreScrollableAncestors ?? false;
798
- if (!ignoreAncestors && hasScrollableAncestor(target, element, scrollAxes)) {
799
- return false;
800
- }
567
+ if (!store.select('open') || !store.select('mounted')) {
568
+ return;
801
569
  }
802
- cancelledSwipeRef.current = false;
803
- intendedSwipeDirectionRef.current = undefined;
804
- maxSwipeDisplacementRef.current = 0;
805
- dragStartPosRef.current = position;
806
- swipeStartTimeRef.current = getValidTimeStamp(event.timeStamp);
807
- swipeCancelBaselineRef.current = position;
808
- lastMovePosRef.current = position;
809
- if (element) {
810
- elementSizeRef.current = {
811
- width: element.offsetWidth,
812
- height: element.offsetHeight
813
- };
814
- resolveSwipeThreshold(primaryDirection);
815
- const transform = getElementTransform(element);
816
- initialTransformRef.current = transform;
817
- dragOffsetRef.current = {
818
- x: transform.x,
819
- y: transform.y
820
- };
821
- recordDragSample({
822
- x: transform.x,
823
- y: transform.y
824
- }, swipeStartTimeRef.current);
825
- if (!('touches' in event)) {
826
- safelyChangePointerCapture(element, event.pointerId, 'setPointerCapture');
827
- }
570
+ if (closedOffsetRef.current == null) {
571
+ closedOffsetRef.current = resolveClosedOffset();
828
572
  }
829
- onSwipeStart?.(event.nativeEvent);
830
- setSwiping(true);
831
- lockedDirectionRef.current = null;
832
- isFirstPointerMoveRef.current = true;
833
- updateSwipeProgress(0);
834
- syncDragStyles(true);
835
- return true;
836
- }
837
- function resetPendingSwipeState() {
838
- clearPendingSwipeStartState();
839
- swipeFromScrollableRef.current = false;
840
- lastMovePosRef.current = null;
841
- }
842
- function clearPendingSwipeStartState() {
843
- pendingSwipeRef.current = false;
844
- pendingSwipeStartPosRef.current = null;
845
- }
846
- function cancelSwipeInteraction(event) {
847
- resetPendingSwipeState();
848
- if (!isSwipingRef.current) {
849
- return;
850
- }
851
- setSwiping(false);
852
- lockedDirectionRef.current = null;
853
- const resolvedInitialTransform = initialTransformRef.current;
854
- dragOffsetRef.current = {
855
- x: resolvedInitialTransform.x,
856
- y: resolvedInitialTransform.y
857
- };
858
- setCurrentSwipeDirection(undefined);
859
- sawPrimaryButtonsOnMoveRef.current = false;
860
- syncDragStyles(false);
861
- const element = elementRef.current;
862
- if (element) {
863
- safelyChangePointerCapture(element, event.pointerId, 'releasePointerCapture');
864
- }
865
- updateSwipeProgress(0, {
866
- deltaX: 0,
867
- deltaY: 0,
868
- direction: undefined
869
- });
870
- onCancel?.(event.nativeEvent);
871
- }
872
- function applyDirectionalDamping(deltaX, deltaY) {
873
- const exponent = value => value >= 0 ? value ** 0.5 : -(Math.abs(value) ** 0.5);
874
- const dampAxis = (delta, allowNegative, allowPositive) => {
875
- if (!allowNegative && delta < 0) {
876
- return exponent(delta);
877
- }
878
- if (!allowPositive && delta > 0) {
879
- return exponent(delta);
880
- }
881
- return delta;
882
- };
883
- const newDeltaX = hasHorizontal ? dampAxis(deltaX, allowLeft, allowRight) : exponent(deltaX);
884
- const newDeltaY = hasVertical ? dampAxis(deltaY, allowUp, allowDown) : exponent(deltaY);
885
- return {
886
- x: newDeltaX,
887
- y: newDeltaY
888
- };
889
- }
890
- function canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY) {
891
- const absDeltaX = Math.abs(deltaX);
892
- const absDeltaY = Math.abs(deltaY);
893
- const useVerticalAxis = hasVertical && deltaY !== 0 && (!hasHorizontal || absDeltaY >= absDeltaX);
894
- if (useVerticalAxis) {
895
- const maxScrollTop = Math.max(0, scrollTarget.scrollHeight - scrollTarget.clientHeight);
896
- const atTop = scrollTarget.scrollTop <= 0;
897
- const atBottom = scrollTarget.scrollTop >= maxScrollTop;
898
- const movingDown = deltaY > 0;
899
- const movingUp = deltaY < 0;
900
- const canSwipeDown = movingDown && atTop && allowDown;
901
- const canSwipeUp = movingUp && atBottom && allowUp;
902
- return canSwipeDown || canSwipeUp;
903
- }
904
- const useHorizontalAxis = hasHorizontal && deltaX !== 0 && (!hasVertical || absDeltaX > absDeltaY);
905
- if (useHorizontalAxis) {
906
- const maxScrollLeft = Math.max(0, scrollTarget.scrollWidth - scrollTarget.clientWidth);
907
- const atLeft = scrollTarget.scrollLeft <= 0;
908
- const atRight = scrollTarget.scrollLeft >= maxScrollLeft;
909
- const movingRight = deltaX > 0;
910
- const movingLeft = deltaX < 0;
911
- const canSwipeRight = movingRight && atLeft && allowRight;
912
- const canSwipeLeft = movingLeft && atRight && allowLeft;
913
- return canSwipeRight || canSwipeLeft;
914
- }
915
- return null;
916
- }
917
- const handleStart = useStableCallback(event => {
918
- if (!enabled) {
919
- return;
920
- }
921
- if (event.defaultPrevented || event.nativeEvent.defaultPrevented) {
922
- return;
923
- }
924
- if (!('touches' in event) && event.button !== 0) {
925
- return;
926
- }
927
- const startPos = getPrimaryPointerPosition(event);
928
- if (!startPos) {
929
- return;
930
- }
931
- pendingSwipeRef.current = true;
932
- pendingSwipeStartPosRef.current = startPos;
933
- swipeFromScrollableRef.current = false;
934
- sawPrimaryButtonsOnMoveRef.current = false;
935
- const allowedToStart = canStart ? canStart(startPos, {
936
- nativeEvent: event.nativeEvent,
937
- direction: primaryDirection
938
- }) : true;
939
- if (!allowedToStart) {
940
- return;
941
- }
942
- if (startSwipeAtPosition(event, startPos)) {
943
- clearPendingSwipeStartState();
944
- }
945
- });
946
- function handleMoveCore(event, position, movement) {
947
- if (!enabled || !isSwipingRef.current) {
948
- return;
949
- }
950
- const target = getTarget(event.nativeEvent);
951
- if (isTouchLikeEvent(event) && !swipeFromScrollableRef.current) {
952
- const boundaryElement = event.currentTarget;
953
- if (findGestureScrollableTouchTarget(target, boundaryElement)) {
954
- return;
955
- }
956
- }
957
- if (!('touches' in event)) {
958
- // Prevent text selection on Safari
959
- event.preventDefault();
960
- }
961
- if (isFirstPointerMoveRef.current) {
962
- // Adjust the starting position to the current position on the first move
963
- // to account for the delay between pointerdown and the first pointermove on iOS.
964
- dragStartPosRef.current = position;
965
- const moveTime = getValidTimeStamp(event.timeStamp);
966
- if (moveTime !== null) {
967
- swipeStartTimeRef.current = moveTime;
968
- }
969
- isFirstPointerMoveRef.current = false;
970
- }
971
- const clientX = position.x;
972
- const clientY = position.y;
973
- const movementX = movement.x;
974
- const movementY = movement.y;
975
- if (movementY < 0 && clientY > swipeCancelBaselineRef.current.y || movementY > 0 && clientY < swipeCancelBaselineRef.current.y) {
976
- swipeCancelBaselineRef.current = {
977
- x: swipeCancelBaselineRef.current.x,
978
- y: clientY
979
- };
980
- }
981
- if (movementX < 0 && clientX > swipeCancelBaselineRef.current.x || movementX > 0 && clientX < swipeCancelBaselineRef.current.x) {
982
- swipeCancelBaselineRef.current = {
983
- x: clientX,
984
- y: swipeCancelBaselineRef.current.y
985
- };
986
- }
987
- const deltaX = clientX - dragStartPosRef.current.x;
988
- const deltaY = clientY - dragStartPosRef.current.y;
989
- const cancelDeltaY = clientY - swipeCancelBaselineRef.current.y;
990
- const cancelDeltaX = clientX - swipeCancelBaselineRef.current.x;
991
- let lockedDirection = lockedDirectionRef.current;
992
- if (lockedDirection === null && hasHorizontal && hasVertical) {
993
- const movementDistance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
994
- if (movementDistance >= MIN_DRAG_THRESHOLD) {
995
- lockedDirection = Math.abs(deltaX) > Math.abs(deltaY) ? 'horizontal' : 'vertical';
996
- lockedDirectionRef.current = lockedDirection;
997
- }
998
- }
999
- let candidate;
1000
- if (!intendedSwipeDirectionRef.current) {
1001
- if (lockedDirection === 'vertical') {
1002
- if (deltaY > 0) {
1003
- candidate = 'down';
1004
- } else if (deltaY < 0) {
1005
- candidate = 'up';
1006
- }
1007
- } else if (lockedDirection === 'horizontal') {
1008
- if (deltaX > 0) {
1009
- candidate = 'right';
1010
- } else if (deltaX < 0) {
1011
- candidate = 'left';
1012
- }
1013
- } else if (Math.abs(deltaX) >= Math.abs(deltaY)) {
1014
- candidate = deltaX > 0 ? 'right' : 'left';
1015
- } else {
1016
- candidate = deltaY > 0 ? 'down' : 'up';
1017
- }
1018
- if (candidate) {
1019
- const isAllowed = candidate === 'left' && allowLeft || candidate === 'right' && allowRight || candidate === 'up' && allowUp || candidate === 'down' && allowDown;
1020
- if (isAllowed) {
1021
- intendedSwipeDirectionRef.current = candidate;
1022
- maxSwipeDisplacementRef.current = getDisplacement(candidate, deltaX, deltaY);
1023
- setCurrentSwipeDirection(candidate);
1024
- resolveSwipeThreshold(candidate);
1025
- }
1026
- }
1027
- } else {
1028
- const direction = intendedSwipeDirectionRef.current;
1029
- const currentDisplacement = getDisplacement(direction, cancelDeltaX, cancelDeltaY);
1030
- if (currentDisplacement > swipeThresholdRef.current) {
1031
- cancelledSwipeRef.current = false;
1032
- setCurrentSwipeDirection(direction);
1033
- } else if (!(allowLeft && allowRight) && !(allowUp && allowDown) && maxSwipeDisplacementRef.current - currentDisplacement >= REVERSE_CANCEL_THRESHOLD) {
1034
- // Mark that a change-of-mind has occurred
1035
- cancelledSwipeRef.current = true;
1036
- }
1037
- }
1038
- const dampedDelta = applyDirectionalDamping(deltaX, deltaY);
1039
- let newOffsetX = initialTransformRef.current.x;
1040
- let newOffsetY = initialTransformRef.current.y;
1041
- if (lockedDirection === 'horizontal') {
1042
- if (hasHorizontal) {
1043
- newOffsetX += dampedDelta.x;
1044
- }
1045
- } else if (lockedDirection === 'vertical') {
1046
- if (hasVertical) {
1047
- newOffsetY += dampedDelta.y;
1048
- }
1049
- } else {
1050
- if (hasHorizontal) {
1051
- newOffsetX += dampedDelta.x;
1052
- }
1053
- if (hasVertical) {
1054
- newOffsetY += dampedDelta.y;
1055
- }
1056
- }
1057
- dragOffsetRef.current = {
1058
- x: newOffsetX,
1059
- y: newOffsetY
1060
- };
1061
- syncDragStyles(true);
1062
- recordDragSample({
1063
- x: newOffsetX,
1064
- y: newOffsetY
1065
- }, getValidTimeStamp(event.timeStamp));
1066
- const dragDeltaX = newOffsetX - initialTransformRef.current.x;
1067
- const dragDeltaY = newOffsetY - initialTransformRef.current.y;
1068
- const swipeDirectionDetails = intendedSwipeDirectionRef.current;
1069
- const progressDirection = primaryDirection ?? intendedSwipeDirectionRef.current;
1070
- if (!progressDirection) {
1071
- updateSwipeProgress(0, {
1072
- deltaX: dragDeltaX,
1073
- deltaY: dragDeltaY,
1074
- direction: swipeDirectionDetails
1075
- });
1076
- return;
1077
- }
1078
- const size = progressDirection === 'left' || progressDirection === 'right' ? elementSizeRef.current.width : elementSizeRef.current.height;
1079
- const scale = initialTransformRef.current.scale || 1;
1080
- if (size <= 0 || scale <= 0) {
1081
- updateSwipeProgress(0, {
1082
- deltaX: dragDeltaX,
1083
- deltaY: dragDeltaY,
1084
- direction: swipeDirectionDetails
1085
- });
1086
- return;
1087
- }
1088
- const progressDisplacement = getDisplacement(progressDirection, newOffsetX - initialTransformRef.current.x, newOffsetY - initialTransformRef.current.y);
1089
- if (progressDisplacement <= 0) {
1090
- updateSwipeProgress(0, {
1091
- deltaX: dragDeltaX,
1092
- deltaY: dragDeltaY,
1093
- direction: swipeDirectionDetails
1094
- });
1095
- return;
1096
- }
1097
- updateSwipeProgress(progressDisplacement / (size * scale), {
1098
- deltaX: dragDeltaX,
1099
- deltaY: dragDeltaY,
1100
- direction: swipeDirectionDetails
1101
- });
1102
- }
1103
- const handleEnd = useStableCallback(event => {
1104
- if (!enabled) {
1105
- return;
1106
- }
1107
- const resolvedDragOffset = dragOffsetRef.current;
1108
- const resolvedInitialTransform = initialTransformRef.current;
1109
- const releaseDeltaX = resolvedDragOffset.x - resolvedInitialTransform.x;
1110
- const releaseDeltaY = resolvedDragOffset.y - resolvedInitialTransform.y;
1111
- const progressDetails = {
1112
- deltaX: releaseDeltaX,
1113
- deltaY: releaseDeltaY,
1114
- direction: intendedSwipeDirectionRef.current
1115
- };
1116
- if (!isSwipingRef.current) {
1117
- resetPendingSwipeState();
1118
- updateSwipeProgress(0, progressDetails);
1119
- return;
1120
- }
1121
- setSwiping(false);
1122
- lockedDirectionRef.current = null;
1123
- resetPendingSwipeState();
1124
- sawPrimaryButtonsOnMoveRef.current = false;
1125
- const element = elementRef.current;
1126
- if (element) {
1127
- if (!('touches' in event)) {
1128
- safelyChangePointerCapture(element, event.pointerId, 'releasePointerCapture');
1129
- }
1130
- }
1131
- const deltaX = releaseDeltaX;
1132
- const deltaY = releaseDeltaY;
1133
- const startTime = swipeStartTimeRef.current;
1134
- const endTime = getValidTimeStamp(event.timeStamp);
1135
- const durationMs = startTime !== null && endTime !== null && endTime > startTime ? endTime - startTime : 0;
1136
- const velocityDurationMs = durationMs > 0 ? Math.max(durationMs, MIN_VELOCITY_DURATION_MS) : 0;
1137
- const velocityX = velocityDurationMs > 0 ? deltaX / velocityDurationMs : 0;
1138
- const velocityY = velocityDurationMs > 0 ? deltaY / velocityDurationMs : 0;
1139
- let releaseVelocityX = lastDragVelocityRef.current.x;
1140
- let releaseVelocityY = lastDragVelocityRef.current.y;
1141
- const lastSample = lastDragSampleRef.current;
1142
- if (lastSample && endTime !== null && endTime >= lastSample.time) {
1143
- const ageMs = endTime - lastSample.time;
1144
- if (ageMs <= MAX_RELEASE_VELOCITY_AGE_MS) {
1145
- const sampleDurationMs = Math.max(ageMs, MIN_RELEASE_VELOCITY_DURATION_MS);
1146
- const deltaFromLastSampleX = resolvedDragOffset.x - lastSample.x;
1147
- const deltaFromLastSampleY = resolvedDragOffset.y - lastSample.y;
1148
- const sampleVelocityX = deltaFromLastSampleX / sampleDurationMs;
1149
- const sampleVelocityY = deltaFromLastSampleY / sampleDurationMs;
1150
- if (sampleVelocityX !== 0) {
1151
- releaseVelocityX = sampleVelocityX;
1152
- }
1153
- if (sampleVelocityY !== 0) {
1154
- releaseVelocityY = sampleVelocityY;
1155
- }
1156
- } else {
1157
- releaseVelocityX = 0;
1158
- releaseVelocityY = 0;
1159
- }
1160
- }
1161
- const releaseDecision = onRelease?.({
1162
- event: event.nativeEvent,
1163
- direction: intendedSwipeDirectionRef.current,
1164
- deltaX,
1165
- deltaY,
1166
- velocityX,
1167
- velocityY,
1168
- releaseVelocityX,
1169
- releaseVelocityY
1170
- });
1171
- const hasReleaseDecision = typeof releaseDecision === 'boolean';
1172
- if (cancelledSwipeRef.current && !hasReleaseDecision) {
1173
- dragOffsetRef.current = {
1174
- x: resolvedInitialTransform.x,
1175
- y: resolvedInitialTransform.y
1176
- };
1177
- setCurrentSwipeDirection(undefined);
1178
- syncDragStyles(false);
1179
- updateSwipeProgress(0, progressDetails);
1180
- return;
1181
- }
1182
- let shouldClose = false;
1183
- let dismissDirection;
1184
- if (hasReleaseDecision) {
1185
- shouldClose = releaseDecision;
1186
- dismissDirection = intendedSwipeDirectionRef.current ?? primaryDirection;
1187
- } else {
1188
- for (const direction of directions) {
1189
- switch (direction) {
1190
- case 'right':
1191
- if (deltaX > swipeThresholdRef.current) {
1192
- shouldClose = true;
1193
- dismissDirection = 'right';
1194
- }
1195
- break;
1196
- case 'left':
1197
- if (deltaX < -swipeThresholdRef.current) {
1198
- shouldClose = true;
1199
- dismissDirection = 'left';
1200
- }
1201
- break;
1202
- case 'down':
1203
- if (deltaY > swipeThresholdRef.current) {
1204
- shouldClose = true;
1205
- dismissDirection = 'down';
1206
- }
1207
- break;
1208
- case 'up':
1209
- if (deltaY < -swipeThresholdRef.current) {
1210
- shouldClose = true;
1211
- dismissDirection = 'up';
1212
- }
1213
- break;
1214
- }
1215
- if (shouldClose) {
1216
- break;
1217
- }
1218
- }
1219
- }
1220
- if (shouldClose && dismissDirection) {
1221
- setCurrentSwipeDirection(dismissDirection);
1222
- setDragDismissed(true);
1223
- syncDragStyles(false);
1224
- onDismiss?.(event.nativeEvent, {
1225
- direction: dismissDirection
1226
- });
1227
- } else {
1228
- dragOffsetRef.current = {
1229
- x: resolvedInitialTransform.x,
1230
- y: resolvedInitialTransform.y
1231
- };
1232
- setCurrentSwipeDirection(undefined);
1233
- syncDragStyles(false);
1234
- updateSwipeProgress(0, progressDetails);
1235
- }
1236
- });
1237
- const handleMove = useStableCallback(event => {
1238
- const currentPos = getPrimaryPointerPosition(event);
1239
- if (!currentPos) {
1240
- return;
1241
- }
1242
- let endAfterMove = false;
1243
- if (!('touches' in event)) {
1244
- const hasPrimaryButton = hasPrimaryMouseButton(event.buttons);
1245
- if (hasPrimaryButton) {
1246
- sawPrimaryButtonsOnMoveRef.current = true;
1247
- }
1248
-
1249
- // Cancel the swipe if a non-primary button takes over the interaction.
1250
- // This handles cases where a right-click interrupts dragging.
1251
- if (event.buttons !== 0 && !hasPrimaryButton) {
1252
- cancelSwipeInteraction(event);
1253
- return;
1254
- }
1255
-
1256
- // A `buttons: 0` pointermove means the primary button was already released, so the gesture is
1257
- // over even if no pointerup reached us. On fast trackpad flicks this trailing move is
1258
- // dispatched just before pointerup; treat it as the release (mirroring touchend) instead of
1259
- // cancelling and snapping the element back.
1260
- if (event.buttons === 0 && sawPrimaryButtonsOnMoveRef.current) {
1261
- if (!isSwipingRef.current) {
1262
- // The gesture never activated — discard it.
1263
- handleEnd(event);
1264
- return;
1265
- }
1266
- // This release move can itself carry the threshold-crossing displacement (and the peak
1267
- // release velocity), so let it flow through `handleMoveCore` below to update the drag
1268
- // offset / velocity sample, then commit the release afterwards.
1269
- endAfterMove = true;
1270
- }
1271
- }
1272
- if (!isSwiping && pendingSwipeRef.current) {
1273
- if (!isTouchLikeEvent(event) && (event.defaultPrevented || event.nativeEvent.defaultPrevented)) {
1274
- resetPendingSwipeState();
1275
- return;
1276
- }
1277
- const allowedToStart = canStart ? canStart(currentPos, {
1278
- nativeEvent: event.nativeEvent,
1279
- direction: primaryDirection
1280
- }) : true;
1281
- if (allowedToStart) {
1282
- const pendingStartPos = pendingSwipeStartPosRef.current;
1283
- let ignoreScrollableOnStart = false;
1284
- if (isTouchLikeEvent(event)) {
1285
- const element = elementRef.current;
1286
- if (pendingStartPos && element) {
1287
- const target = getTargetAtPoint(currentPos, event.nativeEvent);
1288
- const doc = ownerDocument(element);
1289
- const body = doc.body;
1290
- const scrollTarget = body ? findGestureScrollableTouchTarget(target, body) : null;
1291
- if (scrollTarget && (contains(element, scrollTarget) || contains(scrollTarget, element))) {
1292
- const deltaX = currentPos.x - pendingStartPos.x;
1293
- const deltaY = currentPos.y - pendingStartPos.y;
1294
- const canSwipeFromEdge = canSwipeFromScrollEdgeOnPendingMove(scrollTarget, deltaX, deltaY);
1295
- if (canSwipeFromEdge === false) {
1296
- return;
1297
- }
1298
- if (canSwipeFromEdge === true) {
1299
- ignoreScrollableOnStart = true;
1300
- }
1301
- }
1302
- }
1303
- }
1304
- const started = startSwipeAtPosition(event, currentPos, {
1305
- ignoreScrollableTarget: ignoreScrollableOnStart,
1306
- ignoreScrollableAncestors: ignoreScrollableOnStart
1307
- });
1308
- if (started) {
1309
- if (pendingStartPos && ignoreScrollableOnStart) {
1310
- // Preserve displacement between touchstart and the move that activates swipe from
1311
- // a scroll-edge so quick flicks can dismiss.
1312
- clearPendingSwipeStartState();
1313
- dragStartPosRef.current = pendingStartPos;
1314
- swipeCancelBaselineRef.current = pendingStartPos;
1315
- lastMovePosRef.current = pendingStartPos;
1316
- isFirstPointerMoveRef.current = false;
1317
- } else {
1318
- // Start from the current in-bounds position without dropping follow-up move
1319
- // displacement; this avoids jumps when entering from outside the element while
1320
- // keeping swipe tracking responsive on the next move.
1321
- clearPendingSwipeStartState();
1322
- swipeFromScrollableRef.current = false;
1323
- }
1324
- }
1325
- }
1326
- }
1327
- const previousPos = lastMovePosRef.current;
1328
- const movement = previousPos === null ? {
1329
- x: 0,
1330
- y: 0
1331
- } : {
1332
- x: currentPos.x - previousPos.x,
1333
- y: currentPos.y - previousPos.y
1334
- };
1335
- lastMovePosRef.current = currentPos;
1336
- handleMoveCore(event, currentPos, movement);
1337
-
1338
- // `endAfterMove` is only set in the non-touch branch above; the `'touches'` guard re-narrows the
1339
- // event type for `handleEnd` after the shared move handling has run.
1340
- if (endAfterMove && !('touches' in event)) {
1341
- handleEnd(event);
1342
- }
1343
- });
1344
-
1345
- // Feeds a native touchmove into the swipe pipeline. Used by consumers that claim the gesture
1346
- // in a capture-phase listener and stop it from reaching React's delegated touch handlers.
1347
- const moveNative = useStableCallback((nativeEvent, currentTarget) => {
1348
- handleMove({
1349
- touches: nativeEvent.touches,
1350
- currentTarget,
1351
- nativeEvent,
1352
- defaultPrevented: nativeEvent.defaultPrevented,
1353
- timeStamp: nativeEvent.timeStamp
1354
- });
1355
- });
1356
- const getDragStyles = React.useCallback(() => {
1357
- const dragOffset = dragOffsetRef.current;
1358
- const initialTransform = initialTransformRef.current;
1359
- const deltaX = dragOffset.x - initialTransform.x;
1360
- const deltaY = dragOffset.y - initialTransform.y;
1361
- if (!isSwiping && deltaX === 0 && deltaY === 0 && !dragDismissed) {
1362
- return {
1363
- [movementCssVars.x]: '0px',
1364
- [movementCssVars.y]: '0px'
1365
- };
1366
- }
1367
- return {
1368
- transition: isSwiping ? 'none' : undefined,
1369
- // While swiping, freeze the element at its current visual transform so it doesn't snap to the
1370
- // end position.
1371
- transform: isSwiping ? getDragTransform(dragOffset, initialTransform.scale) : undefined,
1372
- [movementCssVars.x]: `${deltaX}px`,
1373
- [movementCssVars.y]: `${deltaY}px`
1374
- };
1375
- }, [dragDismissed, isSwiping, movementCssVars]);
1376
- const getPointerProps = React.useCallback(() => {
1377
- if (!enabled) {
1378
- return {};
1379
- }
1380
- return {
1381
- onPointerDown: handleStart,
1382
- onPointerMove: handleMove,
1383
- onPointerUp: handleEnd,
1384
- onPointerCancel: handleEnd
1385
- };
1386
- }, [enabled, handleEnd, handleMove, handleStart]);
1387
- const getTouchProps = React.useCallback(() => {
1388
- if (!enabled) {
1389
- return {};
1390
- }
1391
- return {
1392
- onTouchStart: handleStart,
1393
- onTouchMove: handleMove,
1394
- onTouchEnd: handleEnd,
1395
- onTouchCancel: handleEnd
1396
- };
1397
- }, [enabled, handleEnd, handleMove, handleStart]);
1398
- return {
1399
- swiping: isSwiping,
1400
- swipeDirection: currentSwipeDirection,
1401
- dragDismissed,
1402
- getPointerProps,
1403
- getTouchProps,
1404
- moveNative,
1405
- getDragStyles,
1406
- reset
1407
- };
1408
- }
1409
-
1410
- let DrawerSwipeAreaDataAttributes = function (DrawerSwipeAreaDataAttributes) {
1411
- /**
1412
- * Present when the drawer is open.
1413
- */
1414
- DrawerSwipeAreaDataAttributes[DrawerSwipeAreaDataAttributes["open"] = CommonPopupDataAttributes.open] = "open";
1415
- /**
1416
- * Present when the drawer is closed.
1417
- */
1418
- DrawerSwipeAreaDataAttributes[DrawerSwipeAreaDataAttributes["closed"] = CommonPopupDataAttributes.closed] = "closed";
1419
- /**
1420
- * Present when the swipe area is disabled.
1421
- */
1422
- DrawerSwipeAreaDataAttributes["disabled"] = "data-disabled";
1423
- /**
1424
- * Indicates the swipe direction.
1425
- * @type {'up' | 'down' | 'left' | 'right'}
1426
- */
1427
- DrawerSwipeAreaDataAttributes["swipeDirection"] = "data-swipe-direction";
1428
- /**
1429
- * Present when the drawer is being swiped.
1430
- */
1431
- DrawerSwipeAreaDataAttributes["swiping"] = "data-swiping";
1432
- return DrawerSwipeAreaDataAttributes;
1433
- }({});
1434
-
1435
- const DEFAULT_SWIPE_OPEN_RATIO = 0.5;
1436
- const MIN_SWIPE_START_DISTANCE = 1;
1437
- const VELOCITY_THRESHOLD = 0.1;
1438
- const FALLBACK_SWIPE_OPEN_THRESHOLD = 40;
1439
- const SWIPE_AREA_OPEN_HOOK = {
1440
- [DrawerSwipeAreaDataAttributes.open]: ''
1441
- };
1442
- const SWIPE_AREA_CLOSED_HOOK = {
1443
- [DrawerSwipeAreaDataAttributes.closed]: ''
1444
- };
1445
- const SWIPE_AREA_SWIPING_HOOK = {
1446
- [DrawerSwipeAreaDataAttributes.swiping]: ''
1447
- };
1448
- const SWIPE_AREA_DISABLED_HOOK = {
1449
- [DrawerSwipeAreaDataAttributes.disabled]: ''
1450
- };
1451
- const stateAttributesMapping$3 = {
1452
- open(value) {
1453
- return value ? SWIPE_AREA_OPEN_HOOK : SWIPE_AREA_CLOSED_HOOK;
1454
- },
1455
- swiping(value) {
1456
- return value ? SWIPE_AREA_SWIPING_HOOK : null;
1457
- },
1458
- swipeDirection(value) {
1459
- return value ? {
1460
- [DrawerSwipeAreaDataAttributes.swipeDirection]: value
1461
- } : null;
1462
- },
1463
- disabled(value) {
1464
- return value ? SWIPE_AREA_DISABLED_HOOK : null;
1465
- }
1466
- };
1467
- const oppositeSwipeDirection = {
1468
- up: 'down',
1469
- down: 'up',
1470
- left: 'right',
1471
- right: 'left'
1472
- };
1473
- function resolveTouchAction(direction) {
1474
- return direction === 'left' || direction === 'right' ? 'pan-y' : 'pan-x';
1475
- }
1476
-
1477
- /**
1478
- * An invisible area that listens for swipe gestures to open the drawer.
1479
- * Renders a `<div>` element.
1480
- *
1481
- * Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
1482
- */
1483
- const DrawerSwipeArea = /*#__PURE__*/React.forwardRef(function DrawerSwipeArea(componentProps, forwardedRef) {
1484
- const {
1485
- render,
1486
- className,
1487
- style,
1488
- disabled = false,
1489
- swipeDirection: swipeDirectionProp,
1490
- ...elementProps
1491
- } = componentProps;
1492
- const {
1493
- store
1494
- } = useDialogRootContext();
1495
- const {
1496
- swipeDirection,
1497
- frontmostHeight
1498
- } = useDrawerRootContext();
1499
- const providerContext = useDrawerProviderContext();
1500
- const [swipeActive, setSwipeActive] = React.useState(false);
1501
- const releaseDismissTimeout = useTimeout();
1502
- const swipeAreaRef = React.useRef(null);
1503
- const swipeStartEventRef = React.useRef(null);
1504
- const openedBySwipeRef = React.useRef(false);
1505
- const dragDeltaRef = React.useRef({
1506
- x: 0,
1507
- y: 0
1508
- });
1509
- const closedOffsetRef = React.useRef(null);
1510
- const appliedSwipeStylesRef = React.useRef(false);
1511
- const popupTransitionRef = React.useRef(null);
1512
- const swipeAreaId = useBaseUiId(componentProps.id);
1513
- const registerTrigger = useTriggerRegistration(swipeAreaId, store);
1514
- const open = store.useState('open');
1515
- const resetDragDelta = useStableCallback(() => {
1516
- dragDeltaRef.current.x = 0;
1517
- dragDeltaRef.current.y = 0;
1518
- });
1519
- const resolvedSwipeDirection = swipeDirectionProp ?? oppositeSwipeDirection[swipeDirection];
1520
- const dismissDirection = oppositeSwipeDirection[resolvedSwipeDirection];
1521
- const enabled = !disabled && (!open || swipeActive);
1522
- function disableDismissForSwipe() {
1523
- releaseDismissTimeout.clear();
1524
- store.context.outsidePressEnabledRef.current = false;
1525
- }
1526
- function enableDismissAfterRelease() {
1527
- // Safari can dispatch outside-press for the same swipe-open gesture
1528
- // after release, so defer re-enabling dismissal to the next macrotask.
1529
- releaseDismissTimeout.start(0, () => {
1530
- store.context.outsidePressEnabledRef.current = true;
1531
- });
1532
- }
1533
- function resolvePopupSize() {
1534
- const popupElement = store.context.popupRef.current;
1535
- if (!popupElement) {
1536
- return null;
1537
- }
1538
- const isHorizontal = dismissDirection === 'left' || dismissDirection === 'right';
1539
- const size = isHorizontal ? popupElement.offsetWidth : popupElement.offsetHeight;
1540
- if (size <= 0) {
1541
- return null;
1542
- }
1543
- return size;
1544
- }
1545
- function resolveClosedOffset() {
1546
- const offset = resolvePopupSize();
1547
- if (offset == null) {
1548
- return null;
1549
- }
1550
- const popupElement = store.context.popupRef.current;
1551
- if (!popupElement) {
1552
- return offset;
1553
- }
1554
- const isHorizontal = dismissDirection === 'left' || dismissDirection === 'right';
1555
- const transform = getElementTransform(popupElement);
1556
- const transformOffset = isHorizontal ? transform.x : transform.y;
1557
- if (Number.isFinite(transformOffset) && Math.abs(transformOffset) > 0.5) {
1558
- return Math.min(offset, Math.abs(transformOffset));
1559
- }
1560
- return offset;
1561
- }
1562
- function resolveSwipeOpenThreshold() {
1563
- const popupSize = resolvePopupSize();
1564
- if (popupSize == null) {
1565
- return FALLBACK_SWIPE_OPEN_THRESHOLD;
1566
- }
1567
- return popupSize * DEFAULT_SWIPE_OPEN_RATIO;
1568
- }
1569
- function applySwipeMovement() {
1570
- if (!swipeActive) {
1571
- return;
1572
- }
1573
- const popupElement = store.context.popupRef.current;
1574
- if (!popupElement) {
1575
- return;
1576
- }
1577
- if (!store.select('open') || !store.select('mounted')) {
1578
- return;
1579
- }
1580
- if (closedOffsetRef.current == null) {
1581
- closedOffsetRef.current = resolveClosedOffset();
1582
- }
1583
- const closedOffset = closedOffsetRef.current;
1584
- if (!closedOffset || !Number.isFinite(closedOffset) || closedOffset <= 0) {
573
+ const closedOffset = closedOffsetRef.current;
574
+ if (!closedOffset || !Number.isFinite(closedOffset) || closedOffset <= 0) {
1585
575
  return;
1586
576
  }
1587
577
  const {
@@ -1684,865 +674,98 @@ const DrawerSwipeArea = /*#__PURE__*/React.forwardRef(function DrawerSwipeArea(c
1684
674
  swipeStartEventRef.current = event;
1685
675
  openedBySwipeRef.current = false;
1686
676
  setSwipeActive(true);
1687
- resetDragDelta();
1688
- },
1689
- onProgress(_progress, details) {
1690
- if (!details) {
1691
- return;
1692
- }
1693
- if (!swipeStartEventRef.current) {
1694
- return;
1695
- }
1696
- dragDeltaRef.current.x = details.deltaX;
1697
- dragDeltaRef.current.y = details.deltaY;
1698
- if (details.direction !== resolvedSwipeDirection) {
1699
- return;
1700
- }
1701
- const displacement = getDisplacement(resolvedSwipeDirection, details.deltaX, details.deltaY);
1702
- if (displacement < MIN_SWIPE_START_DISTANCE && !openedBySwipeRef.current) {
1703
- return;
1704
- }
1705
- if (!openedBySwipeRef.current) {
1706
- openDrawer(swipeStartEventRef.current);
1707
- }
1708
- applySwipeMovement();
1709
- },
1710
- onRelease({
1711
- event,
1712
- direction,
1713
- deltaX,
1714
- deltaY,
1715
- releaseVelocityX,
1716
- releaseVelocityY
1717
- }) {
1718
- const displacement = getDisplacement(resolvedSwipeDirection, deltaX, deltaY);
1719
- const releaseVelocity = getDisplacement(resolvedSwipeDirection, releaseVelocityX, releaseVelocityY);
1720
- const threshold = resolveSwipeOpenThreshold();
1721
- const hasEnoughDistance = threshold != null && displacement >= threshold;
1722
- const hasEnoughVelocity = releaseVelocity >= VELOCITY_THRESHOLD;
1723
- const shouldOpen = threshold != null && direction === resolvedSwipeDirection && (hasEnoughDistance || hasEnoughVelocity) && !disabled;
1724
- if (shouldOpen) {
1725
- if (!store.select('open')) {
1726
- openDrawer(event);
1727
- }
1728
- } else if (openedBySwipeRef.current) {
1729
- closeDrawer(event);
1730
- }
1731
- finishSwipeInteraction();
1732
- return false;
1733
- },
1734
- onCancel: finishSwipeInteraction
1735
- });
1736
- const swipePointerProps = swipe$1.getPointerProps();
1737
- const swipeTouchProps = swipe$1.getTouchProps();
1738
- const resetSwipe = swipe$1.reset;
1739
- React.useEffect(() => {
1740
- if (!enabled) {
1741
- resetSwipe();
1742
- resetDragDelta();
1743
- clearSwipeStyles();
1744
- resetSwipeInteractionState();
1745
- }
1746
- }, [clearSwipeStyles, enabled, resetDragDelta, resetSwipe]);
1747
- React.useEffect(() => {
1748
- return () => {
1749
- store.context.outsidePressEnabledRef.current = true;
1750
- };
1751
- }, [store]);
1752
- const state = {
1753
- open,
1754
- swiping: swipe$1.swiping,
1755
- swipeDirection: resolvedSwipeDirection,
1756
- disabled
1757
- };
1758
- return useRenderElement('div', componentProps, {
1759
- state,
1760
- ref: [forwardedRef, swipeAreaRef, registerTrigger],
1761
- stateAttributesMapping: stateAttributesMapping$3,
1762
- props: [{
1763
- role: 'presentation',
1764
- 'aria-hidden': true,
1765
- style: {
1766
- pointerEvents: !enabled ? 'none' : undefined,
1767
- touchAction: resolveTouchAction(resolvedSwipeDirection)
1768
- },
1769
- onPointerDown(event) {
1770
- if (event.pointerType === 'touch') {
1771
- return;
1772
- }
1773
- swipePointerProps.onPointerDown?.(event);
1774
-
1775
- // Prevent native text selection/drag gestures from competing with swipe-open dragging.
1776
- if (event.cancelable) {
1777
- event.preventDefault();
1778
- }
1779
- },
1780
- onPointerMove(event) {
1781
- if (event.pointerType === 'touch') {
1782
- return;
1783
- }
1784
- swipePointerProps.onPointerMove?.(event);
1785
- },
1786
- onPointerUp(event) {
1787
- if (event.pointerType === 'touch') {
1788
- return;
1789
- }
1790
- swipePointerProps.onPointerUp?.(event);
1791
- },
1792
- onPointerCancel(event) {
1793
- if (event.pointerType === 'touch') {
1794
- return;
1795
- }
1796
- swipePointerProps.onPointerCancel?.(event);
1797
- }
1798
- }, swipeTouchProps, swipeAreaId ? {
1799
- id: swipeAreaId
1800
- } : undefined, elementProps]
1801
- });
1802
- });
1803
- if (process.env.NODE_ENV !== "production") DrawerSwipeArea.displayName = "DrawerSwipeArea";
1804
-
1805
- const DrawerVirtualKeyboardContext = /*#__PURE__*/React.createContext(undefined);
1806
- if (process.env.NODE_ENV !== "production") DrawerVirtualKeyboardContext.displayName = "DrawerVirtualKeyboardContext";
1807
- function useDrawerVirtualKeyboardContext() {
1808
- return React.useContext(DrawerVirtualKeyboardContext);
1809
- }
1810
-
1811
- const MIN_SWIPE_THRESHOLD = 10;
1812
- const FAST_SWIPE_VELOCITY = 0.5;
1813
- const SNAP_VELOCITY_THRESHOLD = 0.5;
1814
- const SNAP_VELOCITY_MULTIPLIER = 300;
1815
- const MAX_SNAP_VELOCITY = 4;
1816
- const MIN_SWIPE_RELEASE_VELOCITY = 0.2;
1817
- const MAX_SWIPE_RELEASE_VELOCITY = 4;
1818
- const MIN_SWIPE_RELEASE_DURATION_MS = 80;
1819
- const MAX_SWIPE_RELEASE_DURATION_MS = 360;
1820
- const MIN_SWIPE_RELEASE_SCALAR = 0.1;
1821
- const MAX_SWIPE_RELEASE_SCALAR = 1;
1822
- const DRAWER_CONTENT_SELECTOR = `[${DRAWER_CONTENT_ATTRIBUTE}]`;
1823
- /**
1824
- * A positioning container for the drawer popup that can be made scrollable.
1825
- * Renders a `<div>` element.
1826
- *
1827
- * Documentation: [Base UI Drawer](https://base-ui.com/react/components/drawer)
1828
- */
1829
- const DrawerViewport = /*#__PURE__*/React.forwardRef(function DrawerViewport(props, forwardedRef) {
1830
- const {
1831
- render,
1832
- className,
1833
- style,
1834
- children,
1835
- ...elementProps
1836
- } = props;
1837
- const {
1838
- store
1839
- } = useDialogRootContext();
1840
- const popupRef = store.context.popupRef;
1841
- const backdropRef = store.context.backdropRef;
1842
- const {
1843
- swipeDirection,
1844
- notifyParentSwipingChange,
1845
- notifyParentSwipeProgressChange,
1846
- frontmostHeight,
1847
- snapToSequentialPoints
1848
- } = useDrawerRootContext();
1849
- const providerContext = useDrawerProviderContext();
1850
- const {
1851
- snapPoints,
1852
- resolvedSnapPoints,
1853
- activeSnapPoint,
1854
- activeSnapPointOffset,
1855
- setActiveSnapPoint,
1856
- popupHeight
1857
- } = useDrawerSnapPoints();
1858
- const open = store.useState('open');
1859
- const mounted = store.useState('mounted');
1860
- const nested = store.useState('nested');
1861
- const nestedOpenDrawerCount = store.useState('nestedOpenDrawerCount');
1862
- const viewportElement = store.useState('viewportElement');
1863
- const popupElementState = store.useState('popupElement');
1864
- const visualStateStore = providerContext?.visualStateStore;
1865
- const nestedDrawerOpen = nestedOpenDrawerCount > 0;
1866
- const scrollAxis = swipeDirection === 'left' || swipeDirection === 'right' ? 'horizontal' : 'vertical';
1867
- const isVerticalScrollAxis = scrollAxis === 'vertical';
1868
- const crossScrollAxis = isVerticalScrollAxis ? 'horizontal' : 'vertical';
1869
- const [swipeRelease, setSwipeRelease] = React.useState(null);
1870
- const pendingSwipeCloseSnapPointRef = React.useRef(undefined);
1871
- const resetSwipeRef = React.useRef(null);
1872
- const controlledDismissFrame = useAnimationFrame();
1873
- const swipingRef = React.useRef(false);
1874
- const nestedSwipeActiveRef = React.useRef(false);
1875
- const lastPointerTypeRef = React.useRef('');
1876
- const ignoreNextTouchStartFromPenRef = React.useRef(false);
1877
- const ignoreTouchSwipeRef = React.useRef(false);
1878
- const touchScrollStateRef = React.useRef(null);
1879
- const virtualKeyboard = useDrawerVirtualKeyboardContext();
1880
- const snapPointRange = React.useMemo(() => {
1881
- if (!snapPoints || snapPoints.length < 2) {
1882
- return null;
1883
- }
1884
- if (swipeDirection !== 'down' && swipeDirection !== 'up') {
1885
- return null;
1886
- }
1887
- if (resolvedSnapPoints.length < 2) {
1888
- return null;
1889
- }
1890
- const offsets = resolvedSnapPoints.map(point => point.offset).filter(offset => Number.isFinite(offset)).sort((a, b) => a - b);
1891
- if (offsets.length < 2) {
1892
- return null;
1893
- }
1894
- const minOffset = offsets[0];
1895
- const nextOffset = offsets[1];
1896
- const maxOffset = offsets[offsets.length - 1];
1897
- let range = nextOffset - minOffset;
1898
- if (!Number.isFinite(range) || range <= 0) {
1899
- const fallbackRange = maxOffset - minOffset;
1900
- if (!Number.isFinite(fallbackRange) || fallbackRange <= 0) {
1901
- return null;
1902
- }
1903
- range = fallbackRange;
1904
- }
1905
- return {
1906
- minOffset,
1907
- range
1908
- };
1909
- }, [resolvedSnapPoints, snapPoints, swipeDirection]);
1910
- const snapPointProgress = React.useMemo(() => {
1911
- if (!snapPointRange || activeSnapPointOffset === null) {
1912
- return null;
1913
- }
1914
- return clamp((activeSnapPointOffset - snapPointRange.minOffset) / snapPointRange.range, 0, 1);
1915
- }, [activeSnapPointOffset, snapPointRange]);
1916
- const swipeDirections = React.useMemo(() => {
1917
- if (snapPoints && snapPoints.length > 0 && (swipeDirection === 'down' || swipeDirection === 'up')) {
1918
- return swipeDirection === 'down' ? ['down', 'up'] : ['up', 'down'];
1919
- }
1920
- return [swipeDirection];
1921
- }, [snapPoints, swipeDirection]);
1922
- const setSwipeDismissed = useStableCallback(dismissed => {
1923
- setSwipeDismissedElements(popupRef.current, backdropRef.current, dismissed);
1924
- });
1925
- const clearSwipeRelease = useStableCallback(() => {
1926
- setSwipeDismissed(false);
1927
- popupRef.current?.removeAttribute(TransitionStatusDataAttributes.endingStyle);
1928
- setSwipeRelease(null);
1929
- });
1930
- const finishNestedSwipe = useStableCallback(() => {
1931
- if (!nestedSwipeActiveRef.current) {
1932
- return;
1933
- }
1934
- nestedSwipeActiveRef.current = false;
1935
- notifyParentSwipingChange?.(false);
1936
- });
1937
- const applySwipeProgress = useStableCallback(({
1938
- resolvedProgress,
1939
- shouldTrackProgress,
1940
- notifyParent
1941
- }) => {
1942
- const isActive = open && !nested && shouldTrackProgress;
1943
- const swipeProgress = isActive ? resolvedProgress : 0;
1944
- const nestedSwipeProgress = open && shouldTrackProgress ? resolvedProgress : 0;
1945
- if (notifyParent && notifyParentSwipeProgressChange) {
1946
- notifyParentSwipeProgressChange(nestedSwipeProgress);
1947
- if (nestedSwipeProgress <= 0) {
1948
- finishNestedSwipe();
1949
- }
1950
- }
1951
- visualStateStore?.set({
1952
- swipeProgress,
1953
- frontmostHeight: swipeProgress > 0 ? frontmostHeight : 0
1954
- });
1955
- const backdropElement = backdropRef.current;
1956
- if (!backdropElement) {
1957
- return;
1958
- }
1959
- if (!isActive || swipeProgress <= 0) {
1960
- backdropElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, '0');
1961
- backdropElement.style.removeProperty(DrawerPopupCssVars.height);
1962
- return;
1963
- }
1964
- backdropElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, `${swipeProgress}`);
1965
- if (frontmostHeight > 0) {
1966
- backdropElement.style.setProperty(DrawerPopupCssVars.height, `${frontmostHeight}px`);
1967
- } else {
1968
- backdropElement.style.removeProperty(DrawerPopupCssVars.height);
1969
- }
1970
- });
1971
- function resolveSwipeRelease({
1972
- direction,
1973
- deltaX,
1974
- deltaY,
1975
- velocityX,
1976
- velocityY,
1977
- releaseVelocityX,
1978
- releaseVelocityY
1979
- }) {
1980
- if (!direction) {
1981
- return null;
1982
- }
1983
- const popupElement = store.context.popupRef.current;
1984
- if (!popupElement) {
1985
- return null;
1986
- }
1987
- const size = direction === 'left' || direction === 'right' ? popupElement.offsetWidth : popupElement.offsetHeight;
1988
- if (!Number.isFinite(size) || size <= 0) {
1989
- return null;
1990
- }
1991
- const axisDelta = direction === 'left' || direction === 'right' ? deltaX : deltaY;
1992
- const snapPointBaseOffset = snapPoints && snapPoints.length > 0 ? activeSnapPointOffset ?? 0 : 0;
1993
- let baseOffset = 0;
1994
- if (direction === 'down') {
1995
- baseOffset = snapPointBaseOffset;
1996
- } else if (direction === 'up') {
1997
- baseOffset = -snapPointBaseOffset;
1998
- }
1999
- const translation = baseOffset + axisDelta;
2000
- const translationAlongDirection = direction === 'left' || direction === 'up' ? -translation : translation;
2001
- const remainingDistance = Math.max(0, size - translationAlongDirection);
2002
- if (!Number.isFinite(remainingDistance) || remainingDistance <= 0) {
2003
- return null;
2004
- }
2005
- const axisVelocity = direction === 'left' || direction === 'right' ? releaseVelocityX : releaseVelocityY;
2006
- const fallbackVelocity = direction === 'left' || direction === 'right' ? velocityX : velocityY;
2007
- const resolvedVelocity = Math.abs(axisVelocity) > 0 && Number.isFinite(axisVelocity) ? axisVelocity : fallbackVelocity;
2008
- const directionalVelocity = direction === 'left' || direction === 'up' ? -resolvedVelocity : resolvedVelocity;
2009
- if (!Number.isFinite(directionalVelocity) || directionalVelocity <= MIN_SWIPE_RELEASE_VELOCITY) {
2010
- return null;
2011
- }
2012
- const clampedVelocity = clamp(directionalVelocity, MIN_SWIPE_RELEASE_VELOCITY, MAX_SWIPE_RELEASE_VELOCITY);
2013
- const durationMs = clamp(remainingDistance / clampedVelocity, MIN_SWIPE_RELEASE_DURATION_MS, MAX_SWIPE_RELEASE_DURATION_MS);
2014
- if (!Number.isFinite(durationMs)) {
2015
- return null;
2016
- }
2017
- const normalizedDuration = (durationMs - MIN_SWIPE_RELEASE_DURATION_MS) / (MAX_SWIPE_RELEASE_DURATION_MS - MIN_SWIPE_RELEASE_DURATION_MS);
2018
- const durationScalar = clamp(MIN_SWIPE_RELEASE_SCALAR + normalizedDuration * (MAX_SWIPE_RELEASE_SCALAR - MIN_SWIPE_RELEASE_SCALAR), MIN_SWIPE_RELEASE_SCALAR, MAX_SWIPE_RELEASE_SCALAR);
2019
- if (!Number.isFinite(durationScalar) || durationScalar <= 0) {
2020
- return null;
2021
- }
2022
- return durationScalar;
2023
- }
2024
- function updateNestedSwipeActive(details) {
2025
- if (nestedSwipeActiveRef.current || !details) {
2026
- return;
2027
- }
2028
- const direction = details.direction ?? swipeDirection;
2029
- const delta = direction === 'left' || direction === 'right' ? details.deltaX : details.deltaY;
2030
- if (!Number.isFinite(delta) || Math.abs(delta) < MIN_SWIPE_THRESHOLD) {
2031
- return;
2032
- }
2033
- nestedSwipeActiveRef.current = true;
2034
- notifyParentSwipingChange?.(true);
2035
- }
2036
- const swipe$1 = useSwipeDismiss({
2037
- enabled: mounted && !nestedDrawerOpen,
2038
- directions: swipeDirections,
2039
- elementRef: store.context.popupRef,
2040
- ignoreSelectorWhenTouch: false,
2041
- ignoreScrollableAncestors: true,
2042
- movementCssVars: {
2043
- x: DrawerPopupCssVars.swipeMovementX,
2044
- y: DrawerPopupCssVars.swipeMovementY
2045
- },
2046
- onSwipeStart(event) {
2047
- if ('touches' in event || 'pointerType' in event && event.pointerType === 'touch') {
2048
- return;
2049
- }
2050
- const popupElement = popupRef.current;
2051
- if (!popupElement) {
2052
- return;
2053
- }
2054
- const doc = ownerDocument(popupElement);
2055
- const selection = doc.getSelection?.();
2056
- if (!selection || selection.isCollapsed) {
2057
- return;
2058
- }
2059
- const anchorElement = isElement(selection.anchorNode) ? selection.anchorNode : selection.anchorNode?.parentElement;
2060
- const focusElement = isElement(selection.focusNode) ? selection.focusNode : selection.focusNode?.parentElement;
2061
- if (!contains(popupElement, anchorElement) && !contains(popupElement, focusElement)) {
2062
- return;
2063
- }
2064
- selection.removeAllRanges();
2065
- },
2066
- onSwipingChange(swiping) {
2067
- swipingRef.current = swiping;
2068
- setBackdropSwipingAttribute(store.context.backdropRef.current, swiping);
2069
- if (!swiping && !notifyParentSwipeProgressChange) {
2070
- finishNestedSwipe();
2071
- }
2072
- },
2073
- swipeThreshold({
2074
- element,
2075
- direction
2076
- }) {
2077
- return getBaseSwipeThreshold(element, direction);
2078
- },
2079
- canStart(position, details) {
2080
- const popupElement = store.context.popupRef.current;
2081
- if (!popupElement) {
2082
- return false;
2083
- }
2084
- const doc = popupElement.ownerDocument;
2085
- const elementAtPoint = getElementAtPoint(doc, position.x, position.y);
2086
- if (!elementAtPoint || !contains(popupElement, elementAtPoint)) {
2087
- return false;
677
+ resetDragDelta();
678
+ },
679
+ onProgress(_progress, details) {
680
+ if (!details) {
681
+ return;
2088
682
  }
2089
- const nativeEvent = details.nativeEvent;
2090
- const touchLike = 'touches' in nativeEvent || 'pointerType' in nativeEvent && nativeEvent.pointerType === 'touch';
2091
- if (touchLike && shouldIgnoreSwipeForTextSelection(doc, popupElement)) {
2092
- return false;
683
+ if (!swipeStartEventRef.current) {
684
+ return;
2093
685
  }
2094
- if (nativeEvent.type === 'touchstart' && isSwipeIgnoredTarget(elementAtPoint)) {
2095
- return false;
686
+ dragDeltaRef.current.x = details.deltaX;
687
+ dragDeltaRef.current.y = details.deltaY;
688
+ if (details.direction !== resolvedSwipeDirection) {
689
+ return;
2096
690
  }
2097
- return true;
2098
- },
2099
- onProgress(progress, details) {
2100
- updateNestedSwipeActive(details);
2101
- const hasSnapPoints = Boolean(snapPoints && snapPoints.length > 0);
2102
- if (swipingRef.current && swipeDirection === 'down' && hasSnapPoints && details && Number.isFinite(details.deltaY)) {
2103
- const popupElement = store.context.popupRef.current;
2104
- if (popupElement) {
2105
- popupElement.style.removeProperty('transform');
2106
- popupElement.style.setProperty(DrawerPopupCssVars.swipeMovementY, `${getSnapPointSwipeMovement(activeSnapPointOffset ?? 0, details.deltaY)}px`);
2107
- }
691
+ const displacement = getDisplacement(resolvedSwipeDirection, details.deltaX, details.deltaY);
692
+ if (displacement < MIN_SWIPE_START_DISTANCE && !openedBySwipeRef.current) {
693
+ return;
2108
694
  }
2109
- const currentDirection = details?.direction ?? swipe$1.swipeDirection;
2110
- const isDismissSwipe = currentDirection === undefined || currentDirection === swipeDirection;
2111
- const isVerticalSwipe = swipeDirection === 'down' || swipeDirection === 'up';
2112
- const shouldTrackProgress = hasSnapPoints && isVerticalSwipe || !hasSnapPoints || swipeDirection === 'left' || swipeDirection === 'right' || isDismissSwipe;
2113
- let resolvedProgress = progress;
2114
- if (snapPointRange && popupHeight > 0) {
2115
- if (details && Number.isFinite(details.deltaY)) {
2116
- const baseOffset = activeSnapPointOffset ?? snapPointRange.minOffset;
2117
- const nextOffset = clamp(baseOffset + details.deltaY, 0, popupHeight);
2118
- resolvedProgress = clamp((nextOffset - snapPointRange.minOffset) / snapPointRange.range, 0, 1);
2119
- } else if (snapPointProgress !== null) {
2120
- resolvedProgress = snapPointProgress;
2121
- } else if (currentDirection === 'down' || currentDirection === 'up') {
2122
- const displacement = progress * popupHeight;
2123
- const baseOffset = activeSnapPointOffset ?? snapPointRange.minOffset;
2124
- const nextOffset = currentDirection === 'down' ? baseOffset + displacement : baseOffset - displacement;
2125
- resolvedProgress = clamp((nextOffset - snapPointRange.minOffset) / snapPointRange.range, 0, 1);
2126
- }
695
+ if (!openedBySwipeRef.current) {
696
+ openDrawer(swipeStartEventRef.current);
2127
697
  }
2128
- applySwipeProgress({
2129
- resolvedProgress,
2130
- shouldTrackProgress,
2131
- notifyParent: true
2132
- });
698
+ applySwipeMovement();
2133
699
  },
2134
700
  onRelease({
2135
701
  event,
702
+ direction,
2136
703
  deltaX,
2137
704
  deltaY,
2138
- direction,
2139
- velocityX,
2140
- velocityY,
2141
705
  releaseVelocityX,
2142
706
  releaseVelocityY
2143
707
  }) {
2144
- const swipeReleasePayload = {
2145
- deltaX,
2146
- deltaY,
2147
- velocityX,
2148
- velocityY,
2149
- releaseVelocityX,
2150
- releaseVelocityY
2151
- };
2152
- function startSwipeRelease(resolvedDirection) {
2153
- // Start ending transition styles earlier and synchronously to prevent a period where
2154
- // the popup appears stuck on release before the actual closing animation starts.
2155
- const popupElement = store.context.popupRef.current;
2156
- if (!popupElement) {
2157
- return;
2158
- }
2159
- finishNestedSwipe();
2160
- setSwipeDismissed(true);
2161
- popupElement.style.removeProperty('transition');
2162
- popupElement.setAttribute(TransitionStatusDataAttributes.endingStyle, '');
2163
- ReactDOM.flushSync(() => {
2164
- setSwipeRelease(resolveSwipeRelease({
2165
- direction: resolvedDirection,
2166
- ...swipeReleasePayload
2167
- }));
2168
- });
2169
- }
2170
- if (!snapPoints || snapPoints.length === 0) {
2171
- if (!direction) {
2172
- clearSwipeRelease();
2173
- return undefined;
2174
- }
2175
- const element = store.context.popupRef.current;
2176
- if (!element) {
2177
- clearSwipeRelease();
2178
- return undefined;
2179
- }
2180
- const baseThreshold = getBaseSwipeThreshold(element, direction);
2181
- const delta = direction === 'left' || direction === 'right' ? deltaX : deltaY;
2182
- if (!Number.isFinite(delta)) {
2183
- clearSwipeRelease();
2184
- return undefined;
2185
- }
2186
- const directionalDelta = direction === 'left' || direction === 'up' ? -delta : delta;
2187
- if (directionalDelta <= 0) {
2188
- clearSwipeRelease();
2189
- return false;
2190
- }
2191
- const velocity = direction === 'left' || direction === 'right' ? velocityX : velocityY;
2192
- const directionalVelocity = direction === 'left' || direction === 'up' ? -velocity : velocity;
2193
- if (directionalVelocity >= FAST_SWIPE_VELOCITY && directionalDelta > 0) {
2194
- startSwipeRelease(direction);
2195
- return true;
2196
- }
2197
- const shouldClose = directionalDelta > baseThreshold;
2198
- if (shouldClose) {
2199
- startSwipeRelease(direction);
2200
- } else {
2201
- clearSwipeRelease();
2202
- }
2203
- return shouldClose;
2204
- }
2205
- if (swipeDirection !== 'down' && swipeDirection !== 'up') {
2206
- clearSwipeRelease();
2207
- return undefined;
2208
- }
2209
- if (!popupHeight || resolvedSnapPoints.length === 0) {
2210
- clearSwipeRelease();
2211
- return undefined;
2212
- }
2213
- const dragDelta = swipeDirection === 'down' ? deltaY : -deltaY;
2214
- if (!Number.isFinite(dragDelta)) {
2215
- clearSwipeRelease();
2216
- return undefined;
2217
- }
2218
- const dragDirection = Math.sign(dragDelta);
2219
- const releaseDirectionalVelocity = swipeDirection === 'down' ? releaseVelocityY : -releaseVelocityY;
2220
- const fallbackDirectionalVelocity = swipeDirection === 'down' ? velocityY : -velocityY;
2221
- let resolvedDirectionalVelocity = Number.isFinite(releaseDirectionalVelocity) ? releaseDirectionalVelocity : fallbackDirectionalVelocity;
2222
- if (dragDirection !== 0 && Math.abs(dragDelta) >= MIN_SWIPE_THRESHOLD && Number.isFinite(resolvedDirectionalVelocity)) {
2223
- const velocityDirection = Math.sign(resolvedDirectionalVelocity);
2224
- if (velocityDirection !== 0 && velocityDirection !== dragDirection) {
2225
- // Ignore touch reversals that would otherwise flip the snap decision.
2226
- resolvedDirectionalVelocity = fallbackDirectionalVelocity;
2227
- }
2228
- }
2229
- const currentOffset = activeSnapPointOffset ?? 0;
2230
- const dragTargetOffset = clamp(currentOffset + dragDelta, 0, popupHeight);
2231
- const velocityOffset = Number.isFinite(resolvedDirectionalVelocity) && Math.abs(resolvedDirectionalVelocity) >= SNAP_VELOCITY_THRESHOLD ? clamp(resolvedDirectionalVelocity, -MAX_SNAP_VELOCITY, MAX_SNAP_VELOCITY) * SNAP_VELOCITY_MULTIPLIER : 0;
2232
- const targetOffset = snapToSequentialPoints ? dragTargetOffset : clamp(dragTargetOffset + velocityOffset, 0, popupHeight);
2233
- const snapPointEventDetails = createChangeEventDetails(swipe, event);
2234
- const closeFromSnapPoints = () => {
2235
- pendingSwipeCloseSnapPointRef.current = activeSnapPoint;
2236
- setActiveSnapPoint?.(null, snapPointEventDetails);
2237
- startSwipeRelease(swipeDirection);
2238
- return true;
2239
- };
2240
- if (snapToSequentialPoints) {
2241
- const orderedSnapPoints = [...resolvedSnapPoints].sort((first, second) => first.offset - second.offset);
2242
- if (orderedSnapPoints.length === 0) {
2243
- clearSwipeRelease();
2244
- return false;
2245
- }
2246
- let currentIndex = 0;
2247
- let closestDistance = Math.abs(currentOffset - orderedSnapPoints[0].offset);
2248
- for (let index = 1; index < orderedSnapPoints.length; index += 1) {
2249
- const distance = Math.abs(currentOffset - orderedSnapPoints[index].offset);
2250
- if (distance < closestDistance) {
2251
- closestDistance = distance;
2252
- currentIndex = index;
2253
- }
2254
- }
2255
- let targetSnapPoint = orderedSnapPoints[0];
2256
- closestDistance = Math.abs(targetOffset - targetSnapPoint.offset);
2257
- for (const snapPoint of orderedSnapPoints) {
2258
- const distance = Math.abs(targetOffset - snapPoint.offset);
2259
- if (distance < closestDistance) {
2260
- closestDistance = distance;
2261
- targetSnapPoint = snapPoint;
2262
- }
2263
- }
2264
- const velocityDirection = Math.sign(resolvedDirectionalVelocity);
2265
- const shouldAdvance = dragDirection !== 0 && velocityDirection !== 0 && velocityDirection === dragDirection && Math.abs(resolvedDirectionalVelocity) >= SNAP_VELOCITY_THRESHOLD;
2266
- let effectiveTargetOffset = targetOffset;
2267
- if (shouldAdvance) {
2268
- const adjacentIndex = clamp(currentIndex + dragDirection, 0, orderedSnapPoints.length - 1);
2269
- if (adjacentIndex !== currentIndex) {
2270
- const adjacentPoint = orderedSnapPoints[adjacentIndex];
2271
- const shouldForceAdjacent = dragDirection > 0 ? targetOffset < adjacentPoint.offset : targetOffset > adjacentPoint.offset;
2272
- if (shouldForceAdjacent) {
2273
- targetSnapPoint = adjacentPoint;
2274
- effectiveTargetOffset = adjacentPoint.offset;
2275
- }
2276
- } else if (dragDirection > 0) {
2277
- return closeFromSnapPoints();
2278
- }
2279
- }
2280
- const closeOffset = popupHeight;
2281
- const closeDistance = Math.abs(effectiveTargetOffset - closeOffset);
2282
- const snapDistance = Math.abs(effectiveTargetOffset - targetSnapPoint.offset);
2283
- if (closeDistance < snapDistance) {
2284
- return closeFromSnapPoints();
2285
- }
2286
- setActiveSnapPoint?.(targetSnapPoint.value, snapPointEventDetails);
2287
- clearSwipeRelease();
2288
- return false;
2289
- }
2290
- if (resolvedDirectionalVelocity >= FAST_SWIPE_VELOCITY && dragDelta > 0) {
2291
- return closeFromSnapPoints();
2292
- }
2293
- let closestSnapPoint = resolvedSnapPoints[0];
2294
- let closestDistance = Math.abs(targetOffset - closestSnapPoint.offset);
2295
- for (const snapPoint of resolvedSnapPoints) {
2296
- const distance = Math.abs(targetOffset - snapPoint.offset);
2297
- if (distance < closestDistance) {
2298
- closestDistance = distance;
2299
- closestSnapPoint = snapPoint;
708
+ const displacement = getDisplacement(resolvedSwipeDirection, deltaX, deltaY);
709
+ const releaseVelocity = getDisplacement(resolvedSwipeDirection, releaseVelocityX, releaseVelocityY);
710
+ const threshold = resolveSwipeOpenThreshold();
711
+ const hasEnoughDistance = threshold != null && displacement >= threshold;
712
+ const hasEnoughVelocity = releaseVelocity >= VELOCITY_THRESHOLD;
713
+ const shouldOpen = threshold != null && direction === resolvedSwipeDirection && (hasEnoughDistance || hasEnoughVelocity) && !disabled;
714
+ if (shouldOpen) {
715
+ if (!store.select('open')) {
716
+ openDrawer(event);
2300
717
  }
718
+ } else if (openedBySwipeRef.current) {
719
+ closeDrawer(event);
2301
720
  }
2302
- const closeOffset = popupHeight;
2303
- const closeDistance = Math.abs(targetOffset - closeOffset);
2304
- if (closeDistance < closestDistance) {
2305
- return closeFromSnapPoints();
2306
- }
2307
- setActiveSnapPoint?.(closestSnapPoint.value, snapPointEventDetails);
2308
- clearSwipeRelease();
721
+ finishSwipeInteraction();
2309
722
  return false;
2310
723
  },
2311
- onDismiss(event) {
2312
- visualStateStore?.set({
2313
- swipeProgress: 0,
2314
- frontmostHeight: 0
2315
- });
2316
- const backdropElement = store.context.backdropRef.current;
2317
- if (backdropElement) {
2318
- backdropElement.style.setProperty(DrawerBackdropCssVars.swipeProgress, '0');
2319
- backdropElement.style.removeProperty(DrawerPopupCssVars.height);
2320
- }
2321
- const dismissEventDetails = createChangeEventDetails(swipe, event);
2322
- store.setOpen(false, dismissEventDetails);
2323
- if (dismissEventDetails.isCanceled) {
2324
- const pendingSnapPoint = pendingSwipeCloseSnapPointRef.current;
2325
- if (pendingSnapPoint !== undefined) {
2326
- setActiveSnapPoint?.(pendingSnapPoint, createChangeEventDetails(swipe, event));
2327
- }
2328
- pendingSwipeCloseSnapPointRef.current = undefined;
2329
- resetSwipeRef.current?.();
2330
- clearSwipeRelease();
2331
- return;
2332
- }
2333
-
2334
- // In controlled mode, the effective open state may not have changed yet
2335
- // (openProp takes precedence over state.open). Proceed optimistically with the
2336
- // dismiss animation — React's Scheduler flushes before the next rAF, so we can
2337
- // reliably check whether the parent accepted or rejected the close.
2338
- // Note: if onOpenChange is asynchronous (e.g., closes the drawer after a network
2339
- // call), the rAF check will see open === true, revert the animation, and the
2340
- // drawer will close without animation when the parent eventually sets open={false}.
2341
- if (store.select('open')) {
2342
- const savedEvent = event;
2343
- controlledDismissFrame.request(() => {
2344
- if (store.select('open')) {
2345
- // Parent rejected: revert animation and restore snap point.
2346
- const pendingSnapPoint = pendingSwipeCloseSnapPointRef.current;
2347
- if (pendingSnapPoint !== undefined) {
2348
- setActiveSnapPoint?.(pendingSnapPoint, createChangeEventDetails(swipe, savedEvent));
2349
- }
2350
- pendingSwipeCloseSnapPointRef.current = undefined;
2351
- clearSwipeRelease();
2352
- resetSwipeRef.current?.();
2353
- } else {
2354
- // Parent accepted: clean up the ref.
2355
- pendingSwipeCloseSnapPointRef.current = undefined;
2356
- }
2357
- });
2358
- return;
2359
- }
2360
- pendingSwipeCloseSnapPointRef.current = undefined;
2361
- setSwipeDismissed(true);
2362
- }
724
+ onCancel: finishSwipeInteraction
2363
725
  });
2364
726
  const swipePointerProps = swipe$1.getPointerProps();
2365
727
  const swipeTouchProps = swipe$1.getTouchProps();
2366
- const {
2367
- moveNative: moveSwipeNative,
2368
- reset: resetSwipe
2369
- } = swipe$1;
2370
- resetSwipeRef.current = resetSwipe;
2371
- React.useEffect(() => {
2372
- const rootElement = viewportElement ?? popupElementState;
2373
- if (!rootElement) {
2374
- return undefined;
2375
- }
2376
- const resolvedRootElement = rootElement;
2377
- const doc = ownerDocument(resolvedRootElement);
2378
- const win = getWindow(doc);
2379
- function handleNativeTouchMove(event) {
2380
- // The virtual keyboard provider observes the move to tell a tap apart from a drag.
2381
- // It must run even when the swipe gesture below claims the event with
2382
- // `stopPropagation()`, which would otherwise prevent React's delegated handlers
2383
- // (and the provider) from ever seeing the move.
2384
- virtualKeyboard?.onTouchMove(event);
2385
- if (ignoreTouchSwipeRef.current) {
2386
- return;
2387
- }
2388
- const touchState = touchScrollStateRef.current;
2389
- const touch = event.touches[0];
2390
- if (!touch || !touchState) {
2391
- return;
2392
- }
2393
- const drawerAxisDelta = isVerticalScrollAxis ? touch.clientY - touchState.lastY : touch.clientX - touchState.lastX;
2394
-
2395
- // Preserve native range interaction by never locking touchmove for range inputs.
2396
- if (isEventOnRangeInput(event, win)) {
2397
- touchState.allowSwipe = false;
2398
- updateTouchScrollPosition(touchState, touch);
2399
- return;
2400
- }
2401
-
2402
- // Avoid blocking pinch zoom or text selection adjustments on iOS Safari.
2403
- if (event.touches.length === 2) {
2404
- updateTouchScrollPosition(touchState, touch);
2405
- return;
2406
- }
2407
- const allowTouchMove = shouldIgnoreSwipeForTextSelection(doc, resolvedRootElement);
2408
- if (allowTouchMove || !open || !mounted || nestedDrawerOpen) {
2409
- updateTouchScrollPosition(touchState, touch);
2410
- return;
2411
- }
2412
- if (preserveNativeCrossAxisScrollOnMove(touchState, touch, isVerticalScrollAxis)) {
2413
- updateTouchScrollPosition(touchState, touch);
2414
- return;
2415
- }
2416
- const scrollTarget = touchState.scrollTarget;
2417
- if (!scrollTarget || scrollTarget === doc.documentElement || scrollTarget === doc.body) {
2418
- if (event.cancelable) {
2419
- event.preventDefault();
2420
- }
2421
- // Claim the gesture before React's delegated touch handlers see it; dispatching the
2422
- // move through React re-rasterizes the popup content on every frame.
2423
- event.stopPropagation();
2424
- moveSwipeNative(event, resolvedRootElement);
2425
- updateTouchScrollPosition(touchState, touch);
2426
- return;
2427
- }
2428
- const hasScrollableContent = hasScrollableContentOnAxis(scrollTarget, scrollAxis);
2429
- if (!hasScrollableContent) {
2430
- // If the scroll container doesn't overflow on the drawer axis, prevent the window from
2431
- // scrolling instead.
2432
- if (event.cancelable) {
2433
- event.preventDefault();
2434
- }
2435
- event.stopPropagation();
2436
- updateTouchScrollPosition(touchState, touch);
2437
- return;
2438
- }
2439
- const delta = drawerAxisDelta;
2440
- if (delta !== 0) {
2441
- const canSwipeFromScrollEdge = canSwipeFromScrollEdgeOnMove(scrollTarget, scrollAxis, swipeDirection, delta);
2442
- if (!touchState.allowSwipe) {
2443
- if (!event.cancelable) {
2444
- touchState.allowSwipe = false;
2445
- } else if (canSwipeFromScrollEdge) {
2446
- touchState.allowSwipe = true;
2447
- event.preventDefault();
2448
- } else {
2449
- touchState.allowSwipe = false;
2450
- }
2451
- } else if (event.cancelable) {
2452
- event.preventDefault();
2453
- }
2454
- }
2455
- if (touchState.allowSwipe === true) {
2456
- event.stopPropagation();
2457
- moveSwipeNative(event, resolvedRootElement);
2458
- }
2459
- updateTouchScrollPosition(touchState, touch);
2460
- }
2461
- return addEventListener(doc, 'touchmove', handleNativeTouchMove, {
2462
- passive: false,
2463
- capture: true
2464
- });
2465
- }, [mounted, nestedDrawerOpen, open, popupElementState, isVerticalScrollAxis, scrollAxis, swipeDirection, moveSwipeNative, viewportElement, virtualKeyboard]);
2466
- React.useEffect(() => {
2467
- if (!snapPointRange || swipe$1.swiping) {
2468
- return;
2469
- }
2470
- const resolvedProgress = !open || nested ? 0 : snapPointProgress ?? 0;
2471
- applySwipeProgress({
2472
- resolvedProgress,
2473
- shouldTrackProgress: true,
2474
- notifyParent: false
2475
- });
2476
- }, [applySwipeProgress, frontmostHeight, nested, notifyParentSwipeProgressChange, open, snapPointProgress, snapPointRange, swipe$1.swiping, store, visualStateStore]);
2477
- React.useEffect(() => {
2478
- if (!notifyParentSwipeProgressChange) {
2479
- return undefined;
2480
- }
2481
- if (!open) {
2482
- notifyParentSwipeProgressChange(0);
2483
- }
2484
- return () => {
2485
- notifyParentSwipeProgressChange(0);
2486
- };
2487
- }, [notifyParentSwipeProgressChange, open]);
728
+ const resetSwipe = swipe$1.reset;
2488
729
  React.useEffect(() => {
2489
- if (open) {
730
+ if (!enabled) {
2490
731
  resetSwipe();
2491
- clearSwipeRelease();
732
+ resetDragDelta();
733
+ clearSwipeStyles();
734
+ resetSwipeInteractionState();
2492
735
  }
2493
- }, [clearSwipeRelease, open, resetSwipe]);
736
+ }, [clearSwipeStyles, enabled, resetDragDelta, resetSwipe]);
2494
737
  React.useEffect(() => {
2495
- const backdropElement = backdropRef.current;
2496
738
  return () => {
2497
- visualStateStore?.set({
2498
- swipeProgress: 0,
2499
- frontmostHeight: 0
2500
- });
2501
- setBackdropSwipingAttribute(backdropElement, false);
2502
- // `data-swiping` is set on whichever backdrop is current when a swipe starts, which can
2503
- // differ from the captured element if the backdrop mounted late or changed identity.
2504
- // Reading the live ref here is intentional so the current backdrop is cleared too.
2505
- // eslint-disable-next-line react-hooks/exhaustive-deps
2506
- const currentBackdrop = backdropRef.current;
2507
- if (currentBackdrop !== backdropElement) {
2508
- setBackdropSwipingAttribute(currentBackdrop, false);
2509
- }
2510
- finishNestedSwipe();
739
+ store.context.outsidePressEnabledRef.current = true;
2511
740
  };
2512
- }, [backdropRef, finishNestedSwipe, visualStateStore]);
2513
- const swipeProviderValue = React.useMemo(() => ({
741
+ }, [store]);
742
+ const state = {
743
+ open,
2514
744
  swiping: swipe$1.swiping,
2515
- getDragStyles: swipe$1.getDragStyles,
2516
- swipeStrength: swipeRelease ?? null,
2517
- setSwipeDismissed
2518
- }), [setSwipeDismissed, swipe$1.getDragStyles, swipe$1.swiping, swipeRelease]);
2519
- function resetTouchTrackingState() {
2520
- ignoreTouchSwipeRef.current = false;
2521
- touchScrollStateRef.current = null;
2522
- lastPointerTypeRef.current = '';
2523
- ignoreNextTouchStartFromPenRef.current = false;
2524
- }
2525
- return /*#__PURE__*/jsx(DialogViewport, {
2526
- ref: forwardedRef,
2527
- className: className,
2528
- style: style,
2529
- render: render,
2530
- ...mergeProps(elementProps, {
745
+ swipeDirection: resolvedSwipeDirection,
746
+ disabled
747
+ };
748
+ return useRenderElement('div', componentProps, {
749
+ state,
750
+ ref: [forwardedRef, swipeAreaRef, registerTrigger],
751
+ stateAttributesMapping: stateAttributesMapping$3,
752
+ props: [{
753
+ role: 'presentation',
754
+ 'aria-hidden': true,
755
+ style: {
756
+ pointerEvents: !enabled ? 'none' : undefined,
757
+ touchAction: resolveTouchAction(resolvedSwipeDirection)
758
+ },
2531
759
  onPointerDown(event) {
2532
- lastPointerTypeRef.current = event.pointerType;
2533
- ignoreNextTouchStartFromPenRef.current = event.pointerType === 'pen';
2534
- if (!open || !mounted || nestedDrawerOpen) {
2535
- return;
2536
- }
2537
- const doc = ownerDocument(event.currentTarget);
2538
- const elementAtPoint = getElementAtPoint(doc, event.clientX, event.clientY);
2539
- if (isSwipeIgnoredTarget(elementAtPoint) || isDrawerContentTarget(elementAtPoint)) {
2540
- return;
2541
- }
2542
760
  if (event.pointerType === 'touch') {
2543
761
  return;
2544
762
  }
2545
763
  swipePointerProps.onPointerDown?.(event);
764
+
765
+ // Prevent native text selection/drag gestures from competing with swipe-open dragging.
766
+ if (event.cancelable) {
767
+ event.preventDefault();
768
+ }
2546
769
  },
2547
770
  onPointerMove(event) {
2548
771
  if (event.pointerType === 'touch') {
@@ -2551,258 +774,23 @@ const DrawerViewport = /*#__PURE__*/React.forwardRef(function DrawerViewport(pro
2551
774
  swipePointerProps.onPointerMove?.(event);
2552
775
  },
2553
776
  onPointerUp(event) {
2554
- if (lastPointerTypeRef.current === event.pointerType) {
2555
- lastPointerTypeRef.current = '';
2556
- }
2557
777
  if (event.pointerType === 'touch') {
2558
778
  return;
2559
779
  }
2560
780
  swipePointerProps.onPointerUp?.(event);
2561
781
  },
2562
782
  onPointerCancel(event) {
2563
- if (lastPointerTypeRef.current === event.pointerType) {
2564
- lastPointerTypeRef.current = '';
2565
- }
2566
783
  if (event.pointerType === 'touch') {
2567
784
  return;
2568
785
  }
2569
786
  swipePointerProps.onPointerCancel?.(event);
2570
- },
2571
- onTouchStart(event) {
2572
- const startedFromPenPointerDown = lastPointerTypeRef.current === 'pen' && ignoreNextTouchStartFromPenRef.current;
2573
- if (startedFromPenPointerDown) {
2574
- ignoreNextTouchStartFromPenRef.current = false;
2575
- ignoreTouchSwipeRef.current = false;
2576
- touchScrollStateRef.current = null;
2577
- return;
2578
- }
2579
- if (!open || !mounted || nestedDrawerOpen) {
2580
- ignoreTouchSwipeRef.current = false;
2581
- touchScrollStateRef.current = null;
2582
- return;
2583
- }
2584
- const touch = event.touches[0];
2585
- if (!touch) {
2586
- return;
2587
- }
2588
- if (isReactTouchEventOnRangeInput(event)) {
2589
- ignoreTouchSwipeRef.current = false;
2590
- touchScrollStateRef.current = null;
2591
- return;
2592
- }
2593
- const doc = ownerDocument(event.currentTarget);
2594
- const elementAtPoint = getElementAtPoint(doc, touch.clientX, touch.clientY);
2595
- const rootElement = viewportElement ?? popupElementState;
2596
- const eventTarget = getTarget(event.nativeEvent);
2597
- const target = isElement(eventTarget) ? eventTarget : null;
2598
- if (rootElement && target && !contains(rootElement, target)) {
2599
- ignoreTouchSwipeRef.current = true;
2600
- touchScrollStateRef.current = null;
2601
- return;
2602
- }
2603
- virtualKeyboard?.onTouchStart(event);
2604
- ignoreTouchSwipeRef.current = isSwipeIgnoredTarget(elementAtPoint);
2605
- if (ignoreTouchSwipeRef.current) {
2606
- touchScrollStateRef.current = null;
2607
- return;
2608
- }
2609
- let scrollTarget = null;
2610
- let hasCrossAxisScrollableContent = false;
2611
- if (rootElement && target) {
2612
- scrollTarget = findScrollableTouchTarget(target, rootElement, scrollAxis);
2613
- hasCrossAxisScrollableContent = findScrollableTouchTarget(target, rootElement, crossScrollAxis) != null;
2614
- }
2615
- let allowSwipe = null;
2616
- if (scrollTarget) {
2617
- const canSwipeFromEdge = isAtSwipeStartEdge(scrollTarget, scrollAxis, swipeDirection);
2618
- allowSwipe = canSwipeFromEdge ? null : false;
2619
- }
2620
- touchScrollStateRef.current = {
2621
- startX: touch.clientX,
2622
- startY: touch.clientY,
2623
- lastX: touch.clientX,
2624
- lastY: touch.clientY,
2625
- scrollTarget,
2626
- hasCrossAxisScrollableContent,
2627
- allowSwipe,
2628
- preserveNativeCrossAxisScroll: false
2629
- };
2630
- swipeTouchProps.onTouchStart?.(event);
2631
- },
2632
- onTouchEnd(event) {
2633
- virtualKeyboard?.onTouchEnd(event);
2634
- resetTouchTrackingState();
2635
- swipeTouchProps.onTouchEnd?.(event);
2636
- },
2637
- onTouchCancel(event) {
2638
- virtualKeyboard?.onTouchCancel();
2639
- resetTouchTrackingState();
2640
- swipeTouchProps.onTouchCancel?.(event);
2641
- },
2642
- // Drawer popups use drawer-specific nested state attributes.
2643
- // Suppress DialogViewport's generic nested dialog attribute.
2644
- ['data-nested-dialog-open']: undefined
2645
- }),
2646
- children: /*#__PURE__*/jsx(DrawerViewportContext.Provider, {
2647
- value: swipeProviderValue,
2648
- children: children
2649
- })
787
+ }
788
+ }, swipeTouchProps, swipeAreaId ? {
789
+ id: swipeAreaId
790
+ } : undefined, elementProps]
2650
791
  });
2651
792
  });
2652
- if (process.env.NODE_ENV !== "production") DrawerViewport.displayName = "DrawerViewport";
2653
- function setSwipeDismissedElements(popupElement, backdropElement, dismissed) {
2654
- if (dismissed) {
2655
- popupElement?.setAttribute(DrawerPopupDataAttributes.swipeDismiss, '');
2656
- backdropElement?.setAttribute(DrawerPopupDataAttributes.swipeDismiss, '');
2657
- return;
2658
- }
2659
- popupElement?.removeAttribute(DrawerPopupDataAttributes.swipeDismiss);
2660
- backdropElement?.removeAttribute(DrawerPopupDataAttributes.swipeDismiss);
2661
- }
2662
- function setBackdropSwipingAttribute(backdropElement, swiping) {
2663
- if (!backdropElement) {
2664
- return;
2665
- }
2666
- if (swiping) {
2667
- backdropElement.setAttribute(DrawerPopupDataAttributes.swiping, '');
2668
- return;
2669
- }
2670
- backdropElement.removeAttribute(DrawerPopupDataAttributes.swiping);
2671
- }
2672
- function isSwipeIgnoredTarget(target) {
2673
- return Boolean(target?.closest(BASE_UI_SWIPE_IGNORE_SELECTOR));
2674
- }
2675
- function isDrawerContentTarget(target) {
2676
- return Boolean(target?.closest(DRAWER_CONTENT_SELECTOR));
2677
- }
2678
- function getBaseSwipeThreshold(element, direction) {
2679
- const size = direction === 'left' || direction === 'right' ? element.offsetWidth : element.offsetHeight;
2680
- return Math.max(size * 0.5, MIN_SWIPE_THRESHOLD);
2681
- }
2682
- function isRangeInput(target, win) {
2683
- return target instanceof win.HTMLInputElement && target.type === 'range';
2684
- }
2685
- function isTextSelectionControl(target) {
2686
- if (!isElement(target)) {
2687
- return false;
2688
- }
2689
- return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA';
2690
- }
2691
- function hasExpandedSelectionWithinTarget(selection, target) {
2692
- const anchorElement = isElement(selection.anchorNode) ? selection.anchorNode : selection.anchorNode?.parentElement;
2693
- const focusElement = isElement(selection.focusNode) ? selection.focusNode : selection.focusNode?.parentElement;
2694
- return selection.containsNode(target, true) || contains(target, anchorElement) || contains(target, focusElement);
2695
- }
2696
- function shouldIgnoreSwipeForTextSelection(doc, rootElement) {
2697
- const activeEl = activeElement(doc);
2698
- const activeElementWithinRoot = Boolean(activeEl && contains(rootElement, activeEl));
2699
- if (activeElementWithinRoot && isTextSelectionControl(activeEl)) {
2700
- const {
2701
- selectionStart,
2702
- selectionEnd
2703
- } = activeEl;
2704
- if (selectionStart != null && selectionEnd != null && selectionStart < selectionEnd) {
2705
- return true;
2706
- }
2707
- }
2708
- const selection = doc.getSelection?.();
2709
- if (!selection || selection.isCollapsed) {
2710
- return false;
2711
- }
2712
- return hasExpandedSelectionWithinTarget(selection, rootElement);
2713
- }
2714
- function isEventOnRangeInput(event, win) {
2715
- const composedPath = event.composedPath();
2716
- if (composedPath) {
2717
- return composedPath.some(pathTarget => isRangeInput(pathTarget, win));
2718
- }
2719
- return isRangeInput(getTarget(event), win);
2720
- }
2721
- function isReactTouchEventOnRangeInput(event) {
2722
- return isEventOnRangeInput(event.nativeEvent, getWindow(event.currentTarget));
2723
- }
2724
- function updateTouchScrollPosition(touchState, touch) {
2725
- touchState.lastX = touch.clientX;
2726
- touchState.lastY = touch.clientY;
2727
- }
2728
- function preserveNativeCrossAxisScrollOnMove(touchState, touch, isVerticalScrollAxis) {
2729
- if (touchState.preserveNativeCrossAxisScroll) {
2730
- return true;
2731
- }
2732
- if (touchState.allowSwipe === true || !touchState.hasCrossAxisScrollableContent) {
2733
- return false;
2734
- }
2735
- const drawerAxisGestureDelta = isVerticalScrollAxis ? touch.clientY - touchState.startY : touch.clientX - touchState.startX;
2736
- const crossAxisGestureDelta = isVerticalScrollAxis ? touch.clientX - touchState.startX : touch.clientY - touchState.startY;
2737
- const absDrawerAxisGestureDelta = Math.abs(drawerAxisGestureDelta);
2738
- const absCrossAxisGestureDelta = Math.abs(crossAxisGestureDelta);
2739
- if (absCrossAxisGestureDelta < 6 || absCrossAxisGestureDelta <= absDrawerAxisGestureDelta + 2) {
2740
- return false;
2741
- }
2742
- touchState.preserveNativeCrossAxisScroll = true;
2743
- return true;
2744
- }
2745
- function hasScrollableContentOnAxis(scrollTarget, axis) {
2746
- return axis === 'vertical' ? scrollTarget.scrollHeight > scrollTarget.clientHeight : scrollTarget.scrollWidth > scrollTarget.clientWidth;
2747
- }
2748
- function getScrollMetrics(scrollTarget, axis) {
2749
- if (axis === 'vertical') {
2750
- const max = Math.max(0, scrollTarget.scrollHeight - scrollTarget.clientHeight);
2751
- return {
2752
- offset: scrollTarget.scrollTop,
2753
- max
2754
- };
2755
- }
2756
- const max = Math.max(0, scrollTarget.scrollWidth - scrollTarget.clientWidth);
2757
- return {
2758
- offset: scrollTarget.scrollLeft,
2759
- max
2760
- };
2761
- }
2762
- function isAtSwipeStartEdge(scrollTarget, axis, direction) {
2763
- const {
2764
- offset,
2765
- max
2766
- } = getScrollMetrics(scrollTarget, axis);
2767
- const dismissFromStartEdge = shouldDismissFromStartEdge(direction, axis);
2768
- if (dismissFromStartEdge === null) {
2769
- return false;
2770
- }
2771
- return dismissFromStartEdge ? offset <= 0 : offset >= max;
2772
- }
2773
- function canSwipeFromScrollEdgeOnMove(scrollTarget, axis, direction, delta) {
2774
- const {
2775
- offset,
2776
- max
2777
- } = getScrollMetrics(scrollTarget, axis);
2778
- const dismissFromStartEdge = shouldDismissFromStartEdge(direction, axis);
2779
- if (dismissFromStartEdge === null) {
2780
- return false;
2781
- }
2782
- const movingTowardDismiss = dismissFromStartEdge ? delta > 0 : delta < 0;
2783
- if (!movingTowardDismiss) {
2784
- return false;
2785
- }
2786
- return dismissFromStartEdge ? offset <= 0 : offset >= max;
2787
- }
2788
- function shouldDismissFromStartEdge(direction, axis) {
2789
- if (axis === 'vertical') {
2790
- if (direction === 'down') {
2791
- return true;
2792
- }
2793
- if (direction === 'up') {
2794
- return false;
2795
- }
2796
- return null;
2797
- }
2798
- if (direction === 'right') {
2799
- return true;
2800
- }
2801
- if (direction === 'left') {
2802
- return false;
2803
- }
2804
- return null;
2805
- }
793
+ if (process.env.NODE_ENV !== "production") DrawerSwipeArea.displayName = "DrawerSwipeArea";
2806
794
 
2807
795
  let DrawerViewportCssVars = /*#__PURE__*/function (DrawerViewportCssVars) {
2808
796
  /**