base-vaul 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,32 +8,13 @@ function __insertCSS(code) {
8
8
  ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
9
9
  }
10
10
 
11
- Object.defineProperty(exports, '__esModule', { value: true });
11
+ import { jsx } from 'react/jsx-runtime';
12
+ import { Dialog } from '@base-ui/react';
13
+ import * as React from 'react';
14
+ import React__default, { useLayoutEffect, useEffect, useMemo } from 'react';
12
15
 
13
- var react = require('@base-ui/react');
14
- var React = require('react');
15
-
16
- function _interopNamespace(e) {
17
- if (e && e.__esModule) return e;
18
- var n = Object.create(null);
19
- if (e) {
20
- Object.keys(e).forEach(function (k) {
21
- if (k !== 'default') {
22
- var d = Object.getOwnPropertyDescriptor(e, k);
23
- Object.defineProperty(n, k, d.get ? d : {
24
- enumerable: true,
25
- get: function () { return e[k]; }
26
- });
27
- }
28
- });
29
- }
30
- n.default = e;
31
- return n;
32
- }
33
-
34
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
35
-
36
- const DrawerContext = React__namespace.default.createContext({
16
+ // @ts-nocheck [FIXME] See after monorepo migration
17
+ const DrawerContext = React__default.createContext({
37
18
  drawerRef: {
38
19
  current: null
39
20
  },
@@ -62,7 +43,7 @@ const DrawerContext = React__namespace.default.createContext({
62
43
  onOpenChange: ()=>{},
63
44
  setActiveSnapPoint: ()=>{},
64
45
  closeDrawer: ()=>{},
65
- direction: 'bottom',
46
+ direction: "bottom",
66
47
  shouldAnimate: {
67
48
  current: true
68
49
  },
@@ -73,9 +54,9 @@ const DrawerContext = React__namespace.default.createContext({
73
54
  autoFocus: false
74
55
  });
75
56
  const useDrawerContext = ()=>{
76
- const context = React__namespace.default.useContext(DrawerContext);
57
+ const context = React__default.useContext(DrawerContext);
77
58
  if (!context) {
78
- throw new Error('useDrawerContext must be used within a Drawer.Root');
59
+ throw new Error("useDrawerContext must be used within a Drawer.Root");
79
60
  }
80
61
  return context;
81
62
  };
@@ -108,22 +89,23 @@ function testPlatform(re) {
108
89
  return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator.platform) : undefined;
109
90
  }
110
91
 
92
+ // @ts-nocheck [FIXME] See after monorepo migration
111
93
  // This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts
112
94
  const KEYBOARD_BUFFER = 24;
113
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
95
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
114
96
  function chain$1(...callbacks) {
115
97
  return (...args)=>{
116
- for (let callback of callbacks){
117
- if (typeof callback === 'function') {
98
+ for (const callback of callbacks){
99
+ if (typeof callback === "function") {
118
100
  callback(...args);
119
101
  }
120
102
  }
121
103
  };
122
104
  }
123
105
  // @ts-ignore
124
- const visualViewport = typeof document !== 'undefined' && window.visualViewport;
106
+ const visualViewport = typeof document !== "undefined" && window.visualViewport;
125
107
  function isScrollable(node) {
126
- let style = window.getComputedStyle(node);
108
+ const style = window.getComputedStyle(node);
127
109
  return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
128
110
  }
129
111
  function getScrollParent(node) {
@@ -137,15 +119,15 @@ function getScrollParent(node) {
137
119
  }
138
120
  // HTML input types that do not cause the software keyboard to appear.
139
121
  const nonTextInputTypes = new Set([
140
- 'checkbox',
141
- 'radio',
142
- 'range',
143
- 'color',
144
- 'file',
145
- 'image',
146
- 'button',
147
- 'submit',
148
- 'reset'
122
+ "checkbox",
123
+ "radio",
124
+ "range",
125
+ "color",
126
+ "file",
127
+ "image",
128
+ "button",
129
+ "submit",
130
+ "reset"
149
131
  ]);
150
132
  // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
151
133
  let preventScrollCount = 0;
@@ -155,7 +137,7 @@ let restore;
155
137
  * restores it on unmount. Also ensures that content does not
156
138
  * shift due to the scrollbars disappearing.
157
139
  */ function usePreventScroll(options = {}) {
158
- let { isDisabled } = options;
140
+ const { isDisabled } = options;
159
141
  useIsomorphicLayoutEffect(()=>{
160
142
  if (isDisabled) {
161
143
  return;
@@ -169,7 +151,7 @@ let restore;
169
151
  return ()=>{
170
152
  preventScrollCount--;
171
153
  if (preventScrollCount === 0) {
172
- restore == null ? void 0 : restore();
154
+ restore?.();
173
155
  }
174
156
  };
175
157
  }, [
@@ -205,7 +187,7 @@ let restore;
205
187
  function preventScrollMobileSafari() {
206
188
  let scrollable;
207
189
  let lastY = 0;
208
- let onTouchStart = (e)=>{
190
+ const onTouchStart = (e)=>{
209
191
  // Store the nearest scrollable parent element from the element that the user touched.
210
192
  scrollable = getScrollParent(e.target);
211
193
  if (scrollable === document.documentElement && scrollable === document.body) {
@@ -213,7 +195,7 @@ function preventScrollMobileSafari() {
213
195
  }
214
196
  lastY = e.changedTouches[0].pageY;
215
197
  };
216
- let onTouchMove = (e)=>{
198
+ const onTouchMove = (e)=>{
217
199
  // Prevent scrolling the window.
218
200
  if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
219
201
  e.preventDefault();
@@ -223,9 +205,9 @@ function preventScrollMobileSafari() {
223
205
  // of a nested scrollable area, otherwise mobile Safari will start scrolling
224
206
  // the window instead. Unfortunately, this disables bounce scrolling when at
225
207
  // the top but it's the best we can do.
226
- let y = e.changedTouches[0].pageY;
227
- let scrollTop = scrollable.scrollTop;
228
- let bottom = scrollable.scrollHeight - scrollable.clientHeight;
208
+ const y = e.changedTouches[0].pageY;
209
+ const scrollTop = scrollable.scrollTop;
210
+ const bottom = scrollable.scrollHeight - scrollable.clientHeight;
229
211
  if (bottom === 0) {
230
212
  return;
231
213
  }
@@ -234,31 +216,31 @@ function preventScrollMobileSafari() {
234
216
  }
235
217
  lastY = y;
236
218
  };
237
- let onTouchEnd = (e)=>{
238
- let target = e.target;
219
+ const onTouchEnd = (e)=>{
220
+ const target = e.target;
239
221
  // Apply this change if we're not already focused on the target element
240
222
  if (isInput(target) && target !== document.activeElement) {
241
223
  e.preventDefault();
242
224
  // Apply a transform to trick Safari into thinking the input is at the top of the page
243
225
  // so it doesn't try to scroll it into view. When tapping on an input, this needs to
244
226
  // be done before the "focus" event, so we have to focus the element ourselves.
245
- target.style.transform = 'translateY(-2000px)';
227
+ target.style.transform = "translateY(-2000px)";
246
228
  target.focus();
247
229
  requestAnimationFrame(()=>{
248
- target.style.transform = '';
230
+ target.style.transform = "";
249
231
  });
250
232
  }
251
233
  };
252
- let onFocus = (e)=>{
253
- let target = e.target;
234
+ const onFocus = (e)=>{
235
+ const target = e.target;
254
236
  if (isInput(target)) {
255
237
  // Transform also needs to be applied in the focus event in cases where focus moves
256
238
  // other than tapping on an input directly, e.g. the next/previous buttons in the
257
239
  // software keyboard. In these cases, it seems applying the transform in the focus event
258
240
  // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
259
- target.style.transform = 'translateY(-2000px)';
241
+ target.style.transform = "translateY(-2000px)";
260
242
  requestAnimationFrame(()=>{
261
- target.style.transform = '';
243
+ target.style.transform = "";
262
244
  // This will have prevented the browser from scrolling the focused element into view,
263
245
  // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
264
246
  if (visualViewport) {
@@ -271,7 +253,7 @@ function preventScrollMobileSafari() {
271
253
  } else {
272
254
  // Otherwise, wait for the visual viewport to resize before scrolling so we can
273
255
  // measure the correct position to scroll to.
274
- visualViewport.addEventListener('resize', ()=>scrollIntoView(target), {
256
+ visualViewport.addEventListener("resize", ()=>scrollIntoView(target), {
275
257
  once: true
276
258
  });
277
259
  }
@@ -279,7 +261,7 @@ function preventScrollMobileSafari() {
279
261
  });
280
262
  }
281
263
  };
282
- let onWindowScroll = ()=>{
264
+ const onWindowScroll = ()=>{
283
265
  // Last resort. If the window scrolled, scroll it back to the top.
284
266
  // It should always be at the top because the body will have a negative margin (see below).
285
267
  window.scrollTo(0, 0);
@@ -287,21 +269,21 @@ function preventScrollMobileSafari() {
287
269
  // Record the original scroll position so we can restore it.
288
270
  // Then apply a negative margin to the body to offset it by the scroll position. This will
289
271
  // enable us to scroll the window to the top, which is required for the rest of this to work.
290
- let scrollX = window.pageXOffset;
291
- let scrollY = window.pageYOffset;
292
- let restoreStyles = chain$1(setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`));
272
+ const scrollX = window.pageXOffset;
273
+ const scrollY = window.pageYOffset;
274
+ const restoreStyles = chain$1(setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`));
293
275
  // Scroll to the top. The negative margin on the body will make this appear the same.
294
276
  window.scrollTo(0, 0);
295
- let removeEvents = chain$1(addEvent(document, 'touchstart', onTouchStart, {
277
+ const removeEvents = chain$1(addEvent(document, "touchstart", onTouchStart, {
296
278
  passive: false,
297
279
  capture: true
298
- }), addEvent(document, 'touchmove', onTouchMove, {
280
+ }), addEvent(document, "touchmove", onTouchMove, {
299
281
  passive: false,
300
282
  capture: true
301
- }), addEvent(document, 'touchend', onTouchEnd, {
283
+ }), addEvent(document, "touchend", onTouchEnd, {
302
284
  passive: false,
303
285
  capture: true
304
- }), addEvent(document, 'focus', onFocus, true), addEvent(window, 'scroll', onWindowScroll));
286
+ }), addEvent(document, "focus", onFocus, true), addEvent(window, "scroll", onWindowScroll));
305
287
  return ()=>{
306
288
  // Restore styles and scroll the page back to where it was.
307
289
  restoreStyles();
@@ -313,7 +295,7 @@ function preventScrollMobileSafari() {
313
295
  function setStyle(element, style, value) {
314
296
  // https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310
315
297
  // @ts-ignore
316
- let cur = element.style[style];
298
+ const cur = element.style[style];
317
299
  // @ts-ignore
318
300
  element.style[style] = value;
319
301
  return ()=>{
@@ -331,14 +313,14 @@ function addEvent(target, event, handler, options) {
331
313
  };
332
314
  }
333
315
  function scrollIntoView(target) {
334
- let root = document.scrollingElement || document.documentElement;
316
+ const root = document.scrollingElement || document.documentElement;
335
317
  while(target && target !== root){
336
318
  // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
337
- let scrollable = getScrollParent(target);
319
+ const scrollable = getScrollParent(target);
338
320
  if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
339
- let scrollableTop = scrollable.getBoundingClientRect().top;
340
- let targetTop = target.getBoundingClientRect().top;
341
- let targetBottom = target.getBoundingClientRect().bottom;
321
+ const scrollableTop = scrollable.getBoundingClientRect().top;
322
+ const targetTop = target.getBoundingClientRect().top;
323
+ const targetBottom = target.getBoundingClientRect().bottom;
342
324
  // Buffer is needed for some edge cases
343
325
  const keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;
344
326
  if (targetBottom > keyboardHeight) {
@@ -375,13 +357,13 @@ function isInput(target) {
375
357
  * Accepts callback refs and RefObject(s)
376
358
  */ function useComposedRefs(...refs) {
377
359
  // eslint-disable-next-line react-hooks/exhaustive-deps
378
- return React__namespace.useCallback(composeRefs(...refs), refs);
360
+ return React.useCallback(composeRefs(...refs), refs);
379
361
  }
380
362
 
381
363
  const cache = new WeakMap();
382
364
  function set(el, styles, ignoreCache = false) {
383
365
  if (!el || !(el instanceof HTMLElement)) return;
384
- let originalStyles = {};
366
+ const originalStyles = {};
385
367
  Object.entries(styles).forEach(([key, value])=>{
386
368
  if (key.startsWith('--')) {
387
369
  el.style.setProperty(key, value);
@@ -395,7 +377,7 @@ function set(el, styles, ignoreCache = false) {
395
377
  }
396
378
  function reset(el, prop) {
397
379
  if (!el || !(el instanceof HTMLElement)) return;
398
- let originalStyles = cache.get(el);
380
+ const originalStyles = cache.get(el);
399
381
  if (!originalStyles) {
400
382
  return;
401
383
  }
@@ -474,19 +456,19 @@ const DRAG_CLASS = 'vaul-dragging';
474
456
 
475
457
  // This code comes from https://github.com/radix-ui/primitives/blob/main/packages/react/use-controllable-state/src/useControllableState.tsx
476
458
  function useCallbackRef(callback) {
477
- const callbackRef = React__namespace.default.useRef(callback);
478
- React__namespace.default.useEffect(()=>{
459
+ const callbackRef = React__default.useRef(callback);
460
+ React__default.useEffect(()=>{
479
461
  callbackRef.current = callback;
480
462
  });
481
463
  // https://github.com/facebook/react/issues/19240
482
- return React__namespace.default.useMemo(()=>(...args)=>callbackRef.current == null ? void 0 : callbackRef.current.call(callbackRef, ...args), []);
464
+ return React__default.useMemo(()=>(...args)=>callbackRef.current?.(...args), []);
483
465
  }
484
466
  function useUncontrolledState({ defaultProp, onChange }) {
485
- const uncontrolledState = React__namespace.default.useState(defaultProp);
467
+ const uncontrolledState = React__default.useState(defaultProp);
486
468
  const [value] = uncontrolledState;
487
- const prevValueRef = React__namespace.default.useRef(value);
469
+ const prevValueRef = React__default.useRef(value);
488
470
  const handleChange = useCallbackRef(onChange);
489
- React__namespace.default.useEffect(()=>{
471
+ React__default.useEffect(()=>{
490
472
  if (prevValueRef.current !== value) {
491
473
  handleChange(value);
492
474
  prevValueRef.current = value;
@@ -506,7 +488,7 @@ function useControllableState({ prop, defaultProp, onChange = ()=>{} }) {
506
488
  const isControlled = prop !== undefined;
507
489
  const value = isControlled ? prop : uncontrolledProp;
508
490
  const handleChange = useCallbackRef(onChange);
509
- const setValue = React__namespace.default.useCallback((nextValue)=>{
491
+ const setValue = React__default.useCallback((nextValue)=>{
510
492
  if (isControlled) {
511
493
  const setter = nextValue;
512
494
  const value = typeof nextValue === 'function' ? setter(prop) : nextValue;
@@ -526,52 +508,49 @@ function useControllableState({ prop, defaultProp, onChange = ()=>{} }) {
526
508
  ];
527
509
  }
528
510
 
529
- function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = 'bottom', container, snapToSequentialPoint }) {
511
+ // @ts-nocheck [FIXME] See after monorepo migration
512
+ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = "bottom", container, snapToSequentialPoint }) {
530
513
  const [activeSnapPoint, setActiveSnapPoint] = useControllableState({
531
514
  prop: activeSnapPointProp,
532
- defaultProp: snapPoints == null ? void 0 : snapPoints[0],
515
+ defaultProp: snapPoints?.[0],
533
516
  onChange: setActiveSnapPointProp
534
517
  });
535
- const [windowDimensions, setWindowDimensions] = React__namespace.default.useState(typeof window !== 'undefined' ? {
518
+ const [windowDimensions, setWindowDimensions] = React__default.useState(typeof window !== "undefined" ? {
536
519
  innerWidth: window.innerWidth,
537
520
  innerHeight: window.innerHeight
538
521
  } : undefined);
539
- React__namespace.default.useEffect(()=>{
522
+ React__default.useEffect(()=>{
540
523
  function onResize() {
541
524
  setWindowDimensions({
542
525
  innerWidth: window.innerWidth,
543
526
  innerHeight: window.innerHeight
544
527
  });
545
528
  }
546
- window.addEventListener('resize', onResize);
547
- return ()=>window.removeEventListener('resize', onResize);
529
+ window.addEventListener("resize", onResize);
530
+ return ()=>window.removeEventListener("resize", onResize);
548
531
  }, []);
549
- const isLastSnapPoint = React__namespace.default.useMemo(()=>activeSnapPoint === (snapPoints == null ? void 0 : snapPoints[snapPoints.length - 1]) || null, [
532
+ const isLastSnapPoint = React__default.useMemo(()=>activeSnapPoint === snapPoints?.[snapPoints.length - 1] || null, [
550
533
  snapPoints,
551
534
  activeSnapPoint
552
535
  ]);
553
- const activeSnapPointIndex = React__namespace.default.useMemo(()=>{
554
- var _snapPoints_findIndex;
555
- return (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : null;
556
- }, [
536
+ const activeSnapPointIndex = React__default.useMemo(()=>snapPoints?.findIndex((snapPoint)=>snapPoint === activeSnapPoint) ?? null, [
557
537
  snapPoints,
558
538
  activeSnapPoint
559
539
  ]);
560
540
  const shouldFade = snapPoints && snapPoints.length > 0 && (fadeFromIndex || fadeFromIndex === 0) && !Number.isNaN(fadeFromIndex) && snapPoints[fadeFromIndex] === activeSnapPoint || !snapPoints;
561
- const snapPointsOffset = React__namespace.default.useMemo(()=>{
541
+ const snapPointsOffset = React__default.useMemo(()=>{
562
542
  const containerSize = container ? {
563
543
  width: container.getBoundingClientRect().width,
564
544
  height: container.getBoundingClientRect().height
565
- } : typeof window !== 'undefined' ? {
545
+ } : typeof window !== "undefined" ? {
566
546
  width: window.innerWidth,
567
547
  height: window.innerHeight
568
548
  } : {
569
549
  width: 0,
570
550
  height: 0
571
551
  };
572
- var _snapPoints_map;
573
- return (_snapPoints_map = snapPoints == null ? void 0 : snapPoints.map((snapPoint)=>{
574
- const isPx = typeof snapPoint === 'string';
552
+ return snapPoints?.map((snapPoint)=>{
553
+ const isPx = typeof snapPoint === "string";
575
554
  let snapPointAsNumber = 0;
576
555
  if (isPx) {
577
556
  snapPointAsNumber = parseInt(snapPoint, 10);
@@ -579,45 +558,44 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
579
558
  if (isVertical(direction)) {
580
559
  const height = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.height : 0;
581
560
  if (windowDimensions) {
582
- return direction === 'bottom' ? containerSize.height - height : -containerSize.height + height;
561
+ return direction === "bottom" ? containerSize.height - height : -containerSize.height + height;
583
562
  }
584
563
  return height;
585
564
  }
586
565
  const width = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.width : 0;
587
566
  if (windowDimensions) {
588
- return direction === 'right' ? containerSize.width - width : -containerSize.width + width;
567
+ return direction === "right" ? containerSize.width - width : -containerSize.width + width;
589
568
  }
590
569
  return width;
591
- })) != null ? _snapPoints_map : [];
570
+ }) ?? [];
592
571
  }, [
593
572
  snapPoints,
594
573
  windowDimensions,
595
574
  container
596
575
  ]);
597
- const activeSnapPointOffset = React__namespace.default.useMemo(()=>activeSnapPointIndex !== null ? snapPointsOffset == null ? void 0 : snapPointsOffset[activeSnapPointIndex] : null, [
576
+ const activeSnapPointOffset = React__default.useMemo(()=>activeSnapPointIndex !== null ? snapPointsOffset?.[activeSnapPointIndex] : null, [
598
577
  snapPointsOffset,
599
578
  activeSnapPointIndex
600
579
  ]);
601
- const snapToPoint = React__namespace.default.useCallback((dimension)=>{
602
- var _snapPointsOffset_findIndex;
603
- const newSnapPointIndex = (_snapPointsOffset_findIndex = snapPointsOffset == null ? void 0 : snapPointsOffset.findIndex((snapPointDim)=>snapPointDim === dimension)) != null ? _snapPointsOffset_findIndex : null;
580
+ const snapToPoint = React__default.useCallback((dimension)=>{
581
+ const newSnapPointIndex = snapPointsOffset?.findIndex((snapPointDim)=>snapPointDim === dimension) ?? null;
604
582
  onSnapPointChange(newSnapPointIndex);
605
583
  set(drawerRef.current, {
606
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
584
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
607
585
  transform: isVertical(direction) ? `translate3d(0, ${dimension}px, 0)` : `translate3d(${dimension}px, 0, 0)`
608
586
  });
609
587
  if (snapPointsOffset && newSnapPointIndex !== snapPointsOffset.length - 1 && fadeFromIndex !== undefined && newSnapPointIndex !== fadeFromIndex && newSnapPointIndex < fadeFromIndex) {
610
588
  set(overlayRef.current, {
611
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
612
- opacity: '0'
589
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
590
+ opacity: "0"
613
591
  });
614
592
  } else {
615
593
  set(overlayRef.current, {
616
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
617
- opacity: '1'
594
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
595
+ opacity: "1"
618
596
  });
619
597
  }
620
- setActiveSnapPoint(snapPoints == null ? void 0 : snapPoints[Math.max(newSnapPointIndex, 0)]);
598
+ setActiveSnapPoint(snapPoints?.[Math.max(newSnapPointIndex, 0)]);
621
599
  }, [
622
600
  drawerRef.current,
623
601
  snapPoints,
@@ -626,11 +604,10 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
626
604
  overlayRef,
627
605
  setActiveSnapPoint
628
606
  ]);
629
- React__namespace.default.useEffect(()=>{
607
+ React__default.useEffect(()=>{
630
608
  if (activeSnapPoint || activeSnapPointProp) {
631
- var _snapPoints_findIndex;
632
- const newIndex = (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : -1;
633
- if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === 'number') {
609
+ const newIndex = snapPoints?.findIndex((snapPoint)=>snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint) ?? -1;
610
+ if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === "number") {
634
611
  snapToPoint(snapPointsOffset[newIndex]);
635
612
  }
636
613
  }
@@ -643,13 +620,13 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
643
620
  ]);
644
621
  function onRelease({ draggedDistance, closeDrawer, velocity, dismissible }) {
645
622
  if (fadeFromIndex === undefined) return;
646
- const currentPosition = direction === 'bottom' || direction === 'right' ? (activeSnapPointOffset != null ? activeSnapPointOffset : 0) - draggedDistance : (activeSnapPointOffset != null ? activeSnapPointOffset : 0) + draggedDistance;
623
+ const currentPosition = direction === "bottom" || direction === "right" ? (activeSnapPointOffset ?? 0) - draggedDistance : (activeSnapPointOffset ?? 0) + draggedDistance;
647
624
  const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
648
625
  const isFirst = activeSnapPointIndex === 0;
649
626
  const hasDraggedUp = draggedDistance > 0;
650
627
  if (isOverlaySnapPoint) {
651
628
  set(overlayRef.current, {
652
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
629
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`
653
630
  });
654
631
  }
655
632
  if (!snapToSequentialPoint && velocity > 2 && !hasDraggedUp) {
@@ -662,8 +639,8 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
662
639
  return;
663
640
  }
664
641
  // Find the closest snap point to the current position
665
- const closestSnapPoint = snapPointsOffset == null ? void 0 : snapPointsOffset.reduce((prev, curr)=>{
666
- if (typeof prev !== 'number' || typeof curr !== 'number') return prev;
642
+ const closestSnapPoint = snapPointsOffset?.reduce((prev, curr)=>{
643
+ if (typeof prev !== "number" || typeof curr !== "number") return prev;
667
644
  return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
668
645
  });
669
646
  const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
@@ -685,12 +662,12 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
685
662
  }
686
663
  function onDrag({ draggedDistance }) {
687
664
  if (activeSnapPointOffset === null) return;
688
- const newValue = direction === 'bottom' || direction === 'right' ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;
665
+ const newValue = direction === "bottom" || direction === "right" ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;
689
666
  // Don't do anything if we exceed the last(biggest) snap point
690
- if ((direction === 'bottom' || direction === 'right') && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {
667
+ if ((direction === "bottom" || direction === "right") && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {
691
668
  return;
692
669
  }
693
- if ((direction === 'top' || direction === 'left') && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {
670
+ if ((direction === "top" || direction === "left") && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {
694
671
  return;
695
672
  }
696
673
  set(drawerRef.current, {
@@ -698,7 +675,7 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
698
675
  });
699
676
  }
700
677
  function getPercentageDragged(absDraggedDistance, isDraggingDown) {
701
- if (!snapPoints || typeof activeSnapPointIndex !== 'number' || !snapPointsOffset || fadeFromIndex === undefined) return null;
678
+ if (!snapPoints || typeof activeSnapPointIndex !== "number" || !snapPointsOffset || fadeFromIndex === undefined) return null;
702
679
  // If this is true we are dragging to a snap point that is supposed to have an overlay
703
680
  const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
704
681
  const isOverlaySnapPointOrHigher = activeSnapPointIndex >= fadeFromIndex;
@@ -735,12 +712,12 @@ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints
735
712
  const noop = ()=>()=>{};
736
713
  function useScaleBackground() {
737
714
  const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();
738
- const timeoutIdRef = React__namespace.default.useRef(null);
739
- const initialBackgroundColor = React.useMemo(()=>document.body.style.backgroundColor, []);
715
+ const timeoutIdRef = React__default.useRef(null);
716
+ const initialBackgroundColor = useMemo(()=>document.body.style.backgroundColor, []);
740
717
  function getScale() {
741
718
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
742
719
  }
743
- React__namespace.default.useEffect(()=>{
720
+ React__default.useEffect(()=>{
744
721
  if (isOpen && shouldScaleBackground) {
745
722
  if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);
746
723
  const wrapper = document.querySelector('[data-vaul-drawer-wrapper]') || document.querySelector('[vaul-drawer-wrapper]');
@@ -789,9 +766,9 @@ let previousBodyPosition = null;
789
766
  * https://github.com/emilkowalski/vaul/issues/433
790
767
  * And more that I discovered, but were just not reported.
791
768
  */ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollRestoration, noBodyStyles }) {
792
- const [activeUrl, setActiveUrl] = React__namespace.default.useState(()=>typeof window !== 'undefined' ? window.location.href : '');
793
- const scrollPos = React__namespace.default.useRef(0);
794
- const setPositionFixed = React__namespace.default.useCallback(()=>{
769
+ const [activeUrl, setActiveUrl] = React__default.useState(()=>typeof window !== 'undefined' ? window.location.href : '');
770
+ const scrollPos = React__default.useRef(0);
771
+ const setPositionFixed = React__default.useCallback(()=>{
795
772
  // All browsers on iOS will return true here.
796
773
  if (!isSafari()) return;
797
774
  // If previousBodyPosition is already set, don't set it again.
@@ -824,7 +801,7 @@ let previousBodyPosition = null;
824
801
  }, [
825
802
  isOpen
826
803
  ]);
827
- const restorePositionSetting = React__namespace.default.useCallback(()=>{
804
+ const restorePositionSetting = React__default.useCallback(()=>{
828
805
  // All browsers on iOS will return true here.
829
806
  if (!isSafari()) return;
830
807
  if (previousBodyPosition !== null && !noBodyStyles) {
@@ -845,7 +822,7 @@ let previousBodyPosition = null;
845
822
  }, [
846
823
  activeUrl
847
824
  ]);
848
- React__namespace.default.useEffect(()=>{
825
+ React__default.useEffect(()=>{
849
826
  function onScroll() {
850
827
  scrollPos.current = window.scrollY;
851
828
  }
@@ -855,7 +832,7 @@ let previousBodyPosition = null;
855
832
  window.removeEventListener('scroll', onScroll);
856
833
  };
857
834
  }, []);
858
- React__namespace.default.useEffect(()=>{
835
+ React__default.useEffect(()=>{
859
836
  if (!modal) return;
860
837
  return ()=>{
861
838
  if (typeof document === 'undefined') return;
@@ -868,7 +845,7 @@ let previousBodyPosition = null;
868
845
  modal,
869
846
  restorePositionSetting
870
847
  ]);
871
- React__namespace.default.useEffect(()=>{
848
+ React__default.useEffect(()=>{
872
849
  if (nested || !hasBeenOpened) return;
873
850
  // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happening
874
851
  if (isOpen) {
@@ -897,51 +874,50 @@ let previousBodyPosition = null;
897
874
  };
898
875
  }
899
876
 
900
- function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground = false, setBackgroundColorOnScale = true, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = false, direction = 'bottom', defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false }) {
901
- var _drawerRef_current, _drawerRef_current1;
877
+ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRelease: onReleaseProp, snapPoints, shouldScaleBackground = false, setBackgroundColorOnScale = true, closeThreshold = CLOSE_THRESHOLD, scrollLockTimeout = SCROLL_LOCK_TIMEOUT, dismissible = true, handleOnly = false, fadeFromIndex = snapPoints && snapPoints.length - 1, activeSnapPoint: activeSnapPointProp, setActiveSnapPoint: setActiveSnapPointProp, fixed, modal = true, onClose, nested, noBodyStyles = false, direction = "bottom", defaultOpen = false, disablePreventScroll = true, snapToSequentialPoint = false, preventScrollRestoration = false, repositionInputs = true, onAnimationEnd, container, autoFocus = false }) {
902
878
  const [isOpen = false, setIsOpen] = useControllableState({
903
879
  defaultProp: defaultOpen,
904
880
  prop: openProp,
905
881
  onChange: (o)=>{
906
- onOpenChange == null ? void 0 : onOpenChange(o);
882
+ onOpenChange?.(o);
907
883
  if (!o && !nested) {
908
884
  restorePositionSetting();
909
885
  }
910
886
  setTimeout(()=>{
911
- onAnimationEnd == null ? void 0 : onAnimationEnd(o);
887
+ onAnimationEnd?.(o);
912
888
  }, TRANSITIONS.DURATION * 1000);
913
889
  if (o && !modal) {
914
- if (typeof window !== 'undefined') {
890
+ if (typeof window !== "undefined") {
915
891
  window.requestAnimationFrame(()=>{
916
- document.body.style.pointerEvents = 'auto';
892
+ document.body.style.pointerEvents = "auto";
917
893
  });
918
894
  }
919
895
  }
920
896
  if (!o) {
921
897
  // This will be removed when the exit animation ends (`500ms`)
922
- document.body.style.pointerEvents = 'auto';
898
+ document.body.style.pointerEvents = "auto";
923
899
  }
924
900
  }
925
901
  });
926
- const [hasBeenOpened, setHasBeenOpened] = React__namespace.default.useState(false);
927
- const [isDragging, setIsDragging] = React__namespace.default.useState(false);
928
- const [justReleased, setJustReleased] = React__namespace.default.useState(false);
929
- const overlayRef = React__namespace.default.useRef(null);
930
- const openTime = React__namespace.default.useRef(null);
931
- const dragStartTime = React__namespace.default.useRef(null);
932
- const dragEndTime = React__namespace.default.useRef(null);
933
- const lastTimeDragPrevented = React__namespace.default.useRef(null);
934
- const isAllowedToDrag = React__namespace.default.useRef(false);
935
- const nestedOpenChangeTimer = React__namespace.default.useRef(null);
936
- const pointerStart = React__namespace.default.useRef(0);
937
- const keyboardIsOpen = React__namespace.default.useRef(false);
938
- const shouldAnimate = React__namespace.default.useRef(!defaultOpen);
939
- const previousDiffFromInitial = React__namespace.default.useRef(0);
940
- const drawerRef = React__namespace.default.useRef(null);
941
- const drawerHeightRef = React__namespace.default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
942
- const drawerWidthRef = React__namespace.default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
943
- const initialDrawerHeight = React__namespace.default.useRef(0);
944
- const onSnapPointChange = React__namespace.default.useCallback((activeSnapPointIndex)=>{
902
+ const [hasBeenOpened, setHasBeenOpened] = React__default.useState(false);
903
+ const [isDragging, setIsDragging] = React__default.useState(false);
904
+ const [justReleased, setJustReleased] = React__default.useState(false);
905
+ const overlayRef = React__default.useRef(null);
906
+ const openTime = React__default.useRef(null);
907
+ const dragStartTime = React__default.useRef(null);
908
+ const dragEndTime = React__default.useRef(null);
909
+ const lastTimeDragPrevented = React__default.useRef(null);
910
+ const isAllowedToDrag = React__default.useRef(false);
911
+ const nestedOpenChangeTimer = React__default.useRef(null);
912
+ const pointerStart = React__default.useRef(0);
913
+ const keyboardIsOpen = React__default.useRef(false);
914
+ const shouldAnimate = React__default.useRef(!defaultOpen);
915
+ const previousDiffFromInitial = React__default.useRef(0);
916
+ const drawerRef = React__default.useRef(null);
917
+ const drawerHeightRef = React__default.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
918
+ const drawerWidthRef = React__default.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
919
+ const initialDrawerHeight = React__default.useRef(0);
920
+ const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{
945
921
  // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
946
922
  if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
947
923
  }, []);
@@ -963,7 +939,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
963
939
  const { restorePositionSetting } = usePositionFixed({
964
940
  isOpen,
965
941
  modal,
966
- nested: nested != null ? nested : false,
942
+ nested: nested ?? false,
967
943
  hasBeenOpened,
968
944
  preventScrollRestoration,
969
945
  noBodyStyles
@@ -972,16 +948,15 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
972
948
  return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
973
949
  }
974
950
  function onPress(event) {
975
- var _drawerRef_current, _drawerRef_current1;
976
951
  if (!dismissible && !snapPoints) return;
977
952
  if (drawerRef.current && !drawerRef.current.contains(event.target)) return;
978
- drawerHeightRef.current = ((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0;
979
- drawerWidthRef.current = ((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0;
953
+ drawerHeightRef.current = drawerRef.current?.getBoundingClientRect().height || 0;
954
+ drawerWidthRef.current = drawerRef.current?.getBoundingClientRect().width || 0;
980
955
  setIsDragging(true);
981
956
  dragStartTime.current = new Date();
982
957
  // iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging
983
958
  if (isIOS()) {
984
- window.addEventListener('touchend', ()=>isAllowedToDrag.current = false, {
959
+ window.addEventListener("touchend", ()=>isAllowedToDrag.current = false, {
985
960
  once: true
986
961
  });
987
962
  }
@@ -990,19 +965,18 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
990
965
  pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
991
966
  }
992
967
  function shouldDrag(el, isDraggingInDirection) {
993
- var _window_getSelection;
994
968
  let element = el;
995
- const highlightedText = (_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString();
969
+ const highlightedText = window.getSelection()?.toString();
996
970
  const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
997
971
  const date = new Date();
998
972
  // Fixes https://github.com/emilkowalski/vaul/issues/483
999
- if (element.tagName === 'SELECT') {
973
+ if (element.tagName === "SELECT") {
1000
974
  return false;
1001
975
  }
1002
- if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {
976
+ if (element.hasAttribute("data-vaul-no-drag") || element.closest("[data-vaul-no-drag]")) {
1003
977
  return false;
1004
978
  }
1005
- if (direction === 'right' || direction === 'left') {
979
+ if (direction === "right" || direction === "left") {
1006
980
  return true;
1007
981
  }
1008
982
  // Allow scrolling when animating
@@ -1010,7 +984,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1010
984
  return false;
1011
985
  }
1012
986
  if (swipeAmount !== null) {
1013
- if (direction === 'bottom' ? swipeAmount > 0 : swipeAmount < 0) {
987
+ if (direction === "bottom" ? swipeAmount > 0 : swipeAmount < 0) {
1014
988
  return true;
1015
989
  }
1016
990
  }
@@ -1037,7 +1011,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1037
1011
  // The element is scrollable and not scrolled to the top, so don't drag
1038
1012
  return false;
1039
1013
  }
1040
- if (element.getAttribute('role') === 'dialog') {
1014
+ if (element.getAttribute("role") === "dialog") {
1041
1015
  return true;
1042
1016
  }
1043
1017
  }
@@ -1053,7 +1027,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1053
1027
  }
1054
1028
  // We need to know how much of the drawer has been dragged in percentages so that we can transform background accordingly
1055
1029
  if (isDragging) {
1056
- const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
1030
+ const directionMultiplier = direction === "bottom" || direction === "right" ? 1 : -1;
1057
1031
  const draggedDistance = (pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX)) * directionMultiplier;
1058
1032
  const isDraggingInDirection = draggedDistance > 0;
1059
1033
  // Pre condition for disallowing dragging in the close direction.
@@ -1062,8 +1036,8 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1062
1036
  if (noCloseSnapPointsPreCondition && activeSnapPointIndex === 0) return;
1063
1037
  // We need to capture last time when drag with scroll was triggered and have a timeout between
1064
1038
  const absDraggedDistance = Math.abs(draggedDistance);
1065
- const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
1066
- const drawerDimension = direction === 'bottom' || direction === 'top' ? drawerHeightRef.current : drawerWidthRef.current;
1039
+ const wrapper = document.querySelector("[data-vaul-drawer-wrapper]");
1040
+ const drawerDimension = direction === "bottom" || direction === "top" ? drawerHeightRef.current : drawerWidthRef.current;
1067
1041
  // Calculate the percentage dragged, where 1 is the closed position
1068
1042
  let percentageDragged = absDraggedDistance / drawerDimension;
1069
1043
  const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);
@@ -1079,10 +1053,10 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1079
1053
  // If shouldDrag gave true once after pressing down on the drawer, we set isAllowedToDrag to true and it will remain true until we let go, there's no reason to disable dragging mid way, ever, and that's the solution to it
1080
1054
  isAllowedToDrag.current = true;
1081
1055
  set(drawerRef.current, {
1082
- transition: 'none'
1056
+ transition: "none"
1083
1057
  });
1084
1058
  set(overlayRef.current, {
1085
- transition: 'none'
1059
+ transition: "none"
1086
1060
  });
1087
1061
  if (snapPoints) {
1088
1062
  onDragSnapPoints({
@@ -1100,10 +1074,10 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1100
1074
  }
1101
1075
  const opacityValue = 1 - percentageDragged;
1102
1076
  if (shouldFade || fadeFromIndex && activeSnapPointIndex === fadeFromIndex - 1) {
1103
- onDragProp == null ? void 0 : onDragProp(event, percentageDragged);
1077
+ onDragProp?.(event, percentageDragged);
1104
1078
  set(overlayRef.current, {
1105
1079
  opacity: `${opacityValue}`,
1106
- transition: 'none'
1080
+ transition: "none"
1107
1081
  }, true);
1108
1082
  }
1109
1083
  if (wrapper && overlayRef.current && shouldScaleBackground) {
@@ -1114,7 +1088,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1114
1088
  set(wrapper, {
1115
1089
  borderRadius: `${borderRadiusValue}px`,
1116
1090
  transform: isVertical(direction) ? `scale(${scaleValue}) translate3d(0, ${translateValue}px, 0)` : `scale(${scaleValue}) translate3d(${translateValue}px, 0, 0)`,
1117
- transition: 'none'
1091
+ transition: "none"
1118
1092
  }, true);
1119
1093
  }
1120
1094
  if (!snapPoints) {
@@ -1125,19 +1099,17 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1125
1099
  }
1126
1100
  }
1127
1101
  }
1128
- React__namespace.default.useEffect(()=>{
1102
+ React__default.useEffect(()=>{
1129
1103
  window.requestAnimationFrame(()=>{
1130
1104
  shouldAnimate.current = true;
1131
1105
  });
1132
1106
  }, []);
1133
- React__namespace.default.useEffect(()=>{
1134
- var _window_visualViewport;
1107
+ React__default.useEffect(()=>{
1135
1108
  function onVisualViewportChange() {
1136
1109
  if (!drawerRef.current || !repositionInputs) return;
1137
1110
  const focusedElement = document.activeElement;
1138
1111
  if (isInput(focusedElement) || keyboardIsOpen.current) {
1139
- var _window_visualViewport;
1140
- const visualViewportHeight = ((_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.height) || 0;
1112
+ const visualViewportHeight = window.visualViewport?.height || 0;
1141
1113
  const totalHeight = window.innerHeight;
1142
1114
  // This is the height of the keyboard
1143
1115
  let diffFromInitial = totalHeight - visualViewportHeight;
@@ -1181,11 +1153,8 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1181
1153
  }
1182
1154
  }
1183
1155
  }
1184
- (_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.addEventListener('resize', onVisualViewportChange);
1185
- return ()=>{
1186
- var _window_visualViewport;
1187
- return (_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.removeEventListener('resize', onVisualViewportChange);
1188
- };
1156
+ window.visualViewport?.addEventListener("resize", onVisualViewportChange);
1157
+ return ()=>window.visualViewport?.removeEventListener("resize", onVisualViewportChange);
1189
1158
  }, [
1190
1159
  activeSnapPointIndex,
1191
1160
  snapPoints,
@@ -1193,7 +1162,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1193
1162
  ]);
1194
1163
  function closeDrawer(fromWithin) {
1195
1164
  cancelDrag();
1196
- onClose == null ? void 0 : onClose();
1165
+ onClose?.();
1197
1166
  if (!fromWithin) {
1198
1167
  setIsOpen(false);
1199
1168
  }
@@ -1205,31 +1174,31 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1205
1174
  }
1206
1175
  function resetDrawer() {
1207
1176
  if (!drawerRef.current) return;
1208
- const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
1177
+ const wrapper = document.querySelector("[data-vaul-drawer-wrapper]");
1209
1178
  const currentSwipeAmount = getTranslate(drawerRef.current, direction);
1210
1179
  set(drawerRef.current, {
1211
- transform: 'translate3d(0, 0, 0)',
1212
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
1180
+ transform: "translate3d(0, 0, 0)",
1181
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`
1213
1182
  });
1214
1183
  set(overlayRef.current, {
1215
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1216
- opacity: '1'
1184
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
1185
+ opacity: "1"
1217
1186
  });
1218
1187
  // Don't reset background if swiped upwards
1219
1188
  if (shouldScaleBackground && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) {
1220
1189
  set(wrapper, {
1221
1190
  borderRadius: `${BORDER_RADIUS}px`,
1222
- overflow: 'hidden',
1191
+ overflow: "hidden",
1223
1192
  ...isVertical(direction) ? {
1224
1193
  transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
1225
- transformOrigin: 'top'
1194
+ transformOrigin: "top"
1226
1195
  } : {
1227
1196
  transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
1228
- transformOrigin: 'left'
1197
+ transformOrigin: "left"
1229
1198
  },
1230
- transitionProperty: 'transform, border-radius',
1199
+ transitionProperty: "transform, border-radius",
1231
1200
  transitionDuration: `${TRANSITIONS.DURATION}s`,
1232
- transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`
1201
+ transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(",")})`
1233
1202
  }, true);
1234
1203
  }
1235
1204
  }
@@ -1260,50 +1229,48 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1260
1229
  }, 200);
1261
1230
  }
1262
1231
  if (snapPoints) {
1263
- const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
1232
+ const directionMultiplier = direction === "bottom" || direction === "right" ? 1 : -1;
1264
1233
  onReleaseSnapPoints({
1265
1234
  draggedDistance: distMoved * directionMultiplier,
1266
1235
  closeDrawer,
1267
1236
  velocity,
1268
1237
  dismissible
1269
1238
  });
1270
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1239
+ onReleaseProp?.(event, true);
1271
1240
  return;
1272
1241
  }
1273
1242
  // Moved upwards, don't do anything
1274
- if (direction === 'bottom' || direction === 'right' ? distMoved > 0 : distMoved < 0) {
1243
+ if (direction === "bottom" || direction === "right" ? distMoved > 0 : distMoved < 0) {
1275
1244
  resetDrawer();
1276
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1245
+ onReleaseProp?.(event, true);
1277
1246
  return;
1278
1247
  }
1279
1248
  if (velocity > VELOCITY_THRESHOLD) {
1280
1249
  closeDrawer();
1281
- onReleaseProp == null ? void 0 : onReleaseProp(event, false);
1250
+ onReleaseProp?.(event, false);
1282
1251
  return;
1283
1252
  }
1284
- var _drawerRef_current_getBoundingClientRect_height;
1285
- const visibleDrawerHeight = Math.min((_drawerRef_current_getBoundingClientRect_height = drawerRef.current.getBoundingClientRect().height) != null ? _drawerRef_current_getBoundingClientRect_height : 0, window.innerHeight);
1286
- var _drawerRef_current_getBoundingClientRect_width;
1287
- const visibleDrawerWidth = Math.min((_drawerRef_current_getBoundingClientRect_width = drawerRef.current.getBoundingClientRect().width) != null ? _drawerRef_current_getBoundingClientRect_width : 0, window.innerWidth);
1288
- const isHorizontalSwipe = direction === 'left' || direction === 'right';
1253
+ const visibleDrawerHeight = Math.min(drawerRef.current.getBoundingClientRect().height ?? 0, window.innerHeight);
1254
+ const visibleDrawerWidth = Math.min(drawerRef.current.getBoundingClientRect().width ?? 0, window.innerWidth);
1255
+ const isHorizontalSwipe = direction === "left" || direction === "right";
1289
1256
  if (Math.abs(swipeAmount) >= (isHorizontalSwipe ? visibleDrawerWidth : visibleDrawerHeight) * closeThreshold) {
1290
1257
  closeDrawer();
1291
- onReleaseProp == null ? void 0 : onReleaseProp(event, false);
1258
+ onReleaseProp?.(event, false);
1292
1259
  return;
1293
1260
  }
1294
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1261
+ onReleaseProp?.(event, true);
1295
1262
  resetDrawer();
1296
1263
  }
1297
- React__namespace.default.useEffect(()=>{
1264
+ React__default.useEffect(()=>{
1298
1265
  // Trigger enter animation without using CSS animation
1299
1266
  if (isOpen) {
1300
1267
  set(document.documentElement, {
1301
- scrollBehavior: 'auto'
1268
+ scrollBehavior: "auto"
1302
1269
  });
1303
1270
  openTime.current = new Date();
1304
1271
  }
1305
1272
  return ()=>{
1306
- reset(document.documentElement, 'scrollBehavior');
1273
+ reset(document.documentElement, "scrollBehavior");
1307
1274
  };
1308
1275
  }, [
1309
1276
  isOpen
@@ -1315,14 +1282,14 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1315
1282
  window.clearTimeout(nestedOpenChangeTimer.current);
1316
1283
  }
1317
1284
  set(drawerRef.current, {
1318
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1285
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
1319
1286
  transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)` : `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`
1320
1287
  });
1321
1288
  if (!o && drawerRef.current) {
1322
1289
  nestedOpenChangeTimer.current = setTimeout(()=>{
1323
1290
  const translateValue = getTranslate(drawerRef.current, direction);
1324
1291
  set(drawerRef.current, {
1325
- transition: 'none',
1292
+ transition: "none",
1326
1293
  transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
1327
1294
  });
1328
1295
  }, 500);
@@ -1335,7 +1302,7 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1335
1302
  const newTranslate = -NESTED_DISPLACEMENT + percentageDragged * NESTED_DISPLACEMENT;
1336
1303
  set(drawerRef.current, {
1337
1304
  transform: isVertical(direction) ? `scale(${newScale}) translate3d(0, ${newTranslate}px, 0)` : `scale(${newScale}) translate3d(${newTranslate}px, 0, 0)`,
1338
- transition: 'none'
1305
+ transition: "none"
1339
1306
  });
1340
1307
  }
1341
1308
  function onNestedRelease(_event, o) {
@@ -1344,22 +1311,22 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1344
1311
  const translate = o ? -NESTED_DISPLACEMENT : 0;
1345
1312
  if (o) {
1346
1313
  set(drawerRef.current, {
1347
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1314
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
1348
1315
  transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${translate}px, 0)` : `scale(${scale}) translate3d(${translate}px, 0, 0)`
1349
1316
  });
1350
1317
  }
1351
1318
  }
1352
- React__namespace.default.useEffect(()=>{
1319
+ React__default.useEffect(()=>{
1353
1320
  if (!modal) {
1354
1321
  // Need to do this manually unfortunately
1355
1322
  window.requestAnimationFrame(()=>{
1356
- document.body.style.pointerEvents = 'auto';
1323
+ document.body.style.pointerEvents = "auto";
1357
1324
  });
1358
1325
  }
1359
1326
  }, [
1360
1327
  modal
1361
1328
  ]);
1362
- return /*#__PURE__*/ React__namespace.default.createElement(react.Dialog.Root, {
1329
+ return /*#__PURE__*/ jsx(Dialog.Root, {
1363
1330
  defaultOpen: defaultOpen,
1364
1331
  onOpenChange: (open)=>{
1365
1332
  if (!dismissible && !open) return;
@@ -1371,71 +1338,73 @@ function Root({ open: openProp, onOpenChange, children, onDrag: onDragProp, onRe
1371
1338
  setIsOpen(open);
1372
1339
  },
1373
1340
  open: isOpen,
1374
- modal: modal
1375
- }, /*#__PURE__*/ React__namespace.default.createElement(DrawerContext.Provider, {
1376
- value: {
1377
- activeSnapPoint,
1378
- snapPoints,
1379
- setActiveSnapPoint,
1380
- drawerRef,
1381
- overlayRef,
1382
- onOpenChange,
1383
- onPress,
1384
- onRelease,
1385
- onDrag,
1386
- dismissible,
1387
- shouldAnimate,
1388
- handleOnly,
1389
- isOpen,
1390
- isDragging,
1391
- shouldFade,
1392
- closeDrawer,
1393
- onNestedDrag,
1394
- onNestedOpenChange,
1395
- onNestedRelease,
1396
- keyboardIsOpen,
1397
- modal,
1398
- snapPointsOffset,
1399
- activeSnapPointIndex,
1400
- direction,
1401
- shouldScaleBackground,
1402
- setBackgroundColorOnScale,
1403
- noBodyStyles,
1404
- container,
1405
- autoFocus
1406
- }
1407
- }, children));
1341
+ modal: modal,
1342
+ children: /*#__PURE__*/ jsx(DrawerContext.Provider, {
1343
+ value: {
1344
+ activeSnapPoint,
1345
+ snapPoints,
1346
+ setActiveSnapPoint,
1347
+ drawerRef,
1348
+ overlayRef,
1349
+ onOpenChange,
1350
+ onPress,
1351
+ onRelease,
1352
+ onDrag,
1353
+ dismissible,
1354
+ shouldAnimate,
1355
+ handleOnly,
1356
+ isOpen,
1357
+ isDragging,
1358
+ shouldFade,
1359
+ closeDrawer,
1360
+ onNestedDrag,
1361
+ onNestedOpenChange,
1362
+ onNestedRelease,
1363
+ keyboardIsOpen,
1364
+ modal,
1365
+ snapPointsOffset,
1366
+ activeSnapPointIndex,
1367
+ direction,
1368
+ shouldScaleBackground,
1369
+ setBackgroundColorOnScale,
1370
+ noBodyStyles,
1371
+ container,
1372
+ autoFocus
1373
+ },
1374
+ children: children
1375
+ })
1376
+ });
1408
1377
  }
1409
- const Overlay = /*#__PURE__*/ React__namespace.default.forwardRef(function({ ...rest }, ref) {
1378
+ const Overlay = /*#__PURE__*/ React__default.forwardRef(function({ ...rest }, ref) {
1410
1379
  const { overlayRef, snapPoints, onRelease, shouldFade, isOpen, modal, shouldAnimate } = useDrawerContext();
1411
1380
  const composedRef = useComposedRefs(ref, overlayRef);
1412
1381
  const hasSnapPoints = snapPoints && snapPoints.length > 0;
1413
- const onMouseUp = React__namespace.default.useCallback((event)=>onRelease(event), [
1382
+ const onMouseUp = React__default.useCallback((event)=>onRelease(event), [
1414
1383
  onRelease
1415
1384
  ]);
1416
1385
  // Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
1417
1386
  if (!modal) {
1418
1387
  return null;
1419
1388
  }
1420
- return /*#__PURE__*/ React__namespace.default.createElement(react.Dialog.Backdrop, {
1389
+ return /*#__PURE__*/ jsx(Dialog.Backdrop, {
1421
1390
  onMouseUp: onMouseUp,
1422
1391
  ref: composedRef,
1423
1392
  "data-vaul-overlay": "",
1424
- "data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
1425
- "data-vaul-snap-points-overlay": isOpen && shouldFade ? 'true' : 'false',
1426
- "data-vaul-animate": (shouldAnimate == null ? void 0 : shouldAnimate.current) ? 'true' : 'false',
1393
+ "data-vaul-snap-points": isOpen && hasSnapPoints ? "true" : "false",
1394
+ "data-vaul-snap-points-overlay": isOpen && shouldFade ? "true" : "false",
1395
+ "data-vaul-animate": shouldAnimate?.current ? "true" : "false",
1427
1396
  ...rest
1428
1397
  });
1429
1398
  });
1430
- Overlay.displayName = 'Drawer.Overlay';
1431
- const Content = /*#__PURE__*/ React__namespace.default.forwardRef(function({ style, ...rest }, ref) {
1399
+ Overlay.displayName = "Drawer.Overlay";
1400
+ const Content = /*#__PURE__*/ React__default.forwardRef(function({ style, ...rest }, ref) {
1432
1401
  const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, shouldAnimate, autoFocus } = useDrawerContext();
1433
1402
  // Needed to use transition instead of animations
1434
- const [delayedSnapPoints, setDelayedSnapPoints] = React__namespace.default.useState(false);
1403
+ const [delayedSnapPoints, setDelayedSnapPoints] = React__default.useState(false);
1435
1404
  const composedRef = useComposedRefs(ref, drawerRef);
1436
- const pointerStartRef = React__namespace.default.useRef(null);
1437
- const lastKnownPointerEventRef = React__namespace.default.useRef(null);
1438
- const wasBeyondThePointRef = React__namespace.default.useRef(false);
1405
+ const pointerStartRef = React__default.useRef(null);
1406
+ const lastKnownPointerEventRef = React__default.useRef(null);
1407
+ const wasBeyondThePointRef = React__default.useRef(false);
1439
1408
  const hasSnapPoints = snapPoints && snapPoints.length > 0;
1440
1409
  useScaleBackground();
1441
1410
  const isDeltaInDirection = (delta, direction, threshold = 0)=>{
@@ -1444,10 +1413,10 @@ const Content = /*#__PURE__*/ React__namespace.default.forwardRef(function({ sty
1444
1413
  const deltaX = Math.abs(delta.x);
1445
1414
  const isDeltaX = deltaX > deltaY;
1446
1415
  const dFactor = [
1447
- 'bottom',
1448
- 'right'
1416
+ "bottom",
1417
+ "right"
1449
1418
  ].includes(direction) ? 1 : -1;
1450
- if (direction === 'left' || direction === 'right') {
1419
+ if (direction === "left" || direction === "right") {
1451
1420
  const isReverseDirection = delta.x * dFactor < 0;
1452
1421
  if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
1453
1422
  return isDeltaX;
@@ -1461,7 +1430,7 @@ const Content = /*#__PURE__*/ React__namespace.default.forwardRef(function({ sty
1461
1430
  wasBeyondThePointRef.current = true;
1462
1431
  return true;
1463
1432
  };
1464
- React__namespace.default.useEffect(()=>{
1433
+ React__default.useEffect(()=>{
1465
1434
  if (hasSnapPoints) {
1466
1435
  window.requestAnimationFrame(()=>{
1467
1436
  setDelayedSnapPoints(true);
@@ -1473,72 +1442,74 @@ const Content = /*#__PURE__*/ React__namespace.default.forwardRef(function({ sty
1473
1442
  wasBeyondThePointRef.current = false;
1474
1443
  onRelease(event);
1475
1444
  }
1476
- return /*#__PURE__*/ React__namespace.default.createElement(react.Dialog.Viewport, null, /*#__PURE__*/ React__namespace.default.createElement(react.Dialog.Popup, {
1477
- "data-vaul-drawer-direction": direction,
1478
- "data-vaul-drawer": "",
1479
- "data-vaul-delayed-snap-points": delayedSnapPoints ? 'true' : 'false',
1480
- "data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
1481
- "data-vaul-custom-container": container ? 'true' : 'false',
1482
- "data-vaul-animate": (shouldAnimate == null ? void 0 : shouldAnimate.current) ? 'true' : 'false',
1483
- ...rest,
1484
- ref: composedRef,
1485
- style: snapPointsOffset && snapPointsOffset.length > 0 ? {
1486
- // @ts-ignore This should not be an error
1487
- '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex != null ? activeSnapPointIndex : 0]}px`,
1488
- ...style
1489
- } : style,
1490
- onPointerDown: (event)=>{
1491
- if (handleOnly) return;
1492
- rest.onPointerDown == null ? void 0 : rest.onPointerDown.call(rest, event);
1493
- pointerStartRef.current = {
1494
- x: event.pageX,
1495
- y: event.pageY
1496
- };
1497
- onPress(event);
1498
- },
1499
- onPointerMove: (event)=>{
1500
- lastKnownPointerEventRef.current = event;
1501
- if (handleOnly) return;
1502
- rest.onPointerMove == null ? void 0 : rest.onPointerMove.call(rest, event);
1503
- if (!pointerStartRef.current) return;
1504
- const yPosition = event.pageY - pointerStartRef.current.y;
1505
- const xPosition = event.pageX - pointerStartRef.current.x;
1506
- const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
1507
- const delta = {
1508
- x: xPosition,
1509
- y: yPosition
1510
- };
1511
- const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1512
- if (isAllowedToSwipe) onDrag(event);
1513
- else if (Math.abs(xPosition) > swipeStartThreshold || Math.abs(yPosition) > swipeStartThreshold) {
1445
+ return /*#__PURE__*/ jsx(Dialog.Viewport, {
1446
+ children: /*#__PURE__*/ jsx(Dialog.Popup, {
1447
+ "data-vaul-drawer-direction": direction,
1448
+ "data-vaul-drawer": "",
1449
+ "data-vaul-delayed-snap-points": delayedSnapPoints ? "true" : "false",
1450
+ "data-vaul-snap-points": isOpen && hasSnapPoints ? "true" : "false",
1451
+ "data-vaul-custom-container": container ? "true" : "false",
1452
+ "data-vaul-animate": shouldAnimate?.current ? "true" : "false",
1453
+ ...rest,
1454
+ ref: composedRef,
1455
+ style: snapPointsOffset && snapPointsOffset.length > 0 ? {
1456
+ // @ts-ignore This should not be an error
1457
+ "--snap-point-height": `${snapPointsOffset[activeSnapPointIndex ?? 0]}px`,
1458
+ ...style
1459
+ } : style,
1460
+ onPointerDown: (event)=>{
1461
+ if (handleOnly) return;
1462
+ rest.onPointerDown?.(event);
1463
+ pointerStartRef.current = {
1464
+ x: event.pageX,
1465
+ y: event.pageY
1466
+ };
1467
+ onPress(event);
1468
+ },
1469
+ onPointerMove: (event)=>{
1470
+ lastKnownPointerEventRef.current = event;
1471
+ if (handleOnly) return;
1472
+ rest.onPointerMove?.(event);
1473
+ if (!pointerStartRef.current) return;
1474
+ const yPosition = event.pageY - pointerStartRef.current.y;
1475
+ const xPosition = event.pageX - pointerStartRef.current.x;
1476
+ const swipeStartThreshold = event.pointerType === "touch" ? 10 : 2;
1477
+ const delta = {
1478
+ x: xPosition,
1479
+ y: yPosition
1480
+ };
1481
+ const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1482
+ if (isAllowedToSwipe) onDrag(event);
1483
+ else if (Math.abs(xPosition) > swipeStartThreshold || Math.abs(yPosition) > swipeStartThreshold) {
1484
+ pointerStartRef.current = null;
1485
+ }
1486
+ },
1487
+ onPointerUp: (event)=>{
1488
+ rest.onPointerUp?.(event);
1514
1489
  pointerStartRef.current = null;
1515
- }
1516
- },
1517
- onPointerUp: (event)=>{
1518
- rest.onPointerUp == null ? void 0 : rest.onPointerUp.call(rest, event);
1519
- pointerStartRef.current = null;
1520
- wasBeyondThePointRef.current = false;
1521
- onRelease(event);
1522
- },
1523
- onPointerOut: (event)=>{
1524
- rest.onPointerOut == null ? void 0 : rest.onPointerOut.call(rest, event);
1525
- handleOnPointerUp(lastKnownPointerEventRef.current);
1526
- },
1527
- onContextMenu: (event)=>{
1528
- rest.onContextMenu == null ? void 0 : rest.onContextMenu.call(rest, event);
1529
- if (lastKnownPointerEventRef.current) {
1490
+ wasBeyondThePointRef.current = false;
1491
+ onRelease(event);
1492
+ },
1493
+ onPointerOut: (event)=>{
1494
+ rest.onPointerOut?.(event);
1530
1495
  handleOnPointerUp(lastKnownPointerEventRef.current);
1496
+ },
1497
+ onContextMenu: (event)=>{
1498
+ rest.onContextMenu?.(event);
1499
+ if (lastKnownPointerEventRef.current) {
1500
+ handleOnPointerUp(lastKnownPointerEventRef.current);
1501
+ }
1531
1502
  }
1532
- }
1533
- }));
1503
+ })
1504
+ });
1534
1505
  });
1535
- Content.displayName = 'Drawer.Content';
1506
+ Content.displayName = "Drawer.Content";
1536
1507
  const LONG_HANDLE_PRESS_TIMEOUT = 250;
1537
1508
  const DOUBLE_TAP_TIMEOUT = 120;
1538
- const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ preventCycle = false, children, ...rest }, ref) {
1509
+ const Handle = /*#__PURE__*/ React__default.forwardRef(function({ preventCycle = false, children, ...rest }, ref) {
1539
1510
  const { closeDrawer, isDragging, snapPoints, activeSnapPoint, setActiveSnapPoint, dismissible, handleOnly, isOpen, onPress, onDrag } = useDrawerContext();
1540
- const closeTimeoutIdRef = React__namespace.default.useRef(null);
1541
- const shouldCancelInteractionRef = React__namespace.default.useRef(false);
1511
+ const closeTimeoutIdRef = React__default.useRef(null);
1512
+ const shouldCancelInteractionRef = React__default.useRef(false);
1542
1513
  function handleStartCycle() {
1543
1514
  // Stop if this is the second click of a double click
1544
1515
  if (shouldCancelInteractionRef.current) {
@@ -1585,7 +1556,7 @@ const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ prev
1585
1556
  }
1586
1557
  shouldCancelInteractionRef.current = false;
1587
1558
  }
1588
- return /*#__PURE__*/ React__namespace.default.createElement("div", {
1559
+ return /*#__PURE__*/ jsx("div", {
1589
1560
  onClick: handleStartCycle,
1590
1561
  onPointerCancel: handleCancelInteraction,
1591
1562
  onPointerDown: (e)=>{
@@ -1603,22 +1574,24 @@ const Handle = /*#__PURE__*/ React__namespace.default.forwardRef(function({ prev
1603
1574
  },
1604
1575
  // onPointerUp is already handled by the content component
1605
1576
  ref: ref,
1606
- "data-vaul-drawer-visible": isOpen ? 'true' : 'false',
1577
+ "data-vaul-drawer-visible": isOpen ? "true" : "false",
1607
1578
  "data-vaul-handle": "",
1608
1579
  "aria-hidden": "true",
1609
- ...rest
1610
- }, /*#__PURE__*/ React__namespace.default.createElement("span", {
1611
- "data-vaul-handle-hitarea": "",
1612
- "aria-hidden": "true"
1613
- }, children));
1580
+ ...rest,
1581
+ children: /*#__PURE__*/ jsx("span", {
1582
+ "data-vaul-handle-hitarea": "",
1583
+ "aria-hidden": "true",
1584
+ children: children
1585
+ })
1586
+ });
1614
1587
  });
1615
- Handle.displayName = 'Drawer.Handle';
1588
+ Handle.displayName = "Drawer.Handle";
1616
1589
  function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }) {
1617
1590
  const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();
1618
1591
  if (!onNestedDrag) {
1619
- throw new Error('Drawer.NestedRoot must be placed in another drawer');
1592
+ throw new Error("Drawer.NestedRoot must be placed in another drawer");
1620
1593
  }
1621
- return /*#__PURE__*/ React__namespace.default.createElement(Root, {
1594
+ return /*#__PURE__*/ jsx(Root, {
1622
1595
  nested: true,
1623
1596
  open: nestedIsOpen,
1624
1597
  onClose: ()=>{
@@ -1626,13 +1599,13 @@ function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }) {
1626
1599
  },
1627
1600
  onDrag: (e, p)=>{
1628
1601
  onNestedDrag(e, p);
1629
- onDrag == null ? void 0 : onDrag(e, p);
1602
+ onDrag?.(e, p);
1630
1603
  },
1631
1604
  onOpenChange: (o)=>{
1632
1605
  if (o) {
1633
1606
  onNestedOpenChange(o);
1634
1607
  }
1635
- onOpenChange == null ? void 0 : onOpenChange(o);
1608
+ onOpenChange?.(o);
1636
1609
  },
1637
1610
  onRelease: onNestedRelease,
1638
1611
  ...rest
@@ -1641,7 +1614,7 @@ function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }) {
1641
1614
  function Portal(props) {
1642
1615
  const context = useDrawerContext();
1643
1616
  const { container = context.container, ...portalProps } = props;
1644
- return /*#__PURE__*/ React__namespace.default.createElement(react.Dialog.Portal, {
1617
+ return /*#__PURE__*/ jsx(Dialog.Portal, {
1645
1618
  container: container,
1646
1619
  ...portalProps
1647
1620
  });
@@ -1651,18 +1624,12 @@ const Drawer = {
1651
1624
  NestedRoot,
1652
1625
  Content,
1653
1626
  Overlay,
1654
- Trigger: react.Dialog.Trigger,
1627
+ Trigger: Dialog.Trigger,
1655
1628
  Portal,
1656
1629
  Handle,
1657
- Close: react.Dialog.Close,
1658
- Title: react.Dialog.Title,
1659
- Description: react.Dialog.Description
1630
+ Close: Dialog.Close,
1631
+ Title: Dialog.Title,
1632
+ Description: Dialog.Description
1660
1633
  };
1661
1634
 
1662
- exports.Content = Content;
1663
- exports.Drawer = Drawer;
1664
- exports.Handle = Handle;
1665
- exports.NestedRoot = NestedRoot;
1666
- exports.Overlay = Overlay;
1667
- exports.Portal = Portal;
1668
- exports.Root = Root;
1635
+ export { Content, Drawer, Handle, NestedRoot, Overlay, Portal, Root };