base-vaul 0.0.1 → 0.1.0

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.mjs CHANGED
@@ -1,1641 +1,1282 @@
1
- 'use client';
2
- function __insertCSS(code) {
3
- if (!code || typeof document == 'undefined') return
4
- let head = document.head || document.getElementsByTagName('head')[0]
5
- let style = document.createElement('style')
6
- style.type = 'text/css'
7
- head.appendChild(style)
8
- ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
9
- }
1
+ "use client";
10
2
 
11
- import { Dialog } from '@base-ui/react';
12
- import * as React from 'react';
13
- import React__default, { useLayoutEffect, useEffect, useMemo } from 'react';
3
+ import { Dialog } from "@base-ui/react";
4
+ import * as React$1 from "react";
5
+ import React, { useEffect, useLayoutEffect, useMemo } from "react";
6
+ import { jsx } from "react/jsx-runtime";
14
7
 
15
- const DrawerContext = React__default.createContext({
16
- drawerRef: {
17
- current: null
18
- },
19
- overlayRef: {
20
- current: null
21
- },
22
- onPress: ()=>{},
23
- onRelease: ()=>{},
24
- onDrag: ()=>{},
25
- onNestedDrag: ()=>{},
26
- onNestedOpenChange: ()=>{},
27
- onNestedRelease: ()=>{},
28
- openProp: undefined,
29
- dismissible: false,
30
- isOpen: false,
31
- isDragging: false,
32
- keyboardIsOpen: {
33
- current: false
34
- },
35
- snapPointsOffset: null,
36
- snapPoints: null,
37
- handleOnly: false,
38
- modal: false,
39
- shouldFade: false,
40
- activeSnapPoint: null,
41
- onOpenChange: ()=>{},
42
- setActiveSnapPoint: ()=>{},
43
- closeDrawer: ()=>{},
44
- direction: 'bottom',
45
- shouldAnimate: {
46
- current: true
47
- },
48
- shouldScaleBackground: false,
49
- setBackgroundColorOnScale: true,
50
- noBodyStyles: false,
51
- container: null,
52
- autoFocus: false
8
+ import './index.css';
9
+ //#region src/context.ts
10
+ const DrawerContext = React.createContext({
11
+ drawerRef: { current: null },
12
+ overlayRef: { current: null },
13
+ onPress: () => {},
14
+ onRelease: () => {},
15
+ onDrag: () => {},
16
+ onNestedDrag: () => {},
17
+ onNestedOpenChange: () => {},
18
+ onNestedRelease: () => {},
19
+ openProp: void 0,
20
+ dismissible: false,
21
+ isOpen: false,
22
+ isDragging: false,
23
+ keyboardIsOpen: { current: false },
24
+ snapPointsOffset: null,
25
+ snapPoints: null,
26
+ handleOnly: false,
27
+ modal: false,
28
+ shouldFade: false,
29
+ activeSnapPoint: null,
30
+ onOpenChange: () => {},
31
+ setActiveSnapPoint: () => {},
32
+ closeDrawer: () => {},
33
+ direction: "bottom",
34
+ shouldAnimate: { current: true },
35
+ shouldScaleBackground: false,
36
+ setBackgroundColorOnScale: true,
37
+ noBodyStyles: false,
38
+ container: null,
39
+ autoFocus: false
53
40
  });
54
- const useDrawerContext = ()=>{
55
- const context = React__default.useContext(DrawerContext);
56
- if (!context) {
57
- throw new Error('useDrawerContext must be used within a Drawer.Root');
58
- }
59
- return context;
41
+ const useDrawerContext = () => {
42
+ const context = React.useContext(DrawerContext);
43
+ if (!context) throw new Error("useDrawerContext must be used within a Drawer.Root");
44
+ return context;
60
45
  };
61
46
 
62
- __insertCSS("[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-open]{animation-name:fadeIn}[data-vaul-overlay][data-closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not([data-closed]){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}");
63
-
47
+ //#endregion
48
+ //#region src/browser.ts
64
49
  function isMobileFirefox() {
65
- const userAgent = navigator.userAgent;
66
- return typeof window !== 'undefined' && (/Firefox/.test(userAgent) && /Mobile/.test(userAgent) || // Android Firefox
67
- /FxiOS/.test(userAgent) // iOS Firefox
68
- );
50
+ const userAgent = navigator.userAgent;
51
+ return typeof window !== "undefined" && (/Firefox/.test(userAgent) && /Mobile/.test(userAgent) || /FxiOS/.test(userAgent));
69
52
  }
70
53
  function isMac() {
71
- return testPlatform(/^Mac/);
54
+ return testPlatform(/^Mac/);
72
55
  }
73
56
  function isIPhone() {
74
- return testPlatform(/^iPhone/);
57
+ return testPlatform(/^iPhone/);
75
58
  }
76
59
  function isSafari() {
77
- return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
60
+ return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
78
61
  }
79
62
  function isIPad() {
80
- return testPlatform(/^iPad/) || // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
81
- isMac() && navigator.maxTouchPoints > 1;
63
+ return testPlatform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
82
64
  }
83
65
  function isIOS() {
84
- return isIPhone() || isIPad();
66
+ return isIPhone() || isIPad();
85
67
  }
86
68
  function testPlatform(re) {
87
- return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator.platform) : undefined;
69
+ return typeof window !== "undefined" && window.navigator != null ? re.test(window.navigator.platform) : void 0;
88
70
  }
89
71
 
90
- // This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts
72
+ //#endregion
73
+ //#region src/use-prevent-scroll.ts
91
74
  const KEYBOARD_BUFFER = 24;
92
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
75
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
93
76
  function chain$1(...callbacks) {
94
- return (...args)=>{
95
- for (let callback of callbacks){
96
- if (typeof callback === 'function') {
97
- callback(...args);
98
- }
99
- }
100
- };
77
+ return (...args) => {
78
+ for (const callback of callbacks) if (typeof callback === "function") callback(...args);
79
+ };
101
80
  }
102
- // @ts-ignore
103
- const visualViewport = typeof document !== 'undefined' && window.visualViewport;
81
+ const visualViewport = typeof document !== "undefined" && window.visualViewport;
104
82
  function isScrollable(node) {
105
- let style = window.getComputedStyle(node);
106
- return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
83
+ const style = window.getComputedStyle(node);
84
+ return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
107
85
  }
108
86
  function getScrollParent(node) {
109
- if (isScrollable(node)) {
110
- node = node.parentElement;
111
- }
112
- while(node && !isScrollable(node)){
113
- node = node.parentElement;
114
- }
115
- return node || document.scrollingElement || document.documentElement;
87
+ if (isScrollable(node)) node = node.parentElement;
88
+ while (node && !isScrollable(node)) node = node.parentElement;
89
+ return node || document.scrollingElement || document.documentElement;
116
90
  }
117
- // HTML input types that do not cause the software keyboard to appear.
118
91
  const nonTextInputTypes = new Set([
119
- 'checkbox',
120
- 'radio',
121
- 'range',
122
- 'color',
123
- 'file',
124
- 'image',
125
- 'button',
126
- 'submit',
127
- 'reset'
92
+ "checkbox",
93
+ "radio",
94
+ "range",
95
+ "color",
96
+ "file",
97
+ "image",
98
+ "button",
99
+ "submit",
100
+ "reset"
128
101
  ]);
129
- // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
130
102
  let preventScrollCount = 0;
131
103
  let restore;
132
104
  /**
133
- * Prevents scrolling on the document body on mount, and
134
- * restores it on unmount. Also ensures that content does not
135
- * shift due to the scrollbars disappearing.
136
- */ function usePreventScroll(options = {}) {
137
- let { isDisabled } = options;
138
- useIsomorphicLayoutEffect(()=>{
139
- if (isDisabled) {
140
- return;
141
- }
142
- preventScrollCount++;
143
- if (preventScrollCount === 1) {
144
- if (isIOS()) {
145
- restore = preventScrollMobileSafari();
146
- }
147
- }
148
- return ()=>{
149
- preventScrollCount--;
150
- if (preventScrollCount === 0) {
151
- restore == null ? void 0 : restore();
152
- }
153
- };
154
- }, [
155
- isDisabled
156
- ]);
105
+ * Prevents scrolling on the document body on mount, and
106
+ * restores it on unmount. Also ensures that content does not
107
+ * shift due to the scrollbars disappearing.
108
+ */
109
+ function usePreventScroll(options = {}) {
110
+ const { isDisabled } = options;
111
+ useIsomorphicLayoutEffect(() => {
112
+ if (isDisabled) return;
113
+ preventScrollCount++;
114
+ if (preventScrollCount === 1) {
115
+ if (isIOS()) restore = preventScrollMobileSafari();
116
+ }
117
+ return () => {
118
+ preventScrollCount--;
119
+ if (preventScrollCount === 0) restore === null || restore === void 0 || restore();
120
+ };
121
+ }, [isDisabled]);
157
122
  }
158
- // Mobile Safari is a whole different beast. Even with overflow: hidden,
159
- // it still scrolls the page in many situations:
160
- //
161
- // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
162
- // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
163
- // it, so it becomes scrollable.
164
- // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
165
- // This may cause even fixed position elements to scroll off the screen.
166
- // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
167
- // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
168
- //
169
- // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
170
- //
171
- // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
172
- // on the window.
173
- // 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the
174
- // top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.
175
- // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
176
- // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
177
- // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
178
- // into view ourselves, without scrolling the whole page.
179
- // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
180
- // same visually, but makes the actual scroll position always zero. This is required to make all of the
181
- // above work or Safari will still try to scroll the page when focusing an input.
182
- // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
183
- // to navigate to an input with the next/previous buttons that's outside a modal.
184
123
  function preventScrollMobileSafari() {
185
- let scrollable;
186
- let lastY = 0;
187
- let onTouchStart = (e)=>{
188
- // Store the nearest scrollable parent element from the element that the user touched.
189
- scrollable = getScrollParent(e.target);
190
- if (scrollable === document.documentElement && scrollable === document.body) {
191
- return;
192
- }
193
- lastY = e.changedTouches[0].pageY;
194
- };
195
- let onTouchMove = (e)=>{
196
- // Prevent scrolling the window.
197
- if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
198
- e.preventDefault();
199
- return;
200
- }
201
- // Prevent scrolling up when at the top and scrolling down when at the bottom
202
- // of a nested scrollable area, otherwise mobile Safari will start scrolling
203
- // the window instead. Unfortunately, this disables bounce scrolling when at
204
- // the top but it's the best we can do.
205
- let y = e.changedTouches[0].pageY;
206
- let scrollTop = scrollable.scrollTop;
207
- let bottom = scrollable.scrollHeight - scrollable.clientHeight;
208
- if (bottom === 0) {
209
- return;
210
- }
211
- if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
212
- e.preventDefault();
213
- }
214
- lastY = y;
215
- };
216
- let onTouchEnd = (e)=>{
217
- let target = e.target;
218
- // Apply this change if we're not already focused on the target element
219
- if (isInput(target) && target !== document.activeElement) {
220
- e.preventDefault();
221
- // Apply a transform to trick Safari into thinking the input is at the top of the page
222
- // so it doesn't try to scroll it into view. When tapping on an input, this needs to
223
- // be done before the "focus" event, so we have to focus the element ourselves.
224
- target.style.transform = 'translateY(-2000px)';
225
- target.focus();
226
- requestAnimationFrame(()=>{
227
- target.style.transform = '';
228
- });
229
- }
230
- };
231
- let onFocus = (e)=>{
232
- let target = e.target;
233
- if (isInput(target)) {
234
- // Transform also needs to be applied in the focus event in cases where focus moves
235
- // other than tapping on an input directly, e.g. the next/previous buttons in the
236
- // software keyboard. In these cases, it seems applying the transform in the focus event
237
- // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
238
- target.style.transform = 'translateY(-2000px)';
239
- requestAnimationFrame(()=>{
240
- target.style.transform = '';
241
- // This will have prevented the browser from scrolling the focused element into view,
242
- // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
243
- if (visualViewport) {
244
- if (visualViewport.height < window.innerHeight) {
245
- // If the keyboard is already visible, do this after one additional frame
246
- // to wait for the transform to be removed.
247
- requestAnimationFrame(()=>{
248
- scrollIntoView(target);
249
- });
250
- } else {
251
- // Otherwise, wait for the visual viewport to resize before scrolling so we can
252
- // measure the correct position to scroll to.
253
- visualViewport.addEventListener('resize', ()=>scrollIntoView(target), {
254
- once: true
255
- });
256
- }
257
- }
258
- });
259
- }
260
- };
261
- let onWindowScroll = ()=>{
262
- // Last resort. If the window scrolled, scroll it back to the top.
263
- // It should always be at the top because the body will have a negative margin (see below).
264
- window.scrollTo(0, 0);
265
- };
266
- // Record the original scroll position so we can restore it.
267
- // Then apply a negative margin to the body to offset it by the scroll position. This will
268
- // enable us to scroll the window to the top, which is required for the rest of this to work.
269
- let scrollX = window.pageXOffset;
270
- let scrollY = window.pageYOffset;
271
- let restoreStyles = chain$1(setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`));
272
- // Scroll to the top. The negative margin on the body will make this appear the same.
273
- window.scrollTo(0, 0);
274
- let removeEvents = chain$1(addEvent(document, 'touchstart', onTouchStart, {
275
- passive: false,
276
- capture: true
277
- }), addEvent(document, 'touchmove', onTouchMove, {
278
- passive: false,
279
- capture: true
280
- }), addEvent(document, 'touchend', onTouchEnd, {
281
- passive: false,
282
- capture: true
283
- }), addEvent(document, 'focus', onFocus, true), addEvent(window, 'scroll', onWindowScroll));
284
- return ()=>{
285
- // Restore styles and scroll the page back to where it was.
286
- restoreStyles();
287
- removeEvents();
288
- window.scrollTo(scrollX, scrollY);
289
- };
124
+ let scrollable;
125
+ let lastY = 0;
126
+ const onTouchStart = (e) => {
127
+ scrollable = getScrollParent(e.target);
128
+ if (scrollable === document.documentElement && scrollable === document.body) return;
129
+ lastY = e.changedTouches[0].pageY;
130
+ };
131
+ const onTouchMove = (e) => {
132
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
133
+ e.preventDefault();
134
+ return;
135
+ }
136
+ const y = e.changedTouches[0].pageY;
137
+ const scrollTop = scrollable.scrollTop;
138
+ const bottom = scrollable.scrollHeight - scrollable.clientHeight;
139
+ if (bottom === 0) return;
140
+ if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) e.preventDefault();
141
+ lastY = y;
142
+ };
143
+ const onTouchEnd = (e) => {
144
+ const target = e.target;
145
+ if (isInput(target) && target !== document.activeElement) {
146
+ e.preventDefault();
147
+ target.style.transform = "translateY(-2000px)";
148
+ target.focus();
149
+ requestAnimationFrame(() => {
150
+ target.style.transform = "";
151
+ });
152
+ }
153
+ };
154
+ const onFocus = (e) => {
155
+ const target = e.target;
156
+ if (isInput(target)) {
157
+ target.style.transform = "translateY(-2000px)";
158
+ requestAnimationFrame(() => {
159
+ target.style.transform = "";
160
+ if (visualViewport) if (visualViewport.height < window.innerHeight) requestAnimationFrame(() => {
161
+ scrollIntoView(target);
162
+ });
163
+ else visualViewport.addEventListener("resize", () => scrollIntoView(target), { once: true });
164
+ });
165
+ }
166
+ };
167
+ const onWindowScroll = () => {
168
+ window.scrollTo(0, 0);
169
+ };
170
+ const scrollX = window.pageXOffset;
171
+ const scrollY = window.pageYOffset;
172
+ const restoreStyles = chain$1(setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`));
173
+ window.scrollTo(0, 0);
174
+ const removeEvents = chain$1(addEvent(document, "touchstart", onTouchStart, {
175
+ passive: false,
176
+ capture: true
177
+ }), addEvent(document, "touchmove", onTouchMove, {
178
+ passive: false,
179
+ capture: true
180
+ }), addEvent(document, "touchend", onTouchEnd, {
181
+ passive: false,
182
+ capture: true
183
+ }), addEvent(document, "focus", onFocus, true), addEvent(window, "scroll", onWindowScroll));
184
+ return () => {
185
+ restoreStyles();
186
+ removeEvents();
187
+ window.scrollTo(scrollX, scrollY);
188
+ };
290
189
  }
291
- // Sets a CSS property on an element, and returns a function to revert it to the previous value.
292
190
  function setStyle(element, style, value) {
293
- // https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310
294
- // @ts-ignore
295
- let cur = element.style[style];
296
- // @ts-ignore
297
- element.style[style] = value;
298
- return ()=>{
299
- // @ts-ignore
300
- element.style[style] = cur;
301
- };
191
+ const cur = element.style[style];
192
+ element.style[style] = value;
193
+ return () => {
194
+ element.style[style] = cur;
195
+ };
302
196
  }
303
- // Adds an event listener to an element, and returns a function to remove it.
304
197
  function addEvent(target, event, handler, options) {
305
- // @ts-ignore
306
- target.addEventListener(event, handler, options);
307
- return ()=>{
308
- // @ts-ignore
309
- target.removeEventListener(event, handler, options);
310
- };
198
+ target.addEventListener(event, handler, options);
199
+ return () => {
200
+ target.removeEventListener(event, handler, options);
201
+ };
311
202
  }
312
203
  function scrollIntoView(target) {
313
- let root = document.scrollingElement || document.documentElement;
314
- while(target && target !== root){
315
- // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
316
- let scrollable = getScrollParent(target);
317
- if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
318
- let scrollableTop = scrollable.getBoundingClientRect().top;
319
- let targetTop = target.getBoundingClientRect().top;
320
- let targetBottom = target.getBoundingClientRect().bottom;
321
- // Buffer is needed for some edge cases
322
- const keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;
323
- if (targetBottom > keyboardHeight) {
324
- scrollable.scrollTop += targetTop - scrollableTop;
325
- }
326
- }
327
- // @ts-ignore
328
- target = scrollable.parentElement;
329
- }
204
+ const root = document.scrollingElement || document.documentElement;
205
+ while (target && target !== root) {
206
+ const scrollable = getScrollParent(target);
207
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
208
+ const scrollableTop = scrollable.getBoundingClientRect().top;
209
+ const targetTop = target.getBoundingClientRect().top;
210
+ if (target.getBoundingClientRect().bottom > scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER) scrollable.scrollTop += targetTop - scrollableTop;
211
+ }
212
+ target = scrollable.parentElement;
213
+ }
330
214
  }
331
215
  function isInput(target) {
332
- return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
216
+ return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
333
217
  }
334
218
 
335
- // This code comes from https://github.com/radix-ui/primitives/tree/main/packages/react/compose-refs
219
+ //#endregion
220
+ //#region src/use-composed-refs.ts
336
221
  /**
337
- * Set a given ref to a given value
338
- * This utility takes care of different types of refs: callback refs and RefObject(s)
339
- */ function setRef(ref, value) {
340
- if (typeof ref === 'function') {
341
- ref(value);
342
- } else if (ref !== null && ref !== undefined) {
343
- ref.current = value;
344
- }
222
+ * Set a given ref to a given value
223
+ * This utility takes care of different types of refs: callback refs and RefObject(s)
224
+ */
225
+ function setRef(ref, value) {
226
+ if (typeof ref === "function") ref(value);
227
+ else if (ref !== null && ref !== void 0) ref.current = value;
345
228
  }
346
229
  /**
347
- * A utility to compose multiple refs together
348
- * Accepts callback refs and RefObject(s)
349
- */ function composeRefs(...refs) {
350
- return (node)=>refs.forEach((ref)=>setRef(ref, node));
230
+ * A utility to compose multiple refs together
231
+ * Accepts callback refs and RefObject(s)
232
+ */
233
+ function composeRefs(...refs) {
234
+ return (node) => refs.forEach((ref) => setRef(ref, node));
351
235
  }
352
236
  /**
353
- * A custom hook that composes multiple refs
354
- * Accepts callback refs and RefObject(s)
355
- */ function useComposedRefs(...refs) {
356
- // eslint-disable-next-line react-hooks/exhaustive-deps
357
- return React.useCallback(composeRefs(...refs), refs);
237
+ * A custom hook that composes multiple refs
238
+ * Accepts callback refs and RefObject(s)
239
+ */
240
+ function useComposedRefs(...refs) {
241
+ return React$1.useCallback(composeRefs(...refs), refs);
358
242
  }
359
243
 
360
- const cache = new WeakMap();
244
+ //#endregion
245
+ //#region src/helpers.ts
246
+ const cache = /* @__PURE__ */ new WeakMap();
361
247
  function set(el, styles, ignoreCache = false) {
362
- if (!el || !(el instanceof HTMLElement)) return;
363
- let originalStyles = {};
364
- Object.entries(styles).forEach(([key, value])=>{
365
- if (key.startsWith('--')) {
366
- el.style.setProperty(key, value);
367
- return;
368
- }
369
- originalStyles[key] = el.style[key];
370
- el.style[key] = value;
371
- });
372
- if (ignoreCache) return;
373
- cache.set(el, originalStyles);
248
+ if (!el || !(el instanceof HTMLElement)) return;
249
+ const originalStyles = {};
250
+ Object.entries(styles).forEach(([key, value]) => {
251
+ if (key.startsWith("--")) {
252
+ el.style.setProperty(key, value);
253
+ return;
254
+ }
255
+ originalStyles[key] = el.style[key];
256
+ el.style[key] = value;
257
+ });
258
+ if (ignoreCache) return;
259
+ cache.set(el, originalStyles);
374
260
  }
375
261
  function reset(el, prop) {
376
- if (!el || !(el instanceof HTMLElement)) return;
377
- let originalStyles = cache.get(el);
378
- if (!originalStyles) {
379
- return;
380
- }
381
- {
382
- el.style[prop] = originalStyles[prop];
383
- }
262
+ if (!el || !(el instanceof HTMLElement)) return;
263
+ const originalStyles = cache.get(el);
264
+ if (!originalStyles) return;
265
+ if (prop) el.style[prop] = originalStyles[prop];
266
+ else Object.entries(originalStyles).forEach(([key, value]) => {
267
+ el.style[key] = value;
268
+ });
384
269
  }
385
- const isVertical = (direction)=>{
386
- switch(direction){
387
- case 'top':
388
- case 'bottom':
389
- return true;
390
- case 'left':
391
- case 'right':
392
- return false;
393
- default:
394
- return direction;
395
- }
270
+ const isVertical = (direction) => {
271
+ switch (direction) {
272
+ case "top":
273
+ case "bottom": return true;
274
+ case "left":
275
+ case "right": return false;
276
+ default: return direction;
277
+ }
396
278
  };
397
279
  function getTranslate(element, direction) {
398
- if (!element) {
399
- return null;
400
- }
401
- const style = window.getComputedStyle(element);
402
- const transform = // @ts-ignore
403
- style.transform || style.webkitTransform || style.mozTransform;
404
- let mat = transform.match(/^matrix3d\((.+)\)$/);
405
- if (mat) {
406
- // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d
407
- return parseFloat(mat[1].split(', ')[isVertical(direction) ? 13 : 12]);
408
- }
409
- // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix
410
- mat = transform.match(/^matrix\((.+)\)$/);
411
- return mat ? parseFloat(mat[1].split(', ')[isVertical(direction) ? 5 : 4]) : null;
280
+ if (!element) return null;
281
+ const style = window.getComputedStyle(element);
282
+ const transform = style.transform || style.webkitTransform || style.mozTransform;
283
+ let mat = transform.match(/^matrix3d\((.+)\)$/);
284
+ if (mat) return parseFloat(mat[1].split(", ")[isVertical(direction) ? 13 : 12]);
285
+ mat = transform.match(/^matrix\((.+)\)$/);
286
+ return mat ? parseFloat(mat[1].split(", ")[isVertical(direction) ? 5 : 4]) : null;
412
287
  }
413
288
  function dampenValue(v) {
414
- return 8 * (Math.log(v + 1) - 2);
289
+ return 8 * (Math.log(v + 1) - 2);
415
290
  }
416
291
  function assignStyle(element, style) {
417
- if (!element) return ()=>{};
418
- const prevStyle = element.style.cssText;
419
- Object.assign(element.style, style);
420
- return ()=>{
421
- element.style.cssText = prevStyle;
422
- };
292
+ if (!element) return () => {};
293
+ const prevStyle = element.style.cssText;
294
+ Object.assign(element.style, style);
295
+ return () => {
296
+ element.style.cssText = prevStyle;
297
+ };
423
298
  }
424
299
  /**
425
- * Receives functions as arguments and returns a new function that calls all.
426
- */ function chain(...fns) {
427
- return (...args)=>{
428
- for (const fn of fns){
429
- if (typeof fn === 'function') {
430
- // @ts-ignore
431
- fn(...args);
432
- }
433
- }
434
- };
300
+ * Receives functions as arguments and returns a new function that calls all.
301
+ */
302
+ function chain(...fns) {
303
+ return (...args) => {
304
+ for (const fn of fns) if (typeof fn === "function") fn(...args);
305
+ };
435
306
  }
436
307
 
308
+ //#endregion
309
+ //#region src/constants.ts
437
310
  const TRANSITIONS = {
438
- DURATION: 0.5,
439
- EASE: [
440
- 0.32,
441
- 0.72,
442
- 0,
443
- 1
444
- ]
311
+ DURATION: .5,
312
+ EASE: [
313
+ .32,
314
+ .72,
315
+ 0,
316
+ 1
317
+ ]
445
318
  };
446
- const VELOCITY_THRESHOLD = 0.4;
447
- const CLOSE_THRESHOLD = 0.25;
319
+ const VELOCITY_THRESHOLD = .4;
320
+ const CLOSE_THRESHOLD = .25;
448
321
  const SCROLL_LOCK_TIMEOUT = 100;
449
322
  const BORDER_RADIUS = 8;
450
323
  const NESTED_DISPLACEMENT = 16;
451
324
  const WINDOW_TOP_OFFSET = 26;
452
- const DRAG_CLASS = 'vaul-dragging';
325
+ const DRAG_CLASS = "vaul-dragging";
453
326
 
454
- // This code comes from https://github.com/radix-ui/primitives/blob/main/packages/react/use-controllable-state/src/useControllableState.tsx
327
+ //#endregion
328
+ //#region src/use-controllable-state.ts
455
329
  function useCallbackRef(callback) {
456
- const callbackRef = React__default.useRef(callback);
457
- React__default.useEffect(()=>{
458
- callbackRef.current = callback;
459
- });
460
- // https://github.com/facebook/react/issues/19240
461
- return React__default.useMemo(()=>(...args)=>callbackRef.current == null ? void 0 : callbackRef.current.call(callbackRef, ...args), []);
330
+ const callbackRef = React.useRef(callback);
331
+ React.useEffect(() => {
332
+ callbackRef.current = callback;
333
+ });
334
+ return React.useMemo(() => ((...args) => {
335
+ var _callbackRef$current;
336
+ return (_callbackRef$current = callbackRef.current) === null || _callbackRef$current === void 0 ? void 0 : _callbackRef$current.call(callbackRef, ...args);
337
+ }), []);
462
338
  }
463
339
  function useUncontrolledState({ defaultProp, onChange }) {
464
- const uncontrolledState = React__default.useState(defaultProp);
465
- const [value] = uncontrolledState;
466
- const prevValueRef = React__default.useRef(value);
467
- const handleChange = useCallbackRef(onChange);
468
- React__default.useEffect(()=>{
469
- if (prevValueRef.current !== value) {
470
- handleChange(value);
471
- prevValueRef.current = value;
472
- }
473
- }, [
474
- value,
475
- prevValueRef,
476
- handleChange
477
- ]);
478
- return uncontrolledState;
340
+ const uncontrolledState = React.useState(defaultProp);
341
+ const [value] = uncontrolledState;
342
+ const prevValueRef = React.useRef(value);
343
+ const handleChange = useCallbackRef(onChange);
344
+ React.useEffect(() => {
345
+ if (prevValueRef.current !== value) {
346
+ handleChange(value);
347
+ prevValueRef.current = value;
348
+ }
349
+ }, [
350
+ value,
351
+ prevValueRef,
352
+ handleChange
353
+ ]);
354
+ return uncontrolledState;
479
355
  }
480
- function useControllableState({ prop, defaultProp, onChange = ()=>{} }) {
481
- const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({
482
- defaultProp,
483
- onChange
484
- });
485
- const isControlled = prop !== undefined;
486
- const value = isControlled ? prop : uncontrolledProp;
487
- const handleChange = useCallbackRef(onChange);
488
- const setValue = React__default.useCallback((nextValue)=>{
489
- if (isControlled) {
490
- const setter = nextValue;
491
- const value = typeof nextValue === 'function' ? setter(prop) : nextValue;
492
- if (value !== prop) handleChange(value);
493
- } else {
494
- setUncontrolledProp(nextValue);
495
- }
496
- }, [
497
- isControlled,
498
- prop,
499
- setUncontrolledProp,
500
- handleChange
501
- ]);
502
- return [
503
- value,
504
- setValue
505
- ];
356
+ function useControllableState({ prop, defaultProp, onChange = () => {} }) {
357
+ const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({
358
+ defaultProp,
359
+ onChange
360
+ });
361
+ const isControlled = prop !== void 0;
362
+ const value = isControlled ? prop : uncontrolledProp;
363
+ const handleChange = useCallbackRef(onChange);
364
+ return [value, React.useCallback((nextValue) => {
365
+ if (isControlled) {
366
+ const value$1 = typeof nextValue === "function" ? nextValue(prop) : nextValue;
367
+ if (value$1 !== prop) handleChange(value$1);
368
+ } else setUncontrolledProp(nextValue);
369
+ }, [
370
+ isControlled,
371
+ prop,
372
+ setUncontrolledProp,
373
+ handleChange
374
+ ])];
506
375
  }
507
376
 
508
- function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = 'bottom', container, snapToSequentialPoint }) {
509
- const [activeSnapPoint, setActiveSnapPoint] = useControllableState({
510
- prop: activeSnapPointProp,
511
- defaultProp: snapPoints == null ? void 0 : snapPoints[0],
512
- onChange: setActiveSnapPointProp
513
- });
514
- const [windowDimensions, setWindowDimensions] = React__default.useState(typeof window !== 'undefined' ? {
515
- innerWidth: window.innerWidth,
516
- innerHeight: window.innerHeight
517
- } : undefined);
518
- React__default.useEffect(()=>{
519
- function onResize() {
520
- setWindowDimensions({
521
- innerWidth: window.innerWidth,
522
- innerHeight: window.innerHeight
523
- });
524
- }
525
- window.addEventListener('resize', onResize);
526
- return ()=>window.removeEventListener('resize', onResize);
527
- }, []);
528
- const isLastSnapPoint = React__default.useMemo(()=>activeSnapPoint === (snapPoints == null ? void 0 : snapPoints[snapPoints.length - 1]) || null, [
529
- snapPoints,
530
- activeSnapPoint
531
- ]);
532
- const activeSnapPointIndex = React__default.useMemo(()=>{
533
- var _snapPoints_findIndex;
534
- return (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : null;
535
- }, [
536
- snapPoints,
537
- activeSnapPoint
538
- ]);
539
- const shouldFade = snapPoints && snapPoints.length > 0 && (fadeFromIndex || fadeFromIndex === 0) && !Number.isNaN(fadeFromIndex) && snapPoints[fadeFromIndex] === activeSnapPoint || !snapPoints;
540
- const snapPointsOffset = React__default.useMemo(()=>{
541
- const containerSize = container ? {
542
- width: container.getBoundingClientRect().width,
543
- height: container.getBoundingClientRect().height
544
- } : typeof window !== 'undefined' ? {
545
- width: window.innerWidth,
546
- height: window.innerHeight
547
- } : {
548
- width: 0,
549
- height: 0
550
- };
551
- var _snapPoints_map;
552
- return (_snapPoints_map = snapPoints == null ? void 0 : snapPoints.map((snapPoint)=>{
553
- const isPx = typeof snapPoint === 'string';
554
- let snapPointAsNumber = 0;
555
- if (isPx) {
556
- snapPointAsNumber = parseInt(snapPoint, 10);
557
- }
558
- if (isVertical(direction)) {
559
- const height = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.height : 0;
560
- if (windowDimensions) {
561
- return direction === 'bottom' ? containerSize.height - height : -containerSize.height + height;
562
- }
563
- return height;
564
- }
565
- const width = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.width : 0;
566
- if (windowDimensions) {
567
- return direction === 'right' ? containerSize.width - width : -containerSize.width + width;
568
- }
569
- return width;
570
- })) != null ? _snapPoints_map : [];
571
- }, [
572
- snapPoints,
573
- windowDimensions,
574
- container
575
- ]);
576
- const activeSnapPointOffset = React__default.useMemo(()=>activeSnapPointIndex !== null ? snapPointsOffset == null ? void 0 : snapPointsOffset[activeSnapPointIndex] : null, [
577
- snapPointsOffset,
578
- activeSnapPointIndex
579
- ]);
580
- const snapToPoint = React__default.useCallback((dimension)=>{
581
- var _snapPointsOffset_findIndex;
582
- const newSnapPointIndex = (_snapPointsOffset_findIndex = snapPointsOffset == null ? void 0 : snapPointsOffset.findIndex((snapPointDim)=>snapPointDim === dimension)) != null ? _snapPointsOffset_findIndex : null;
583
- onSnapPointChange(newSnapPointIndex);
584
- set(drawerRef.current, {
585
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
586
- transform: isVertical(direction) ? `translate3d(0, ${dimension}px, 0)` : `translate3d(${dimension}px, 0, 0)`
587
- });
588
- if (snapPointsOffset && newSnapPointIndex !== snapPointsOffset.length - 1 && fadeFromIndex !== undefined && newSnapPointIndex !== fadeFromIndex && newSnapPointIndex < fadeFromIndex) {
589
- set(overlayRef.current, {
590
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
591
- opacity: '0'
592
- });
593
- } else {
594
- set(overlayRef.current, {
595
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
596
- opacity: '1'
597
- });
598
- }
599
- setActiveSnapPoint(snapPoints == null ? void 0 : snapPoints[Math.max(newSnapPointIndex, 0)]);
600
- }, [
601
- drawerRef.current,
602
- snapPoints,
603
- snapPointsOffset,
604
- fadeFromIndex,
605
- overlayRef,
606
- setActiveSnapPoint
607
- ]);
608
- React__default.useEffect(()=>{
609
- if (activeSnapPoint || activeSnapPointProp) {
610
- var _snapPoints_findIndex;
611
- const newIndex = (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : -1;
612
- if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === 'number') {
613
- snapToPoint(snapPointsOffset[newIndex]);
614
- }
615
- }
616
- }, [
617
- activeSnapPoint,
618
- activeSnapPointProp,
619
- snapPoints,
620
- snapPointsOffset,
621
- snapToPoint
622
- ]);
623
- function onRelease({ draggedDistance, closeDrawer, velocity, dismissible }) {
624
- if (fadeFromIndex === undefined) return;
625
- const currentPosition = direction === 'bottom' || direction === 'right' ? (activeSnapPointOffset != null ? activeSnapPointOffset : 0) - draggedDistance : (activeSnapPointOffset != null ? activeSnapPointOffset : 0) + draggedDistance;
626
- const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
627
- const isFirst = activeSnapPointIndex === 0;
628
- const hasDraggedUp = draggedDistance > 0;
629
- if (isOverlaySnapPoint) {
630
- set(overlayRef.current, {
631
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
632
- });
633
- }
634
- if (!snapToSequentialPoint && velocity > 2 && !hasDraggedUp) {
635
- if (dismissible) closeDrawer();
636
- else snapToPoint(snapPointsOffset[0]); // snap to initial point
637
- return;
638
- }
639
- if (!snapToSequentialPoint && velocity > 2 && hasDraggedUp && snapPointsOffset && snapPoints) {
640
- snapToPoint(snapPointsOffset[snapPoints.length - 1]);
641
- return;
642
- }
643
- // Find the closest snap point to the current position
644
- const closestSnapPoint = snapPointsOffset == null ? void 0 : snapPointsOffset.reduce((prev, curr)=>{
645
- if (typeof prev !== 'number' || typeof curr !== 'number') return prev;
646
- return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
647
- });
648
- const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
649
- if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedDistance) < dim * 0.4) {
650
- const dragDirection = hasDraggedUp ? 1 : -1; // 1 = up, -1 = down
651
- // Don't do anything if we swipe upwards while being on the last snap point
652
- if (dragDirection > 0 && isLastSnapPoint && snapPoints) {
653
- snapToPoint(snapPointsOffset[snapPoints.length - 1]);
654
- return;
655
- }
656
- if (isFirst && dragDirection < 0 && dismissible) {
657
- closeDrawer();
658
- }
659
- if (activeSnapPointIndex === null) return;
660
- snapToPoint(snapPointsOffset[activeSnapPointIndex + dragDirection]);
661
- return;
662
- }
663
- snapToPoint(closestSnapPoint);
664
- }
665
- function onDrag({ draggedDistance }) {
666
- if (activeSnapPointOffset === null) return;
667
- const newValue = direction === 'bottom' || direction === 'right' ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;
668
- // Don't do anything if we exceed the last(biggest) snap point
669
- if ((direction === 'bottom' || direction === 'right') && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {
670
- return;
671
- }
672
- if ((direction === 'top' || direction === 'left') && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {
673
- return;
674
- }
675
- set(drawerRef.current, {
676
- transform: isVertical(direction) ? `translate3d(0, ${newValue}px, 0)` : `translate3d(${newValue}px, 0, 0)`
677
- });
678
- }
679
- function getPercentageDragged(absDraggedDistance, isDraggingDown) {
680
- if (!snapPoints || typeof activeSnapPointIndex !== 'number' || !snapPointsOffset || fadeFromIndex === undefined) return null;
681
- // If this is true we are dragging to a snap point that is supposed to have an overlay
682
- const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
683
- const isOverlaySnapPointOrHigher = activeSnapPointIndex >= fadeFromIndex;
684
- if (isOverlaySnapPointOrHigher && isDraggingDown) {
685
- return 0;
686
- }
687
- // Don't animate, but still use this one if we are dragging away from the overlaySnapPoint
688
- if (isOverlaySnapPoint && !isDraggingDown) return 1;
689
- if (!shouldFade && !isOverlaySnapPoint) return null;
690
- // Either fadeFrom index or the one before
691
- const targetSnapPointIndex = isOverlaySnapPoint ? activeSnapPointIndex + 1 : activeSnapPointIndex - 1;
692
- // Get the distance from overlaySnapPoint to the one before or vice-versa to calculate the opacity percentage accordingly
693
- const snapPointDistance = isOverlaySnapPoint ? snapPointsOffset[targetSnapPointIndex] - snapPointsOffset[targetSnapPointIndex - 1] : snapPointsOffset[targetSnapPointIndex + 1] - snapPointsOffset[targetSnapPointIndex];
694
- const percentageDragged = absDraggedDistance / Math.abs(snapPointDistance);
695
- if (isOverlaySnapPoint) {
696
- return 1 - percentageDragged;
697
- } else {
698
- return percentageDragged;
699
- }
700
- }
701
- return {
702
- isLastSnapPoint,
703
- activeSnapPoint,
704
- shouldFade,
705
- getPercentageDragged,
706
- setActiveSnapPoint,
707
- activeSnapPointIndex,
708
- onRelease,
709
- onDrag,
710
- snapPointsOffset
711
- };
377
+ //#endregion
378
+ //#region src/use-snap-points.ts
379
+ function useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = "bottom", container, snapToSequentialPoint }) {
380
+ const [activeSnapPoint, setActiveSnapPoint] = useControllableState({
381
+ prop: activeSnapPointProp,
382
+ defaultProp: snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[0],
383
+ onChange: setActiveSnapPointProp
384
+ });
385
+ const [windowDimensions, setWindowDimensions] = React.useState(typeof window !== "undefined" ? {
386
+ innerWidth: window.innerWidth,
387
+ innerHeight: window.innerHeight
388
+ } : void 0);
389
+ React.useEffect(() => {
390
+ function onResize() {
391
+ setWindowDimensions({
392
+ innerWidth: window.innerWidth,
393
+ innerHeight: window.innerHeight
394
+ });
395
+ }
396
+ window.addEventListener("resize", onResize);
397
+ return () => window.removeEventListener("resize", onResize);
398
+ }, []);
399
+ const isLastSnapPoint = React.useMemo(() => activeSnapPoint === (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[snapPoints.length - 1]) || null, [snapPoints, activeSnapPoint]);
400
+ const activeSnapPointIndex = React.useMemo(() => (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints.findIndex((snapPoint) => snapPoint === activeSnapPoint)) ?? null, [snapPoints, activeSnapPoint]);
401
+ const shouldFade = snapPoints && snapPoints.length > 0 && (fadeFromIndex || fadeFromIndex === 0) && !Number.isNaN(fadeFromIndex) && snapPoints[fadeFromIndex] === activeSnapPoint || !snapPoints;
402
+ const snapPointsOffset = React.useMemo(() => {
403
+ const containerSize = container ? {
404
+ width: container.getBoundingClientRect().width,
405
+ height: container.getBoundingClientRect().height
406
+ } : typeof window !== "undefined" ? {
407
+ width: window.innerWidth,
408
+ height: window.innerHeight
409
+ } : {
410
+ width: 0,
411
+ height: 0
412
+ };
413
+ return (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints.map((snapPoint) => {
414
+ const isPx = typeof snapPoint === "string";
415
+ let snapPointAsNumber = 0;
416
+ if (isPx) snapPointAsNumber = parseInt(snapPoint, 10);
417
+ if (isVertical(direction)) {
418
+ const height = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.height : 0;
419
+ if (windowDimensions) return direction === "bottom" ? containerSize.height - height : -containerSize.height + height;
420
+ return height;
421
+ }
422
+ const width = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.width : 0;
423
+ if (windowDimensions) return direction === "right" ? containerSize.width - width : -containerSize.width + width;
424
+ return width;
425
+ })) ?? [];
426
+ }, [
427
+ snapPoints,
428
+ windowDimensions,
429
+ container
430
+ ]);
431
+ const activeSnapPointOffset = React.useMemo(() => activeSnapPointIndex !== null ? snapPointsOffset === null || snapPointsOffset === void 0 ? void 0 : snapPointsOffset[activeSnapPointIndex] : null, [snapPointsOffset, activeSnapPointIndex]);
432
+ const snapToPoint = React.useCallback((dimension) => {
433
+ const newSnapPointIndex = (snapPointsOffset === null || snapPointsOffset === void 0 ? void 0 : snapPointsOffset.findIndex((snapPointDim) => snapPointDim === dimension)) ?? null;
434
+ onSnapPointChange(newSnapPointIndex);
435
+ set(drawerRef.current, {
436
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
437
+ transform: isVertical(direction) ? `translate3d(0, ${dimension}px, 0)` : `translate3d(${dimension}px, 0, 0)`
438
+ });
439
+ if (snapPointsOffset && newSnapPointIndex !== snapPointsOffset.length - 1 && fadeFromIndex !== void 0 && newSnapPointIndex !== fadeFromIndex && newSnapPointIndex < fadeFromIndex) set(overlayRef.current, {
440
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
441
+ opacity: "0"
442
+ });
443
+ else set(overlayRef.current, {
444
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
445
+ opacity: "1"
446
+ });
447
+ setActiveSnapPoint(snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints[Math.max(newSnapPointIndex, 0)]);
448
+ }, [
449
+ drawerRef.current,
450
+ snapPoints,
451
+ snapPointsOffset,
452
+ fadeFromIndex,
453
+ overlayRef,
454
+ setActiveSnapPoint
455
+ ]);
456
+ React.useEffect(() => {
457
+ if (activeSnapPoint || activeSnapPointProp) {
458
+ const newIndex = (snapPoints === null || snapPoints === void 0 ? void 0 : snapPoints.findIndex((snapPoint) => snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint)) ?? -1;
459
+ if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === "number") snapToPoint(snapPointsOffset[newIndex]);
460
+ }
461
+ }, [
462
+ activeSnapPoint,
463
+ activeSnapPointProp,
464
+ snapPoints,
465
+ snapPointsOffset,
466
+ snapToPoint
467
+ ]);
468
+ function onRelease({ draggedDistance, closeDrawer, velocity, dismissible }) {
469
+ if (fadeFromIndex === void 0) return;
470
+ const currentPosition = direction === "bottom" || direction === "right" ? (activeSnapPointOffset ?? 0) - draggedDistance : (activeSnapPointOffset ?? 0) + draggedDistance;
471
+ const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
472
+ const isFirst = activeSnapPointIndex === 0;
473
+ const hasDraggedUp = draggedDistance > 0;
474
+ if (isOverlaySnapPoint) set(overlayRef.current, { transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})` });
475
+ if (!snapToSequentialPoint && velocity > 2 && !hasDraggedUp) {
476
+ if (dismissible) closeDrawer();
477
+ else snapToPoint(snapPointsOffset[0]);
478
+ return;
479
+ }
480
+ if (!snapToSequentialPoint && velocity > 2 && hasDraggedUp && snapPointsOffset && snapPoints) {
481
+ snapToPoint(snapPointsOffset[snapPoints.length - 1]);
482
+ return;
483
+ }
484
+ const closestSnapPoint = snapPointsOffset === null || snapPointsOffset === void 0 ? void 0 : snapPointsOffset.reduce((prev, curr) => {
485
+ if (typeof prev !== "number" || typeof curr !== "number") return prev;
486
+ return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;
487
+ });
488
+ const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
489
+ if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedDistance) < dim * .4) {
490
+ const dragDirection = hasDraggedUp ? 1 : -1;
491
+ if (dragDirection > 0 && isLastSnapPoint && snapPoints) {
492
+ snapToPoint(snapPointsOffset[snapPoints.length - 1]);
493
+ return;
494
+ }
495
+ if (isFirst && dragDirection < 0 && dismissible) closeDrawer();
496
+ if (activeSnapPointIndex === null) return;
497
+ snapToPoint(snapPointsOffset[activeSnapPointIndex + dragDirection]);
498
+ return;
499
+ }
500
+ snapToPoint(closestSnapPoint);
501
+ }
502
+ function onDrag({ draggedDistance }) {
503
+ if (activeSnapPointOffset === null) return;
504
+ const newValue = direction === "bottom" || direction === "right" ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;
505
+ if ((direction === "bottom" || direction === "right") && newValue < snapPointsOffset[snapPointsOffset.length - 1]) return;
506
+ if ((direction === "top" || direction === "left") && newValue > snapPointsOffset[snapPointsOffset.length - 1]) return;
507
+ set(drawerRef.current, { transform: isVertical(direction) ? `translate3d(0, ${newValue}px, 0)` : `translate3d(${newValue}px, 0, 0)` });
508
+ }
509
+ function getPercentageDragged(absDraggedDistance, isDraggingDown) {
510
+ if (!snapPoints || typeof activeSnapPointIndex !== "number" || !snapPointsOffset || fadeFromIndex === void 0) return null;
511
+ const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;
512
+ if (activeSnapPointIndex >= fadeFromIndex && isDraggingDown) return 0;
513
+ if (isOverlaySnapPoint && !isDraggingDown) return 1;
514
+ if (!shouldFade && !isOverlaySnapPoint) return null;
515
+ const targetSnapPointIndex = isOverlaySnapPoint ? activeSnapPointIndex + 1 : activeSnapPointIndex - 1;
516
+ const snapPointDistance = isOverlaySnapPoint ? snapPointsOffset[targetSnapPointIndex] - snapPointsOffset[targetSnapPointIndex - 1] : snapPointsOffset[targetSnapPointIndex + 1] - snapPointsOffset[targetSnapPointIndex];
517
+ const percentageDragged = absDraggedDistance / Math.abs(snapPointDistance);
518
+ if (isOverlaySnapPoint) return 1 - percentageDragged;
519
+ else return percentageDragged;
520
+ }
521
+ return {
522
+ isLastSnapPoint,
523
+ activeSnapPoint,
524
+ shouldFade,
525
+ getPercentageDragged,
526
+ setActiveSnapPoint,
527
+ activeSnapPointIndex,
528
+ onRelease,
529
+ onDrag,
530
+ snapPointsOffset
531
+ };
712
532
  }
713
533
 
714
- const noop = ()=>()=>{};
534
+ //#endregion
535
+ //#region src/use-scale-background.ts
536
+ const noop = () => () => {};
715
537
  function useScaleBackground() {
716
- const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();
717
- const timeoutIdRef = React__default.useRef(null);
718
- const initialBackgroundColor = useMemo(()=>document.body.style.backgroundColor, []);
719
- function getScale() {
720
- return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
721
- }
722
- React__default.useEffect(()=>{
723
- if (isOpen && shouldScaleBackground) {
724
- if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);
725
- const wrapper = document.querySelector('[data-vaul-drawer-wrapper]') || document.querySelector('[vaul-drawer-wrapper]');
726
- if (!wrapper) return;
727
- chain(setBackgroundColorOnScale && !noBodyStyles ? assignStyle(document.body, {
728
- background: 'black'
729
- }) : noop, assignStyle(wrapper, {
730
- transformOrigin: isVertical(direction) ? 'top' : 'left',
731
- transitionProperty: 'transform, border-radius',
732
- transitionDuration: `${TRANSITIONS.DURATION}s`,
733
- transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`
734
- }));
735
- const wrapperStylesCleanup = assignStyle(wrapper, {
736
- borderRadius: `${BORDER_RADIUS}px`,
737
- overflow: 'hidden',
738
- ...isVertical(direction) ? {
739
- transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`
740
- } : {
741
- transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`
742
- }
743
- });
744
- return ()=>{
745
- wrapperStylesCleanup();
746
- timeoutIdRef.current = window.setTimeout(()=>{
747
- if (initialBackgroundColor) {
748
- document.body.style.background = initialBackgroundColor;
749
- } else {
750
- document.body.style.removeProperty('background');
751
- }
752
- }, TRANSITIONS.DURATION * 1000);
753
- };
754
- }
755
- }, [
756
- isOpen,
757
- shouldScaleBackground,
758
- initialBackgroundColor
759
- ]);
538
+ const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();
539
+ const timeoutIdRef = React.useRef(null);
540
+ const initialBackgroundColor = useMemo(() => document.body.style.backgroundColor, []);
541
+ function getScale() {
542
+ return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
543
+ }
544
+ React.useEffect(() => {
545
+ if (isOpen && shouldScaleBackground) {
546
+ if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);
547
+ const wrapper = document.querySelector("[data-vaul-drawer-wrapper]") || document.querySelector("[vaul-drawer-wrapper]");
548
+ if (!wrapper) return;
549
+ chain(setBackgroundColorOnScale && !noBodyStyles ? assignStyle(document.body, { background: "black" }) : noop, assignStyle(wrapper, {
550
+ transformOrigin: isVertical(direction) ? "top" : "left",
551
+ transitionProperty: "transform, border-radius",
552
+ transitionDuration: `${TRANSITIONS.DURATION}s`,
553
+ transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(",")})`
554
+ }));
555
+ const wrapperStylesCleanup = assignStyle(wrapper, {
556
+ borderRadius: `${BORDER_RADIUS}px`,
557
+ overflow: "hidden",
558
+ ...isVertical(direction) ? { transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)` } : { transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)` }
559
+ });
560
+ return () => {
561
+ wrapperStylesCleanup();
562
+ timeoutIdRef.current = window.setTimeout(() => {
563
+ if (initialBackgroundColor) document.body.style.background = initialBackgroundColor;
564
+ else document.body.style.removeProperty("background");
565
+ }, TRANSITIONS.DURATION * 1e3);
566
+ };
567
+ }
568
+ }, [
569
+ isOpen,
570
+ shouldScaleBackground,
571
+ initialBackgroundColor
572
+ ]);
760
573
  }
761
574
 
575
+ //#endregion
576
+ //#region src/use-position-fixed.ts
762
577
  let previousBodyPosition = null;
763
578
  /**
764
- * This hook is necessary to prevent buggy behavior on iOS devices (need to test on Android).
765
- * I won't get into too much detail about what bugs it solves, but so far I've found that setting the body to `position: fixed` is the most reliable way to prevent those bugs.
766
- * Issues that this hook solves:
767
- * https://github.com/emilkowalski/vaul/issues/435
768
- * https://github.com/emilkowalski/vaul/issues/433
769
- * And more that I discovered, but were just not reported.
770
- */ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollRestoration, noBodyStyles }) {
771
- const [activeUrl, setActiveUrl] = React__default.useState(()=>typeof window !== 'undefined' ? window.location.href : '');
772
- const scrollPos = React__default.useRef(0);
773
- const setPositionFixed = React__default.useCallback(()=>{
774
- // All browsers on iOS will return true here.
775
- if (!isSafari()) return;
776
- // If previousBodyPosition is already set, don't set it again.
777
- if (previousBodyPosition === null && isOpen && !noBodyStyles) {
778
- previousBodyPosition = {
779
- position: document.body.style.position,
780
- top: document.body.style.top,
781
- left: document.body.style.left,
782
- height: document.body.style.height,
783
- right: 'unset'
784
- };
785
- // Update the dom inside an animation frame
786
- const { scrollX, innerHeight } = window;
787
- document.body.style.setProperty('position', 'fixed', 'important');
788
- Object.assign(document.body.style, {
789
- top: `${-scrollPos.current}px`,
790
- left: `${-scrollX}px`,
791
- right: '0px',
792
- height: 'auto'
793
- });
794
- window.setTimeout(()=>window.requestAnimationFrame(()=>{
795
- // Attempt to check if the bottom bar appeared due to the position change
796
- const bottomBarHeight = innerHeight - window.innerHeight;
797
- if (bottomBarHeight && scrollPos.current >= innerHeight) {
798
- // Move the content further up so that the bottom bar doesn't hide it
799
- document.body.style.top = `${-(scrollPos.current + bottomBarHeight)}px`;
800
- }
801
- }), 300);
802
- }
803
- }, [
804
- isOpen
805
- ]);
806
- const restorePositionSetting = React__default.useCallback(()=>{
807
- // All browsers on iOS will return true here.
808
- if (!isSafari()) return;
809
- if (previousBodyPosition !== null && !noBodyStyles) {
810
- // Convert the position from "px" to Int
811
- const y = -parseInt(document.body.style.top, 10);
812
- const x = -parseInt(document.body.style.left, 10);
813
- // Restore styles
814
- Object.assign(document.body.style, previousBodyPosition);
815
- window.requestAnimationFrame(()=>{
816
- if (preventScrollRestoration && activeUrl !== window.location.href) {
817
- setActiveUrl(window.location.href);
818
- return;
819
- }
820
- window.scrollTo(x, y);
821
- });
822
- previousBodyPosition = null;
823
- }
824
- }, [
825
- activeUrl
826
- ]);
827
- React__default.useEffect(()=>{
828
- function onScroll() {
829
- scrollPos.current = window.scrollY;
830
- }
831
- onScroll();
832
- window.addEventListener('scroll', onScroll);
833
- return ()=>{
834
- window.removeEventListener('scroll', onScroll);
835
- };
836
- }, []);
837
- React__default.useEffect(()=>{
838
- if (!modal) return;
839
- return ()=>{
840
- if (typeof document === 'undefined') return;
841
- // Another drawer is opened, safe to ignore the execution
842
- const hasDrawerOpened = !!document.querySelector('[data-vaul-drawer]');
843
- if (hasDrawerOpened) return;
844
- restorePositionSetting();
845
- };
846
- }, [
847
- modal,
848
- restorePositionSetting
849
- ]);
850
- React__default.useEffect(()=>{
851
- if (nested || !hasBeenOpened) return;
852
- // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happening
853
- if (isOpen) {
854
- // avoid for standalone mode (PWA)
855
- const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
856
- !isStandalone && setPositionFixed();
857
- if (!modal) {
858
- window.setTimeout(()=>{
859
- restorePositionSetting();
860
- }, 500);
861
- }
862
- } else {
863
- restorePositionSetting();
864
- }
865
- }, [
866
- isOpen,
867
- hasBeenOpened,
868
- activeUrl,
869
- modal,
870
- nested,
871
- setPositionFixed,
872
- restorePositionSetting
873
- ]);
874
- return {
875
- restorePositionSetting
876
- };
579
+ * This hook is necessary to prevent buggy behavior on iOS devices (need to test on Android).
580
+ * I won't get into too much detail about what bugs it solves, but so far I've found that setting the body to `position: fixed` is the most reliable way to prevent those bugs.
581
+ * Issues that this hook solves:
582
+ * https://github.com/emilkowalski/vaul/issues/435
583
+ * https://github.com/emilkowalski/vaul/issues/433
584
+ * And more that I discovered, but were just not reported.
585
+ */
586
+ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollRestoration, noBodyStyles }) {
587
+ const [activeUrl, setActiveUrl] = React.useState(() => typeof window !== "undefined" ? window.location.href : "");
588
+ const scrollPos = React.useRef(0);
589
+ const setPositionFixed = React.useCallback(() => {
590
+ if (!isSafari()) return;
591
+ if (previousBodyPosition === null && isOpen && !noBodyStyles) {
592
+ previousBodyPosition = {
593
+ position: document.body.style.position,
594
+ top: document.body.style.top,
595
+ left: document.body.style.left,
596
+ height: document.body.style.height,
597
+ right: "unset"
598
+ };
599
+ const { scrollX, innerHeight } = window;
600
+ document.body.style.setProperty("position", "fixed", "important");
601
+ Object.assign(document.body.style, {
602
+ top: `${-scrollPos.current}px`,
603
+ left: `${-scrollX}px`,
604
+ right: "0px",
605
+ height: "auto"
606
+ });
607
+ window.setTimeout(() => window.requestAnimationFrame(() => {
608
+ const bottomBarHeight = innerHeight - window.innerHeight;
609
+ if (bottomBarHeight && scrollPos.current >= innerHeight) document.body.style.top = `${-(scrollPos.current + bottomBarHeight)}px`;
610
+ }), 300);
611
+ }
612
+ }, [isOpen]);
613
+ const restorePositionSetting = React.useCallback(() => {
614
+ if (!isSafari()) return;
615
+ if (previousBodyPosition !== null && !noBodyStyles) {
616
+ const y = -parseInt(document.body.style.top, 10);
617
+ const x = -parseInt(document.body.style.left, 10);
618
+ Object.assign(document.body.style, previousBodyPosition);
619
+ window.requestAnimationFrame(() => {
620
+ if (preventScrollRestoration && activeUrl !== window.location.href) {
621
+ setActiveUrl(window.location.href);
622
+ return;
623
+ }
624
+ window.scrollTo(x, y);
625
+ });
626
+ previousBodyPosition = null;
627
+ }
628
+ }, [activeUrl]);
629
+ React.useEffect(() => {
630
+ function onScroll() {
631
+ scrollPos.current = window.scrollY;
632
+ }
633
+ onScroll();
634
+ window.addEventListener("scroll", onScroll);
635
+ return () => {
636
+ window.removeEventListener("scroll", onScroll);
637
+ };
638
+ }, []);
639
+ React.useEffect(() => {
640
+ if (!modal) return;
641
+ return () => {
642
+ if (typeof document === "undefined") return;
643
+ if (!!document.querySelector("[data-vaul-drawer]")) return;
644
+ restorePositionSetting();
645
+ };
646
+ }, [modal, restorePositionSetting]);
647
+ React.useEffect(() => {
648
+ if (nested || !hasBeenOpened) return;
649
+ if (isOpen) {
650
+ !window.matchMedia("(display-mode: standalone)").matches && setPositionFixed();
651
+ if (!modal) window.setTimeout(() => {
652
+ restorePositionSetting();
653
+ }, 500);
654
+ } else restorePositionSetting();
655
+ }, [
656
+ isOpen,
657
+ hasBeenOpened,
658
+ activeUrl,
659
+ modal,
660
+ nested,
661
+ setPositionFixed,
662
+ restorePositionSetting
663
+ ]);
664
+ return { restorePositionSetting };
877
665
  }
878
666
 
879
- 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 }) {
880
- var _drawerRef_current, _drawerRef_current1;
881
- const [isOpen = false, setIsOpen] = useControllableState({
882
- defaultProp: defaultOpen,
883
- prop: openProp,
884
- onChange: (o)=>{
885
- onOpenChange == null ? void 0 : onOpenChange(o);
886
- if (!o && !nested) {
887
- restorePositionSetting();
888
- }
889
- setTimeout(()=>{
890
- onAnimationEnd == null ? void 0 : onAnimationEnd(o);
891
- }, TRANSITIONS.DURATION * 1000);
892
- if (o && !modal) {
893
- if (typeof window !== 'undefined') {
894
- window.requestAnimationFrame(()=>{
895
- document.body.style.pointerEvents = 'auto';
896
- });
897
- }
898
- }
899
- if (!o) {
900
- // This will be removed when the exit animation ends (`500ms`)
901
- document.body.style.pointerEvents = 'auto';
902
- }
903
- }
904
- });
905
- const [hasBeenOpened, setHasBeenOpened] = React__default.useState(false);
906
- const [isDragging, setIsDragging] = React__default.useState(false);
907
- const [justReleased, setJustReleased] = React__default.useState(false);
908
- const overlayRef = React__default.useRef(null);
909
- const openTime = React__default.useRef(null);
910
- const dragStartTime = React__default.useRef(null);
911
- const dragEndTime = React__default.useRef(null);
912
- const lastTimeDragPrevented = React__default.useRef(null);
913
- const isAllowedToDrag = React__default.useRef(false);
914
- const nestedOpenChangeTimer = React__default.useRef(null);
915
- const pointerStart = React__default.useRef(0);
916
- const keyboardIsOpen = React__default.useRef(false);
917
- const shouldAnimate = React__default.useRef(!defaultOpen);
918
- const previousDiffFromInitial = React__default.useRef(0);
919
- const drawerRef = React__default.useRef(null);
920
- const drawerHeightRef = React__default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);
921
- const drawerWidthRef = React__default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);
922
- const initialDrawerHeight = React__default.useRef(0);
923
- const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{
924
- // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.
925
- if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();
926
- }, []);
927
- const { activeSnapPoint, activeSnapPointIndex, setActiveSnapPoint, onRelease: onReleaseSnapPoints, snapPointsOffset, onDrag: onDragSnapPoints, shouldFade, getPercentageDragged: getSnapPointsPercentageDragged } = useSnapPoints({
928
- snapPoints,
929
- activeSnapPointProp,
930
- setActiveSnapPointProp,
931
- drawerRef,
932
- fadeFromIndex,
933
- overlayRef,
934
- onSnapPointChange,
935
- direction,
936
- container,
937
- snapToSequentialPoint
938
- });
939
- usePreventScroll({
940
- isDisabled: !isOpen || isDragging || !modal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll
941
- });
942
- const { restorePositionSetting } = usePositionFixed({
943
- isOpen,
944
- modal,
945
- nested: nested != null ? nested : false,
946
- hasBeenOpened,
947
- preventScrollRestoration,
948
- noBodyStyles
949
- });
950
- function getScale() {
951
- return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
952
- }
953
- function onPress(event) {
954
- var _drawerRef_current, _drawerRef_current1;
955
- if (!dismissible && !snapPoints) return;
956
- if (drawerRef.current && !drawerRef.current.contains(event.target)) return;
957
- drawerHeightRef.current = ((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0;
958
- drawerWidthRef.current = ((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0;
959
- setIsDragging(true);
960
- dragStartTime.current = new Date();
961
- // iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging
962
- if (isIOS()) {
963
- window.addEventListener('touchend', ()=>isAllowedToDrag.current = false, {
964
- once: true
965
- });
966
- }
967
- // Ensure we maintain correct pointer capture even when going outside of the drawer
968
- event.target.setPointerCapture(event.pointerId);
969
- pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
970
- }
971
- function shouldDrag(el, isDraggingInDirection) {
972
- var _window_getSelection;
973
- let element = el;
974
- const highlightedText = (_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString();
975
- const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
976
- const date = new Date();
977
- // Fixes https://github.com/emilkowalski/vaul/issues/483
978
- if (element.tagName === 'SELECT') {
979
- return false;
980
- }
981
- if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {
982
- return false;
983
- }
984
- if (direction === 'right' || direction === 'left') {
985
- return true;
986
- }
987
- // Allow scrolling when animating
988
- if (openTime.current && date.getTime() - openTime.current.getTime() < 500) {
989
- return false;
990
- }
991
- if (swipeAmount !== null) {
992
- if (direction === 'bottom' ? swipeAmount > 0 : swipeAmount < 0) {
993
- return true;
994
- }
995
- }
996
- // Don't drag if there's highlighted text
997
- if (highlightedText && highlightedText.length > 0) {
998
- return false;
999
- }
1000
- // Disallow dragging if drawer was scrolled within `scrollLockTimeout`
1001
- if (lastTimeDragPrevented.current && date.getTime() - lastTimeDragPrevented.current.getTime() < scrollLockTimeout && swipeAmount === 0) {
1002
- lastTimeDragPrevented.current = date;
1003
- return false;
1004
- }
1005
- if (isDraggingInDirection) {
1006
- lastTimeDragPrevented.current = date;
1007
- // We are dragging down so we should allow scrolling
1008
- return false;
1009
- }
1010
- // Keep climbing up the DOM tree as long as there's a parent
1011
- while(element){
1012
- // Check if the element is scrollable
1013
- if (element.scrollHeight > element.clientHeight) {
1014
- if (element.scrollTop !== 0) {
1015
- lastTimeDragPrevented.current = new Date();
1016
- // The element is scrollable and not scrolled to the top, so don't drag
1017
- return false;
1018
- }
1019
- if (element.getAttribute('role') === 'dialog') {
1020
- return true;
1021
- }
1022
- }
1023
- // Move up to the parent element
1024
- element = element.parentNode;
1025
- }
1026
- // No scrollable parents not scrolled to the top found, so drag
1027
- return true;
1028
- }
1029
- function onDrag(event) {
1030
- if (!drawerRef.current) {
1031
- return;
1032
- }
1033
- // We need to know how much of the drawer has been dragged in percentages so that we can transform background accordingly
1034
- if (isDragging) {
1035
- const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
1036
- const draggedDistance = (pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX)) * directionMultiplier;
1037
- const isDraggingInDirection = draggedDistance > 0;
1038
- // Pre condition for disallowing dragging in the close direction.
1039
- const noCloseSnapPointsPreCondition = snapPoints && !dismissible && !isDraggingInDirection;
1040
- // Disallow dragging down to close when first snap point is the active one and dismissible prop is set to false.
1041
- if (noCloseSnapPointsPreCondition && activeSnapPointIndex === 0) return;
1042
- // We need to capture last time when drag with scroll was triggered and have a timeout between
1043
- const absDraggedDistance = Math.abs(draggedDistance);
1044
- const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
1045
- const drawerDimension = direction === 'bottom' || direction === 'top' ? drawerHeightRef.current : drawerWidthRef.current;
1046
- // Calculate the percentage dragged, where 1 is the closed position
1047
- let percentageDragged = absDraggedDistance / drawerDimension;
1048
- const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);
1049
- if (snapPointPercentageDragged !== null) {
1050
- percentageDragged = snapPointPercentageDragged;
1051
- }
1052
- // Disallow close dragging beyond the smallest snap point.
1053
- if (noCloseSnapPointsPreCondition && percentageDragged >= 1) {
1054
- return;
1055
- }
1056
- if (!isAllowedToDrag.current && !shouldDrag(event.target, isDraggingInDirection)) return;
1057
- drawerRef.current.classList.add(DRAG_CLASS);
1058
- // 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
1059
- isAllowedToDrag.current = true;
1060
- set(drawerRef.current, {
1061
- transition: 'none'
1062
- });
1063
- set(overlayRef.current, {
1064
- transition: 'none'
1065
- });
1066
- if (snapPoints) {
1067
- onDragSnapPoints({
1068
- draggedDistance
1069
- });
1070
- }
1071
- // Run this only if snapPoints are not defined or if we are at the last snap point (highest one)
1072
- if (isDraggingInDirection && !snapPoints) {
1073
- const dampenedDraggedDistance = dampenValue(draggedDistance);
1074
- const translateValue = Math.min(dampenedDraggedDistance * -1, 0) * directionMultiplier;
1075
- set(drawerRef.current, {
1076
- transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
1077
- });
1078
- return;
1079
- }
1080
- const opacityValue = 1 - percentageDragged;
1081
- if (shouldFade || fadeFromIndex && activeSnapPointIndex === fadeFromIndex - 1) {
1082
- onDragProp == null ? void 0 : onDragProp(event, percentageDragged);
1083
- set(overlayRef.current, {
1084
- opacity: `${opacityValue}`,
1085
- transition: 'none'
1086
- }, true);
1087
- }
1088
- if (wrapper && overlayRef.current && shouldScaleBackground) {
1089
- // Calculate percentageDragged as a fraction (0 to 1)
1090
- const scaleValue = Math.min(getScale() + percentageDragged * (1 - getScale()), 1);
1091
- const borderRadiusValue = 8 - percentageDragged * 8;
1092
- const translateValue = Math.max(0, 14 - percentageDragged * 14);
1093
- set(wrapper, {
1094
- borderRadius: `${borderRadiusValue}px`,
1095
- transform: isVertical(direction) ? `scale(${scaleValue}) translate3d(0, ${translateValue}px, 0)` : `scale(${scaleValue}) translate3d(${translateValue}px, 0, 0)`,
1096
- transition: 'none'
1097
- }, true);
1098
- }
1099
- if (!snapPoints) {
1100
- const translateValue = absDraggedDistance * directionMultiplier;
1101
- set(drawerRef.current, {
1102
- transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
1103
- });
1104
- }
1105
- }
1106
- }
1107
- React__default.useEffect(()=>{
1108
- window.requestAnimationFrame(()=>{
1109
- shouldAnimate.current = true;
1110
- });
1111
- }, []);
1112
- React__default.useEffect(()=>{
1113
- var _window_visualViewport;
1114
- function onVisualViewportChange() {
1115
- if (!drawerRef.current || !repositionInputs) return;
1116
- const focusedElement = document.activeElement;
1117
- if (isInput(focusedElement) || keyboardIsOpen.current) {
1118
- var _window_visualViewport;
1119
- const visualViewportHeight = ((_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.height) || 0;
1120
- const totalHeight = window.innerHeight;
1121
- // This is the height of the keyboard
1122
- let diffFromInitial = totalHeight - visualViewportHeight;
1123
- const drawerHeight = drawerRef.current.getBoundingClientRect().height || 0;
1124
- // Adjust drawer height only if it's tall enough
1125
- const isTallEnough = drawerHeight > totalHeight * 0.8;
1126
- if (!initialDrawerHeight.current) {
1127
- initialDrawerHeight.current = drawerHeight;
1128
- }
1129
- const offsetFromTop = drawerRef.current.getBoundingClientRect().top;
1130
- // visualViewport height may change due to somq e subtle changes to the keyboard. Checking if the height changed by 60 or more will make sure that they keyboard really changed its open state.
1131
- if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 60) {
1132
- keyboardIsOpen.current = !keyboardIsOpen.current;
1133
- }
1134
- if (snapPoints && snapPoints.length > 0 && snapPointsOffset && activeSnapPointIndex) {
1135
- const activeSnapPointHeight = snapPointsOffset[activeSnapPointIndex] || 0;
1136
- diffFromInitial += activeSnapPointHeight;
1137
- }
1138
- previousDiffFromInitial.current = diffFromInitial;
1139
- // We don't have to change the height if the input is in view, when we are here we are in the opened keyboard state so we can correctly check if the input is in view
1140
- if (drawerHeight > visualViewportHeight || keyboardIsOpen.current) {
1141
- const height = drawerRef.current.getBoundingClientRect().height;
1142
- let newDrawerHeight = height;
1143
- if (height > visualViewportHeight) {
1144
- newDrawerHeight = visualViewportHeight - (isTallEnough ? offsetFromTop : WINDOW_TOP_OFFSET);
1145
- }
1146
- // When fixed, don't move the drawer upwards if there's space, but rather only change it's height so it's fully scrollable when the keyboard is open
1147
- if (fixed) {
1148
- drawerRef.current.style.height = `${height - Math.max(diffFromInitial, 0)}px`;
1149
- } else {
1150
- drawerRef.current.style.height = `${Math.max(newDrawerHeight, visualViewportHeight - offsetFromTop)}px`;
1151
- }
1152
- } else if (!isMobileFirefox()) {
1153
- drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
1154
- }
1155
- if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) {
1156
- drawerRef.current.style.bottom = `0px`;
1157
- } else {
1158
- // Negative bottom value would never make sense
1159
- drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
1160
- }
1161
- }
1162
- }
1163
- (_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.addEventListener('resize', onVisualViewportChange);
1164
- return ()=>{
1165
- var _window_visualViewport;
1166
- return (_window_visualViewport = window.visualViewport) == null ? void 0 : _window_visualViewport.removeEventListener('resize', onVisualViewportChange);
1167
- };
1168
- }, [
1169
- activeSnapPointIndex,
1170
- snapPoints,
1171
- snapPointsOffset
1172
- ]);
1173
- function closeDrawer(fromWithin) {
1174
- cancelDrag();
1175
- onClose == null ? void 0 : onClose();
1176
- if (!fromWithin) {
1177
- setIsOpen(false);
1178
- }
1179
- setTimeout(()=>{
1180
- if (snapPoints) {
1181
- setActiveSnapPoint(snapPoints[0]);
1182
- }
1183
- }, TRANSITIONS.DURATION * 1000); // seconds to ms
1184
- }
1185
- function resetDrawer() {
1186
- if (!drawerRef.current) return;
1187
- const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
1188
- const currentSwipeAmount = getTranslate(drawerRef.current, direction);
1189
- set(drawerRef.current, {
1190
- transform: 'translate3d(0, 0, 0)',
1191
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`
1192
- });
1193
- set(overlayRef.current, {
1194
- transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1195
- opacity: '1'
1196
- });
1197
- // Don't reset background if swiped upwards
1198
- if (shouldScaleBackground && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) {
1199
- set(wrapper, {
1200
- borderRadius: `${BORDER_RADIUS}px`,
1201
- overflow: 'hidden',
1202
- ...isVertical(direction) ? {
1203
- transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
1204
- transformOrigin: 'top'
1205
- } : {
1206
- transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
1207
- transformOrigin: 'left'
1208
- },
1209
- transitionProperty: 'transform, border-radius',
1210
- transitionDuration: `${TRANSITIONS.DURATION}s`,
1211
- transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`
1212
- }, true);
1213
- }
1214
- }
1215
- function cancelDrag() {
1216
- if (!isDragging || !drawerRef.current) return;
1217
- drawerRef.current.classList.remove(DRAG_CLASS);
1218
- isAllowedToDrag.current = false;
1219
- setIsDragging(false);
1220
- dragEndTime.current = new Date();
1221
- }
1222
- function onRelease(event) {
1223
- if (!isDragging || !drawerRef.current) return;
1224
- drawerRef.current.classList.remove(DRAG_CLASS);
1225
- isAllowedToDrag.current = false;
1226
- setIsDragging(false);
1227
- dragEndTime.current = new Date();
1228
- const swipeAmount = getTranslate(drawerRef.current, direction);
1229
- if (!event || !shouldDrag(event.target, false) || !swipeAmount || Number.isNaN(swipeAmount)) return;
1230
- if (dragStartTime.current === null) return;
1231
- const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
1232
- const distMoved = pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX);
1233
- const velocity = Math.abs(distMoved) / timeTaken;
1234
- if (velocity > 0.05) {
1235
- // `justReleased` is needed to prevent the drawer from focusing on an input when the drag ends, as it's not the intent most of the time.
1236
- setJustReleased(true);
1237
- setTimeout(()=>{
1238
- setJustReleased(false);
1239
- }, 200);
1240
- }
1241
- if (snapPoints) {
1242
- const directionMultiplier = direction === 'bottom' || direction === 'right' ? 1 : -1;
1243
- onReleaseSnapPoints({
1244
- draggedDistance: distMoved * directionMultiplier,
1245
- closeDrawer,
1246
- velocity,
1247
- dismissible
1248
- });
1249
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1250
- return;
1251
- }
1252
- // Moved upwards, don't do anything
1253
- if (direction === 'bottom' || direction === 'right' ? distMoved > 0 : distMoved < 0) {
1254
- resetDrawer();
1255
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1256
- return;
1257
- }
1258
- if (velocity > VELOCITY_THRESHOLD) {
1259
- closeDrawer();
1260
- onReleaseProp == null ? void 0 : onReleaseProp(event, false);
1261
- return;
1262
- }
1263
- var _drawerRef_current_getBoundingClientRect_height;
1264
- const visibleDrawerHeight = Math.min((_drawerRef_current_getBoundingClientRect_height = drawerRef.current.getBoundingClientRect().height) != null ? _drawerRef_current_getBoundingClientRect_height : 0, window.innerHeight);
1265
- var _drawerRef_current_getBoundingClientRect_width;
1266
- const visibleDrawerWidth = Math.min((_drawerRef_current_getBoundingClientRect_width = drawerRef.current.getBoundingClientRect().width) != null ? _drawerRef_current_getBoundingClientRect_width : 0, window.innerWidth);
1267
- const isHorizontalSwipe = direction === 'left' || direction === 'right';
1268
- if (Math.abs(swipeAmount) >= (isHorizontalSwipe ? visibleDrawerWidth : visibleDrawerHeight) * closeThreshold) {
1269
- closeDrawer();
1270
- onReleaseProp == null ? void 0 : onReleaseProp(event, false);
1271
- return;
1272
- }
1273
- onReleaseProp == null ? void 0 : onReleaseProp(event, true);
1274
- resetDrawer();
1275
- }
1276
- React__default.useEffect(()=>{
1277
- // Trigger enter animation without using CSS animation
1278
- if (isOpen) {
1279
- set(document.documentElement, {
1280
- scrollBehavior: 'auto'
1281
- });
1282
- openTime.current = new Date();
1283
- }
1284
- return ()=>{
1285
- reset(document.documentElement, 'scrollBehavior');
1286
- };
1287
- }, [
1288
- isOpen
1289
- ]);
1290
- function onNestedOpenChange(o) {
1291
- const scale = o ? (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth : 1;
1292
- const initialTranslate = o ? -NESTED_DISPLACEMENT : 0;
1293
- if (nestedOpenChangeTimer.current) {
1294
- window.clearTimeout(nestedOpenChangeTimer.current);
1295
- }
1296
- set(drawerRef.current, {
1297
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1298
- transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)` : `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`
1299
- });
1300
- if (!o && drawerRef.current) {
1301
- nestedOpenChangeTimer.current = setTimeout(()=>{
1302
- const translateValue = getTranslate(drawerRef.current, direction);
1303
- set(drawerRef.current, {
1304
- transition: 'none',
1305
- transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
1306
- });
1307
- }, 500);
1308
- }
1309
- }
1310
- function onNestedDrag(_event, percentageDragged) {
1311
- if (percentageDragged < 0) return;
1312
- const initialScale = (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth;
1313
- const newScale = initialScale + percentageDragged * (1 - initialScale);
1314
- const newTranslate = -NESTED_DISPLACEMENT + percentageDragged * NESTED_DISPLACEMENT;
1315
- set(drawerRef.current, {
1316
- transform: isVertical(direction) ? `scale(${newScale}) translate3d(0, ${newTranslate}px, 0)` : `scale(${newScale}) translate3d(${newTranslate}px, 0, 0)`,
1317
- transition: 'none'
1318
- });
1319
- }
1320
- function onNestedRelease(_event, o) {
1321
- const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
1322
- const scale = o ? (dim - NESTED_DISPLACEMENT) / dim : 1;
1323
- const translate = o ? -NESTED_DISPLACEMENT : 0;
1324
- if (o) {
1325
- set(drawerRef.current, {
1326
- transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,
1327
- transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${translate}px, 0)` : `scale(${scale}) translate3d(${translate}px, 0, 0)`
1328
- });
1329
- }
1330
- }
1331
- React__default.useEffect(()=>{
1332
- if (!modal) {
1333
- // Need to do this manually unfortunately
1334
- window.requestAnimationFrame(()=>{
1335
- document.body.style.pointerEvents = 'auto';
1336
- });
1337
- }
1338
- }, [
1339
- modal
1340
- ]);
1341
- return /*#__PURE__*/ React__default.createElement(Dialog.Root, {
1342
- defaultOpen: defaultOpen,
1343
- onOpenChange: (open)=>{
1344
- if (!dismissible && !open) return;
1345
- if (open) {
1346
- setHasBeenOpened(true);
1347
- } else {
1348
- closeDrawer(true);
1349
- }
1350
- setIsOpen(open);
1351
- },
1352
- open: isOpen,
1353
- modal: modal
1354
- }, /*#__PURE__*/ React__default.createElement(DrawerContext.Provider, {
1355
- value: {
1356
- activeSnapPoint,
1357
- snapPoints,
1358
- setActiveSnapPoint,
1359
- drawerRef,
1360
- overlayRef,
1361
- onOpenChange,
1362
- onPress,
1363
- onRelease,
1364
- onDrag,
1365
- dismissible,
1366
- shouldAnimate,
1367
- handleOnly,
1368
- isOpen,
1369
- isDragging,
1370
- shouldFade,
1371
- closeDrawer,
1372
- onNestedDrag,
1373
- onNestedOpenChange,
1374
- onNestedRelease,
1375
- keyboardIsOpen,
1376
- modal,
1377
- snapPointsOffset,
1378
- activeSnapPointIndex,
1379
- direction,
1380
- shouldScaleBackground,
1381
- setBackgroundColorOnScale,
1382
- noBodyStyles,
1383
- container,
1384
- autoFocus
1385
- }
1386
- }, children));
667
+ //#endregion
668
+ //#region src/index.tsx
669
+ 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 }) {
670
+ var _drawerRef$current, _drawerRef$current2;
671
+ const [isOpen = false, setIsOpen] = useControllableState({
672
+ defaultProp: defaultOpen,
673
+ prop: openProp,
674
+ onChange: (o) => {
675
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(o);
676
+ if (!o && !nested) restorePositionSetting();
677
+ setTimeout(() => {
678
+ onAnimationEnd === null || onAnimationEnd === void 0 || onAnimationEnd(o);
679
+ }, TRANSITIONS.DURATION * 1e3);
680
+ if (o && !modal) {
681
+ if (typeof window !== "undefined") window.requestAnimationFrame(() => {
682
+ document.body.style.pointerEvents = "auto";
683
+ });
684
+ }
685
+ if (!o) document.body.style.pointerEvents = "auto";
686
+ }
687
+ });
688
+ const [hasBeenOpened, setHasBeenOpened] = React.useState(false);
689
+ const [isDragging, setIsDragging] = React.useState(false);
690
+ const [justReleased, setJustReleased] = React.useState(false);
691
+ const overlayRef = React.useRef(null);
692
+ const openTime = React.useRef(null);
693
+ const dragStartTime = React.useRef(null);
694
+ const dragEndTime = React.useRef(null);
695
+ const lastTimeDragPrevented = React.useRef(null);
696
+ const isAllowedToDrag = React.useRef(false);
697
+ const nestedOpenChangeTimer = React.useRef(null);
698
+ const pointerStart = React.useRef(0);
699
+ const keyboardIsOpen = React.useRef(false);
700
+ const shouldAnimate = React.useRef(!defaultOpen);
701
+ const previousDiffFromInitial = React.useRef(0);
702
+ const drawerRef = React.useRef(null);
703
+ const drawerHeightRef = React.useRef(((_drawerRef$current = drawerRef.current) === null || _drawerRef$current === void 0 ? void 0 : _drawerRef$current.getBoundingClientRect().height) || 0);
704
+ const drawerWidthRef = React.useRef(((_drawerRef$current2 = drawerRef.current) === null || _drawerRef$current2 === void 0 ? void 0 : _drawerRef$current2.getBoundingClientRect().width) || 0);
705
+ const initialDrawerHeight = React.useRef(0);
706
+ const { activeSnapPoint, activeSnapPointIndex, setActiveSnapPoint, onRelease: onReleaseSnapPoints, snapPointsOffset, onDrag: onDragSnapPoints, shouldFade, getPercentageDragged: getSnapPointsPercentageDragged } = useSnapPoints({
707
+ snapPoints,
708
+ activeSnapPointProp,
709
+ setActiveSnapPointProp,
710
+ drawerRef,
711
+ fadeFromIndex,
712
+ overlayRef,
713
+ onSnapPointChange: React.useCallback((activeSnapPointIndex$1) => {
714
+ if (snapPoints && activeSnapPointIndex$1 === snapPointsOffset.length - 1) openTime.current = /* @__PURE__ */ new Date();
715
+ }, []),
716
+ direction,
717
+ container,
718
+ snapToSequentialPoint
719
+ });
720
+ usePreventScroll({ isDisabled: !isOpen || isDragging || !modal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll });
721
+ const { restorePositionSetting } = usePositionFixed({
722
+ isOpen,
723
+ modal,
724
+ nested: nested ?? false,
725
+ hasBeenOpened,
726
+ preventScrollRestoration,
727
+ noBodyStyles
728
+ });
729
+ function getScale() {
730
+ return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
731
+ }
732
+ function onPress(event) {
733
+ var _drawerRef$current3, _drawerRef$current4;
734
+ if (!dismissible && !snapPoints) return;
735
+ if (drawerRef.current && !drawerRef.current.contains(event.target)) return;
736
+ drawerHeightRef.current = ((_drawerRef$current3 = drawerRef.current) === null || _drawerRef$current3 === void 0 ? void 0 : _drawerRef$current3.getBoundingClientRect().height) || 0;
737
+ drawerWidthRef.current = ((_drawerRef$current4 = drawerRef.current) === null || _drawerRef$current4 === void 0 ? void 0 : _drawerRef$current4.getBoundingClientRect().width) || 0;
738
+ setIsDragging(true);
739
+ dragStartTime.current = /* @__PURE__ */ new Date();
740
+ if (isIOS()) window.addEventListener("touchend", () => isAllowedToDrag.current = false, { once: true });
741
+ event.target.setPointerCapture(event.pointerId);
742
+ pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;
743
+ }
744
+ function shouldDrag(el, isDraggingInDirection) {
745
+ var _window$getSelection;
746
+ let element = el;
747
+ const highlightedText = (_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString();
748
+ const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;
749
+ const date = /* @__PURE__ */ new Date();
750
+ if (element.tagName === "SELECT") return false;
751
+ if (element.hasAttribute("data-vaul-no-drag") || element.closest("[data-vaul-no-drag]")) return false;
752
+ if (direction === "right" || direction === "left") return true;
753
+ if (openTime.current && date.getTime() - openTime.current.getTime() < 500) return false;
754
+ if (swipeAmount !== null) {
755
+ if (direction === "bottom" ? swipeAmount > 0 : swipeAmount < 0) return true;
756
+ }
757
+ if (highlightedText && highlightedText.length > 0) return false;
758
+ if (lastTimeDragPrevented.current && date.getTime() - lastTimeDragPrevented.current.getTime() < scrollLockTimeout && swipeAmount === 0) {
759
+ lastTimeDragPrevented.current = date;
760
+ return false;
761
+ }
762
+ if (isDraggingInDirection) {
763
+ lastTimeDragPrevented.current = date;
764
+ return false;
765
+ }
766
+ while (element) {
767
+ if (element.scrollHeight > element.clientHeight) {
768
+ if (element.scrollTop !== 0) {
769
+ lastTimeDragPrevented.current = /* @__PURE__ */ new Date();
770
+ return false;
771
+ }
772
+ if (element.getAttribute("role") === "dialog") return true;
773
+ }
774
+ element = element.parentNode;
775
+ }
776
+ return true;
777
+ }
778
+ function onDrag(event) {
779
+ if (!drawerRef.current) return;
780
+ if (isDragging) {
781
+ const directionMultiplier = direction === "bottom" || direction === "right" ? 1 : -1;
782
+ const draggedDistance = (pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX)) * directionMultiplier;
783
+ const isDraggingInDirection = draggedDistance > 0;
784
+ const noCloseSnapPointsPreCondition = snapPoints && !dismissible && !isDraggingInDirection;
785
+ if (noCloseSnapPointsPreCondition && activeSnapPointIndex === 0) return;
786
+ const absDraggedDistance = Math.abs(draggedDistance);
787
+ const wrapper = document.querySelector("[data-vaul-drawer-wrapper]");
788
+ let percentageDragged = absDraggedDistance / (direction === "bottom" || direction === "top" ? drawerHeightRef.current : drawerWidthRef.current);
789
+ const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);
790
+ if (snapPointPercentageDragged !== null) percentageDragged = snapPointPercentageDragged;
791
+ if (noCloseSnapPointsPreCondition && percentageDragged >= 1) return;
792
+ if (!isAllowedToDrag.current && !shouldDrag(event.target, isDraggingInDirection)) return;
793
+ drawerRef.current.classList.add(DRAG_CLASS);
794
+ isAllowedToDrag.current = true;
795
+ set(drawerRef.current, { transition: "none" });
796
+ set(overlayRef.current, { transition: "none" });
797
+ if (snapPoints) onDragSnapPoints({ draggedDistance });
798
+ if (isDraggingInDirection && !snapPoints) {
799
+ const dampenedDraggedDistance = dampenValue(draggedDistance);
800
+ const translateValue = Math.min(dampenedDraggedDistance * -1, 0) * directionMultiplier;
801
+ set(drawerRef.current, { transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)` });
802
+ return;
803
+ }
804
+ const opacityValue = 1 - percentageDragged;
805
+ if (shouldFade || fadeFromIndex && activeSnapPointIndex === fadeFromIndex - 1) {
806
+ onDragProp === null || onDragProp === void 0 || onDragProp(event, percentageDragged);
807
+ set(overlayRef.current, {
808
+ opacity: `${opacityValue}`,
809
+ transition: "none"
810
+ }, true);
811
+ }
812
+ if (wrapper && overlayRef.current && shouldScaleBackground) {
813
+ const scaleValue = Math.min(getScale() + percentageDragged * (1 - getScale()), 1);
814
+ const borderRadiusValue = 8 - percentageDragged * 8;
815
+ const translateValue = Math.max(0, 14 - percentageDragged * 14);
816
+ set(wrapper, {
817
+ borderRadius: `${borderRadiusValue}px`,
818
+ transform: isVertical(direction) ? `scale(${scaleValue}) translate3d(0, ${translateValue}px, 0)` : `scale(${scaleValue}) translate3d(${translateValue}px, 0, 0)`,
819
+ transition: "none"
820
+ }, true);
821
+ }
822
+ if (!snapPoints) {
823
+ const translateValue = absDraggedDistance * directionMultiplier;
824
+ set(drawerRef.current, { transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)` });
825
+ }
826
+ }
827
+ }
828
+ React.useEffect(() => {
829
+ window.requestAnimationFrame(() => {
830
+ shouldAnimate.current = true;
831
+ });
832
+ }, []);
833
+ React.useEffect(() => {
834
+ var _window$visualViewpor2;
835
+ function onVisualViewportChange() {
836
+ if (!drawerRef.current || !repositionInputs) return;
837
+ const focusedElement = document.activeElement;
838
+ if (isInput(focusedElement) || keyboardIsOpen.current) {
839
+ var _window$visualViewpor;
840
+ const visualViewportHeight = ((_window$visualViewpor = window.visualViewport) === null || _window$visualViewpor === void 0 ? void 0 : _window$visualViewpor.height) || 0;
841
+ const totalHeight = window.innerHeight;
842
+ let diffFromInitial = totalHeight - visualViewportHeight;
843
+ const drawerHeight = drawerRef.current.getBoundingClientRect().height || 0;
844
+ const isTallEnough = drawerHeight > totalHeight * .8;
845
+ if (!initialDrawerHeight.current) initialDrawerHeight.current = drawerHeight;
846
+ const offsetFromTop = drawerRef.current.getBoundingClientRect().top;
847
+ if (Math.abs(previousDiffFromInitial.current - diffFromInitial) > 60) keyboardIsOpen.current = !keyboardIsOpen.current;
848
+ if (snapPoints && snapPoints.length > 0 && snapPointsOffset && activeSnapPointIndex) {
849
+ const activeSnapPointHeight = snapPointsOffset[activeSnapPointIndex] || 0;
850
+ diffFromInitial += activeSnapPointHeight;
851
+ }
852
+ previousDiffFromInitial.current = diffFromInitial;
853
+ if (drawerHeight > visualViewportHeight || keyboardIsOpen.current) {
854
+ const height = drawerRef.current.getBoundingClientRect().height;
855
+ let newDrawerHeight = height;
856
+ if (height > visualViewportHeight) newDrawerHeight = visualViewportHeight - (isTallEnough ? offsetFromTop : WINDOW_TOP_OFFSET);
857
+ if (fixed) drawerRef.current.style.height = `${height - Math.max(diffFromInitial, 0)}px`;
858
+ else drawerRef.current.style.height = `${Math.max(newDrawerHeight, visualViewportHeight - offsetFromTop)}px`;
859
+ } else if (!isMobileFirefox()) drawerRef.current.style.height = `${initialDrawerHeight.current}px`;
860
+ if (snapPoints && snapPoints.length > 0 && !keyboardIsOpen.current) drawerRef.current.style.bottom = `0px`;
861
+ else drawerRef.current.style.bottom = `${Math.max(diffFromInitial, 0)}px`;
862
+ }
863
+ }
864
+ (_window$visualViewpor2 = window.visualViewport) === null || _window$visualViewpor2 === void 0 || _window$visualViewpor2.addEventListener("resize", onVisualViewportChange);
865
+ return () => {
866
+ var _window$visualViewpor3;
867
+ return (_window$visualViewpor3 = window.visualViewport) === null || _window$visualViewpor3 === void 0 ? void 0 : _window$visualViewpor3.removeEventListener("resize", onVisualViewportChange);
868
+ };
869
+ }, [
870
+ activeSnapPointIndex,
871
+ snapPoints,
872
+ snapPointsOffset
873
+ ]);
874
+ function closeDrawer(fromWithin) {
875
+ cancelDrag();
876
+ onClose === null || onClose === void 0 || onClose();
877
+ if (!fromWithin) setIsOpen(false);
878
+ setTimeout(() => {
879
+ if (snapPoints) setActiveSnapPoint(snapPoints[0]);
880
+ }, TRANSITIONS.DURATION * 1e3);
881
+ }
882
+ function resetDrawer() {
883
+ if (!drawerRef.current) return;
884
+ const wrapper = document.querySelector("[data-vaul-drawer-wrapper]");
885
+ const currentSwipeAmount = getTranslate(drawerRef.current, direction);
886
+ set(drawerRef.current, {
887
+ transform: "translate3d(0, 0, 0)",
888
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`
889
+ });
890
+ set(overlayRef.current, {
891
+ transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
892
+ opacity: "1"
893
+ });
894
+ if (shouldScaleBackground && currentSwipeAmount && currentSwipeAmount > 0 && isOpen) set(wrapper, {
895
+ borderRadius: `${BORDER_RADIUS}px`,
896
+ overflow: "hidden",
897
+ ...isVertical(direction) ? {
898
+ transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
899
+ transformOrigin: "top"
900
+ } : {
901
+ transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
902
+ transformOrigin: "left"
903
+ },
904
+ transitionProperty: "transform, border-radius",
905
+ transitionDuration: `${TRANSITIONS.DURATION}s`,
906
+ transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(",")})`
907
+ }, true);
908
+ }
909
+ function cancelDrag() {
910
+ if (!isDragging || !drawerRef.current) return;
911
+ drawerRef.current.classList.remove(DRAG_CLASS);
912
+ isAllowedToDrag.current = false;
913
+ setIsDragging(false);
914
+ dragEndTime.current = /* @__PURE__ */ new Date();
915
+ }
916
+ function onRelease(event) {
917
+ if (!isDragging || !drawerRef.current) return;
918
+ drawerRef.current.classList.remove(DRAG_CLASS);
919
+ isAllowedToDrag.current = false;
920
+ setIsDragging(false);
921
+ dragEndTime.current = /* @__PURE__ */ new Date();
922
+ const swipeAmount = getTranslate(drawerRef.current, direction);
923
+ if (!event || !shouldDrag(event.target, false) || !swipeAmount || Number.isNaN(swipeAmount)) return;
924
+ if (dragStartTime.current === null) return;
925
+ const timeTaken = dragEndTime.current.getTime() - dragStartTime.current.getTime();
926
+ const distMoved = pointerStart.current - (isVertical(direction) ? event.pageY : event.pageX);
927
+ const velocity = Math.abs(distMoved) / timeTaken;
928
+ if (velocity > .05) {
929
+ setJustReleased(true);
930
+ setTimeout(() => {
931
+ setJustReleased(false);
932
+ }, 200);
933
+ }
934
+ if (snapPoints) {
935
+ onReleaseSnapPoints({
936
+ draggedDistance: distMoved * (direction === "bottom" || direction === "right" ? 1 : -1),
937
+ closeDrawer,
938
+ velocity,
939
+ dismissible
940
+ });
941
+ onReleaseProp === null || onReleaseProp === void 0 || onReleaseProp(event, true);
942
+ return;
943
+ }
944
+ if (direction === "bottom" || direction === "right" ? distMoved > 0 : distMoved < 0) {
945
+ resetDrawer();
946
+ onReleaseProp === null || onReleaseProp === void 0 || onReleaseProp(event, true);
947
+ return;
948
+ }
949
+ if (velocity > VELOCITY_THRESHOLD) {
950
+ closeDrawer();
951
+ onReleaseProp === null || onReleaseProp === void 0 || onReleaseProp(event, false);
952
+ return;
953
+ }
954
+ const visibleDrawerHeight = Math.min(drawerRef.current.getBoundingClientRect().height ?? 0, window.innerHeight);
955
+ const visibleDrawerWidth = Math.min(drawerRef.current.getBoundingClientRect().width ?? 0, window.innerWidth);
956
+ const isHorizontalSwipe = direction === "left" || direction === "right";
957
+ if (Math.abs(swipeAmount) >= (isHorizontalSwipe ? visibleDrawerWidth : visibleDrawerHeight) * closeThreshold) {
958
+ closeDrawer();
959
+ onReleaseProp === null || onReleaseProp === void 0 || onReleaseProp(event, false);
960
+ return;
961
+ }
962
+ onReleaseProp === null || onReleaseProp === void 0 || onReleaseProp(event, true);
963
+ resetDrawer();
964
+ }
965
+ React.useEffect(() => {
966
+ if (isOpen) {
967
+ set(document.documentElement, { scrollBehavior: "auto" });
968
+ openTime.current = /* @__PURE__ */ new Date();
969
+ }
970
+ return () => {
971
+ reset(document.documentElement, "scrollBehavior");
972
+ };
973
+ }, [isOpen]);
974
+ function onNestedOpenChange(o) {
975
+ const scale = o ? (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth : 1;
976
+ const initialTranslate = o ? -NESTED_DISPLACEMENT : 0;
977
+ if (nestedOpenChangeTimer.current) window.clearTimeout(nestedOpenChangeTimer.current);
978
+ set(drawerRef.current, {
979
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
980
+ transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${initialTranslate}px, 0)` : `scale(${scale}) translate3d(${initialTranslate}px, 0, 0)`
981
+ });
982
+ if (!o && drawerRef.current) nestedOpenChangeTimer.current = setTimeout(() => {
983
+ const translateValue = getTranslate(drawerRef.current, direction);
984
+ set(drawerRef.current, {
985
+ transition: "none",
986
+ transform: isVertical(direction) ? `translate3d(0, ${translateValue}px, 0)` : `translate3d(${translateValue}px, 0, 0)`
987
+ });
988
+ }, 500);
989
+ }
990
+ function onNestedDrag(_event, percentageDragged) {
991
+ if (percentageDragged < 0) return;
992
+ const initialScale = (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth;
993
+ const newScale = initialScale + percentageDragged * (1 - initialScale);
994
+ const newTranslate = -NESTED_DISPLACEMENT + percentageDragged * NESTED_DISPLACEMENT;
995
+ set(drawerRef.current, {
996
+ transform: isVertical(direction) ? `scale(${newScale}) translate3d(0, ${newTranslate}px, 0)` : `scale(${newScale}) translate3d(${newTranslate}px, 0, 0)`,
997
+ transition: "none"
998
+ });
999
+ }
1000
+ function onNestedRelease(_event, o) {
1001
+ const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;
1002
+ const scale = o ? (dim - NESTED_DISPLACEMENT) / dim : 1;
1003
+ const translate = o ? -NESTED_DISPLACEMENT : 0;
1004
+ if (o) set(drawerRef.current, {
1005
+ transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
1006
+ transform: isVertical(direction) ? `scale(${scale}) translate3d(0, ${translate}px, 0)` : `scale(${scale}) translate3d(${translate}px, 0, 0)`
1007
+ });
1008
+ }
1009
+ React.useEffect(() => {
1010
+ if (!modal) window.requestAnimationFrame(() => {
1011
+ document.body.style.pointerEvents = "auto";
1012
+ });
1013
+ }, [modal]);
1014
+ return /* @__PURE__ */ jsx(Dialog.Root, {
1015
+ defaultOpen,
1016
+ onOpenChange: (open) => {
1017
+ if (!dismissible && !open) return;
1018
+ if (open) setHasBeenOpened(true);
1019
+ else closeDrawer(true);
1020
+ setIsOpen(open);
1021
+ },
1022
+ open: isOpen,
1023
+ modal,
1024
+ children: /* @__PURE__ */ jsx(DrawerContext.Provider, {
1025
+ value: {
1026
+ activeSnapPoint,
1027
+ snapPoints,
1028
+ setActiveSnapPoint,
1029
+ drawerRef,
1030
+ overlayRef,
1031
+ onOpenChange,
1032
+ onPress,
1033
+ onRelease,
1034
+ onDrag,
1035
+ dismissible,
1036
+ shouldAnimate,
1037
+ handleOnly,
1038
+ isOpen,
1039
+ isDragging,
1040
+ shouldFade,
1041
+ closeDrawer,
1042
+ onNestedDrag,
1043
+ onNestedOpenChange,
1044
+ onNestedRelease,
1045
+ keyboardIsOpen,
1046
+ modal,
1047
+ snapPointsOffset,
1048
+ activeSnapPointIndex,
1049
+ direction,
1050
+ shouldScaleBackground,
1051
+ setBackgroundColorOnScale,
1052
+ noBodyStyles,
1053
+ container,
1054
+ autoFocus
1055
+ },
1056
+ children
1057
+ })
1058
+ });
1387
1059
  }
1388
- const Overlay = /*#__PURE__*/ React__default.forwardRef(function({ ...rest }, ref) {
1389
- const { overlayRef, snapPoints, onRelease, shouldFade, isOpen, modal, shouldAnimate } = useDrawerContext();
1390
- const composedRef = useComposedRefs(ref, overlayRef);
1391
- const hasSnapPoints = snapPoints && snapPoints.length > 0;
1392
- const onMouseUp = React__default.useCallback((event)=>onRelease(event), [
1393
- onRelease
1394
- ]);
1395
- // Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
1396
- if (!modal) {
1397
- return null;
1398
- }
1399
- return /*#__PURE__*/ React__default.createElement(Dialog.Backdrop, {
1400
- onMouseUp: onMouseUp,
1401
- ref: composedRef,
1402
- "data-vaul-overlay": "",
1403
- "data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
1404
- "data-vaul-snap-points-overlay": isOpen && shouldFade ? 'true' : 'false',
1405
- "data-vaul-animate": (shouldAnimate == null ? void 0 : shouldAnimate.current) ? 'true' : 'false',
1406
- ...rest
1407
- });
1060
+ const Overlay = React.forwardRef(function({ ...rest }, ref) {
1061
+ const { overlayRef, snapPoints, onRelease, shouldFade, isOpen, modal, shouldAnimate } = useDrawerContext();
1062
+ const composedRef = useComposedRefs(ref, overlayRef);
1063
+ const hasSnapPoints = snapPoints && snapPoints.length > 0;
1064
+ const onMouseUp = React.useCallback((event) => onRelease(event), [onRelease]);
1065
+ if (!modal) return null;
1066
+ return /* @__PURE__ */ jsx(Dialog.Backdrop, {
1067
+ onMouseUp,
1068
+ ref: composedRef,
1069
+ "data-vaul-overlay": "",
1070
+ "data-vaul-snap-points": isOpen && hasSnapPoints ? "true" : "false",
1071
+ "data-vaul-snap-points-overlay": isOpen && shouldFade ? "true" : "false",
1072
+ "data-vaul-animate": (shouldAnimate === null || shouldAnimate === void 0 ? void 0 : shouldAnimate.current) ? "true" : "false",
1073
+ ...rest
1074
+ });
1408
1075
  });
1409
- Overlay.displayName = 'Drawer.Overlay';
1410
- const Content = /*#__PURE__*/ React__default.forwardRef(function({ style, ...rest }, ref) {
1411
- const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, shouldAnimate, autoFocus } = useDrawerContext();
1412
- // Needed to use transition instead of animations
1413
- const [delayedSnapPoints, setDelayedSnapPoints] = React__default.useState(false);
1414
- const composedRef = useComposedRefs(ref, drawerRef);
1415
- const pointerStartRef = React__default.useRef(null);
1416
- const lastKnownPointerEventRef = React__default.useRef(null);
1417
- const wasBeyondThePointRef = React__default.useRef(false);
1418
- const hasSnapPoints = snapPoints && snapPoints.length > 0;
1419
- useScaleBackground();
1420
- const isDeltaInDirection = (delta, direction, threshold = 0)=>{
1421
- if (wasBeyondThePointRef.current) return true;
1422
- const deltaY = Math.abs(delta.y);
1423
- const deltaX = Math.abs(delta.x);
1424
- const isDeltaX = deltaX > deltaY;
1425
- const dFactor = [
1426
- 'bottom',
1427
- 'right'
1428
- ].includes(direction) ? 1 : -1;
1429
- if (direction === 'left' || direction === 'right') {
1430
- const isReverseDirection = delta.x * dFactor < 0;
1431
- if (!isReverseDirection && deltaX >= 0 && deltaX <= threshold) {
1432
- return isDeltaX;
1433
- }
1434
- } else {
1435
- const isReverseDirection = delta.y * dFactor < 0;
1436
- if (!isReverseDirection && deltaY >= 0 && deltaY <= threshold) {
1437
- return !isDeltaX;
1438
- }
1439
- }
1440
- wasBeyondThePointRef.current = true;
1441
- return true;
1442
- };
1443
- React__default.useEffect(()=>{
1444
- if (hasSnapPoints) {
1445
- window.requestAnimationFrame(()=>{
1446
- setDelayedSnapPoints(true);
1447
- });
1448
- }
1449
- }, []);
1450
- function handleOnPointerUp(event) {
1451
- pointerStartRef.current = null;
1452
- wasBeyondThePointRef.current = false;
1453
- onRelease(event);
1454
- }
1455
- return /*#__PURE__*/ React__default.createElement(Dialog.Viewport, null, /*#__PURE__*/ React__default.createElement(Dialog.Popup, {
1456
- "data-vaul-drawer-direction": direction,
1457
- "data-vaul-drawer": "",
1458
- "data-vaul-delayed-snap-points": delayedSnapPoints ? 'true' : 'false',
1459
- "data-vaul-snap-points": isOpen && hasSnapPoints ? 'true' : 'false',
1460
- "data-vaul-custom-container": container ? 'true' : 'false',
1461
- "data-vaul-animate": (shouldAnimate == null ? void 0 : shouldAnimate.current) ? 'true' : 'false',
1462
- ...rest,
1463
- ref: composedRef,
1464
- style: snapPointsOffset && snapPointsOffset.length > 0 ? {
1465
- // @ts-ignore This should not be an error
1466
- '--snap-point-height': `${snapPointsOffset[activeSnapPointIndex != null ? activeSnapPointIndex : 0]}px`,
1467
- ...style
1468
- } : style,
1469
- onPointerDown: (event)=>{
1470
- if (handleOnly) return;
1471
- rest.onPointerDown == null ? void 0 : rest.onPointerDown.call(rest, event);
1472
- pointerStartRef.current = {
1473
- x: event.pageX,
1474
- y: event.pageY
1475
- };
1476
- onPress(event);
1477
- },
1478
- onPointerMove: (event)=>{
1479
- lastKnownPointerEventRef.current = event;
1480
- if (handleOnly) return;
1481
- rest.onPointerMove == null ? void 0 : rest.onPointerMove.call(rest, event);
1482
- if (!pointerStartRef.current) return;
1483
- const yPosition = event.pageY - pointerStartRef.current.y;
1484
- const xPosition = event.pageX - pointerStartRef.current.x;
1485
- const swipeStartThreshold = event.pointerType === 'touch' ? 10 : 2;
1486
- const delta = {
1487
- x: xPosition,
1488
- y: yPosition
1489
- };
1490
- const isAllowedToSwipe = isDeltaInDirection(delta, direction, swipeStartThreshold);
1491
- if (isAllowedToSwipe) onDrag(event);
1492
- else if (Math.abs(xPosition) > swipeStartThreshold || Math.abs(yPosition) > swipeStartThreshold) {
1493
- pointerStartRef.current = null;
1494
- }
1495
- },
1496
- onPointerUp: (event)=>{
1497
- rest.onPointerUp == null ? void 0 : rest.onPointerUp.call(rest, event);
1498
- pointerStartRef.current = null;
1499
- wasBeyondThePointRef.current = false;
1500
- onRelease(event);
1501
- },
1502
- onPointerOut: (event)=>{
1503
- rest.onPointerOut == null ? void 0 : rest.onPointerOut.call(rest, event);
1504
- handleOnPointerUp(lastKnownPointerEventRef.current);
1505
- },
1506
- onContextMenu: (event)=>{
1507
- rest.onContextMenu == null ? void 0 : rest.onContextMenu.call(rest, event);
1508
- if (lastKnownPointerEventRef.current) {
1509
- handleOnPointerUp(lastKnownPointerEventRef.current);
1510
- }
1511
- }
1512
- }));
1076
+ Overlay.displayName = "Drawer.Overlay";
1077
+ const Content = React.forwardRef(function({ style, ...rest }, ref) {
1078
+ const { drawerRef, onPress, onRelease, onDrag, keyboardIsOpen, snapPointsOffset, activeSnapPointIndex, modal, isOpen, direction, snapPoints, container, handleOnly, shouldAnimate, autoFocus } = useDrawerContext();
1079
+ const [delayedSnapPoints, setDelayedSnapPoints] = React.useState(false);
1080
+ const composedRef = useComposedRefs(ref, drawerRef);
1081
+ const pointerStartRef = React.useRef(null);
1082
+ const lastKnownPointerEventRef = React.useRef(null);
1083
+ const wasBeyondThePointRef = React.useRef(false);
1084
+ const hasSnapPoints = snapPoints && snapPoints.length > 0;
1085
+ useScaleBackground();
1086
+ const isDeltaInDirection = (delta, direction$1, threshold = 0) => {
1087
+ if (wasBeyondThePointRef.current) return true;
1088
+ const deltaY = Math.abs(delta.y);
1089
+ const deltaX = Math.abs(delta.x);
1090
+ const isDeltaX = deltaX > deltaY;
1091
+ const dFactor = ["bottom", "right"].includes(direction$1) ? 1 : -1;
1092
+ if (direction$1 === "left" || direction$1 === "right") {
1093
+ if (!(delta.x * dFactor < 0) && deltaX >= 0 && deltaX <= threshold) return isDeltaX;
1094
+ } else if (!(delta.y * dFactor < 0) && deltaY >= 0 && deltaY <= threshold) return !isDeltaX;
1095
+ wasBeyondThePointRef.current = true;
1096
+ return true;
1097
+ };
1098
+ React.useEffect(() => {
1099
+ if (hasSnapPoints) window.requestAnimationFrame(() => {
1100
+ setDelayedSnapPoints(true);
1101
+ });
1102
+ }, []);
1103
+ function handleOnPointerUp(event) {
1104
+ pointerStartRef.current = null;
1105
+ wasBeyondThePointRef.current = false;
1106
+ onRelease(event);
1107
+ }
1108
+ return /* @__PURE__ */ jsx(Dialog.Viewport, { children: /* @__PURE__ */ jsx(Dialog.Popup, {
1109
+ "data-vaul-drawer-direction": direction,
1110
+ "data-vaul-drawer": "",
1111
+ "data-vaul-delayed-snap-points": delayedSnapPoints ? "true" : "false",
1112
+ "data-vaul-snap-points": isOpen && hasSnapPoints ? "true" : "false",
1113
+ "data-vaul-custom-container": container ? "true" : "false",
1114
+ "data-vaul-animate": (shouldAnimate === null || shouldAnimate === void 0 ? void 0 : shouldAnimate.current) ? "true" : "false",
1115
+ ...rest,
1116
+ ref: composedRef,
1117
+ style: snapPointsOffset && snapPointsOffset.length > 0 ? {
1118
+ "--snap-point-height": `${snapPointsOffset[activeSnapPointIndex ?? 0]}px`,
1119
+ ...style
1120
+ } : style,
1121
+ onPointerDown: (event) => {
1122
+ var _rest$onPointerDown;
1123
+ if (handleOnly) return;
1124
+ (_rest$onPointerDown = rest.onPointerDown) === null || _rest$onPointerDown === void 0 || _rest$onPointerDown.call(rest, event);
1125
+ pointerStartRef.current = {
1126
+ x: event.pageX,
1127
+ y: event.pageY
1128
+ };
1129
+ onPress(event);
1130
+ },
1131
+ onPointerMove: (event) => {
1132
+ var _rest$onPointerMove;
1133
+ lastKnownPointerEventRef.current = event;
1134
+ if (handleOnly) return;
1135
+ (_rest$onPointerMove = rest.onPointerMove) === null || _rest$onPointerMove === void 0 || _rest$onPointerMove.call(rest, event);
1136
+ if (!pointerStartRef.current) return;
1137
+ const yPosition = event.pageY - pointerStartRef.current.y;
1138
+ const xPosition = event.pageX - pointerStartRef.current.x;
1139
+ const swipeStartThreshold = event.pointerType === "touch" ? 10 : 2;
1140
+ if (isDeltaInDirection({
1141
+ x: xPosition,
1142
+ y: yPosition
1143
+ }, direction, swipeStartThreshold)) onDrag(event);
1144
+ else if (Math.abs(xPosition) > swipeStartThreshold || Math.abs(yPosition) > swipeStartThreshold) pointerStartRef.current = null;
1145
+ },
1146
+ onPointerUp: (event) => {
1147
+ var _rest$onPointerUp;
1148
+ (_rest$onPointerUp = rest.onPointerUp) === null || _rest$onPointerUp === void 0 || _rest$onPointerUp.call(rest, event);
1149
+ pointerStartRef.current = null;
1150
+ wasBeyondThePointRef.current = false;
1151
+ onRelease(event);
1152
+ },
1153
+ onPointerOut: (event) => {
1154
+ var _rest$onPointerOut;
1155
+ (_rest$onPointerOut = rest.onPointerOut) === null || _rest$onPointerOut === void 0 || _rest$onPointerOut.call(rest, event);
1156
+ handleOnPointerUp(lastKnownPointerEventRef.current);
1157
+ },
1158
+ onContextMenu: (event) => {
1159
+ var _rest$onContextMenu;
1160
+ (_rest$onContextMenu = rest.onContextMenu) === null || _rest$onContextMenu === void 0 || _rest$onContextMenu.call(rest, event);
1161
+ if (lastKnownPointerEventRef.current) handleOnPointerUp(lastKnownPointerEventRef.current);
1162
+ }
1163
+ }) });
1513
1164
  });
1514
- Content.displayName = 'Drawer.Content';
1165
+ Content.displayName = "Drawer.Content";
1515
1166
  const LONG_HANDLE_PRESS_TIMEOUT = 250;
1516
1167
  const DOUBLE_TAP_TIMEOUT = 120;
1517
- const Handle = /*#__PURE__*/ React__default.forwardRef(function({ preventCycle = false, children, ...rest }, ref) {
1518
- const { closeDrawer, isDragging, snapPoints, activeSnapPoint, setActiveSnapPoint, dismissible, handleOnly, isOpen, onPress, onDrag } = useDrawerContext();
1519
- const closeTimeoutIdRef = React__default.useRef(null);
1520
- const shouldCancelInteractionRef = React__default.useRef(false);
1521
- function handleStartCycle() {
1522
- // Stop if this is the second click of a double click
1523
- if (shouldCancelInteractionRef.current) {
1524
- handleCancelInteraction();
1525
- return;
1526
- }
1527
- window.setTimeout(()=>{
1528
- handleCycleSnapPoints();
1529
- }, DOUBLE_TAP_TIMEOUT);
1530
- }
1531
- function handleCycleSnapPoints() {
1532
- // Prevent accidental taps while resizing drawer
1533
- if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
1534
- handleCancelInteraction();
1535
- return;
1536
- }
1537
- // Make sure to clear the timeout id if the user releases the handle before the cancel timeout
1538
- handleCancelInteraction();
1539
- if (!snapPoints || snapPoints.length === 0) {
1540
- if (!dismissible) {
1541
- closeDrawer();
1542
- }
1543
- return;
1544
- }
1545
- const isLastSnapPoint = activeSnapPoint === snapPoints[snapPoints.length - 1];
1546
- if (isLastSnapPoint && dismissible) {
1547
- closeDrawer();
1548
- return;
1549
- }
1550
- const currentSnapIndex = snapPoints.findIndex((point)=>point === activeSnapPoint);
1551
- if (currentSnapIndex === -1) return; // activeSnapPoint not found in snapPoints
1552
- const nextSnapPoint = snapPoints[currentSnapIndex + 1];
1553
- setActiveSnapPoint(nextSnapPoint);
1554
- }
1555
- function handleStartInteraction() {
1556
- closeTimeoutIdRef.current = window.setTimeout(()=>{
1557
- // Cancel click interaction on a long press
1558
- shouldCancelInteractionRef.current = true;
1559
- }, LONG_HANDLE_PRESS_TIMEOUT);
1560
- }
1561
- function handleCancelInteraction() {
1562
- if (closeTimeoutIdRef.current) {
1563
- window.clearTimeout(closeTimeoutIdRef.current);
1564
- }
1565
- shouldCancelInteractionRef.current = false;
1566
- }
1567
- return /*#__PURE__*/ React__default.createElement("div", {
1568
- onClick: handleStartCycle,
1569
- onPointerCancel: handleCancelInteraction,
1570
- onPointerDown: (e)=>{
1571
- if (handleOnly) onPress({
1572
- ...e,
1573
- preventBaseUIHandler: ()=>{}
1574
- });
1575
- handleStartInteraction();
1576
- },
1577
- onPointerMove: (e)=>{
1578
- if (handleOnly) onDrag({
1579
- ...e,
1580
- preventBaseUIHandler: ()=>{}
1581
- });
1582
- },
1583
- // onPointerUp is already handled by the content component
1584
- ref: ref,
1585
- "data-vaul-drawer-visible": isOpen ? 'true' : 'false',
1586
- "data-vaul-handle": "",
1587
- "aria-hidden": "true",
1588
- ...rest
1589
- }, /*#__PURE__*/ React__default.createElement("span", {
1590
- "data-vaul-handle-hitarea": "",
1591
- "aria-hidden": "true"
1592
- }, children));
1168
+ const Handle = React.forwardRef(function({ preventCycle = false, children, ...rest }, ref) {
1169
+ const { closeDrawer, isDragging, snapPoints, activeSnapPoint, setActiveSnapPoint, dismissible, handleOnly, isOpen, onPress, onDrag } = useDrawerContext();
1170
+ const closeTimeoutIdRef = React.useRef(null);
1171
+ const shouldCancelInteractionRef = React.useRef(false);
1172
+ function handleStartCycle() {
1173
+ if (shouldCancelInteractionRef.current) {
1174
+ handleCancelInteraction();
1175
+ return;
1176
+ }
1177
+ window.setTimeout(() => {
1178
+ handleCycleSnapPoints();
1179
+ }, DOUBLE_TAP_TIMEOUT);
1180
+ }
1181
+ function handleCycleSnapPoints() {
1182
+ if (isDragging || preventCycle || shouldCancelInteractionRef.current) {
1183
+ handleCancelInteraction();
1184
+ return;
1185
+ }
1186
+ handleCancelInteraction();
1187
+ if (!snapPoints || snapPoints.length === 0) {
1188
+ if (!dismissible) closeDrawer();
1189
+ return;
1190
+ }
1191
+ if (activeSnapPoint === snapPoints[snapPoints.length - 1] && dismissible) {
1192
+ closeDrawer();
1193
+ return;
1194
+ }
1195
+ const currentSnapIndex = snapPoints.findIndex((point) => point === activeSnapPoint);
1196
+ if (currentSnapIndex === -1) return;
1197
+ const nextSnapPoint = snapPoints[currentSnapIndex + 1];
1198
+ setActiveSnapPoint(nextSnapPoint);
1199
+ }
1200
+ function handleStartInteraction() {
1201
+ closeTimeoutIdRef.current = window.setTimeout(() => {
1202
+ shouldCancelInteractionRef.current = true;
1203
+ }, LONG_HANDLE_PRESS_TIMEOUT);
1204
+ }
1205
+ function handleCancelInteraction() {
1206
+ if (closeTimeoutIdRef.current) window.clearTimeout(closeTimeoutIdRef.current);
1207
+ shouldCancelInteractionRef.current = false;
1208
+ }
1209
+ return /* @__PURE__ */ jsx("div", {
1210
+ onClick: handleStartCycle,
1211
+ onPointerCancel: handleCancelInteraction,
1212
+ onPointerDown: (e) => {
1213
+ if (handleOnly) onPress({
1214
+ ...e,
1215
+ preventBaseUIHandler: () => {}
1216
+ });
1217
+ handleStartInteraction();
1218
+ },
1219
+ onPointerMove: (e) => {
1220
+ if (handleOnly) onDrag({
1221
+ ...e,
1222
+ preventBaseUIHandler: () => {}
1223
+ });
1224
+ },
1225
+ ref,
1226
+ "data-vaul-drawer-visible": isOpen ? "true" : "false",
1227
+ "data-vaul-handle": "",
1228
+ "aria-hidden": "true",
1229
+ ...rest,
1230
+ children: /* @__PURE__ */ jsx("span", {
1231
+ "data-vaul-handle-hitarea": "",
1232
+ "aria-hidden": "true",
1233
+ children
1234
+ })
1235
+ });
1593
1236
  });
1594
- Handle.displayName = 'Drawer.Handle';
1237
+ Handle.displayName = "Drawer.Handle";
1595
1238
  function NestedRoot({ onDrag, onOpenChange, open: nestedIsOpen, ...rest }) {
1596
- const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();
1597
- if (!onNestedDrag) {
1598
- throw new Error('Drawer.NestedRoot must be placed in another drawer');
1599
- }
1600
- return /*#__PURE__*/ React__default.createElement(Root, {
1601
- nested: true,
1602
- open: nestedIsOpen,
1603
- onClose: ()=>{
1604
- onNestedOpenChange(false);
1605
- },
1606
- onDrag: (e, p)=>{
1607
- onNestedDrag(e, p);
1608
- onDrag == null ? void 0 : onDrag(e, p);
1609
- },
1610
- onOpenChange: (o)=>{
1611
- if (o) {
1612
- onNestedOpenChange(o);
1613
- }
1614
- onOpenChange == null ? void 0 : onOpenChange(o);
1615
- },
1616
- onRelease: onNestedRelease,
1617
- ...rest
1618
- });
1239
+ const { onNestedDrag, onNestedOpenChange, onNestedRelease } = useDrawerContext();
1240
+ if (!onNestedDrag) throw new Error("Drawer.NestedRoot must be placed in another drawer");
1241
+ return /* @__PURE__ */ jsx(Root, {
1242
+ nested: true,
1243
+ open: nestedIsOpen,
1244
+ onClose: () => {
1245
+ onNestedOpenChange(false);
1246
+ },
1247
+ onDrag: (e, p) => {
1248
+ onNestedDrag(e, p);
1249
+ onDrag === null || onDrag === void 0 || onDrag(e, p);
1250
+ },
1251
+ onOpenChange: (o) => {
1252
+ if (o) onNestedOpenChange(o);
1253
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(o);
1254
+ },
1255
+ onRelease: onNestedRelease,
1256
+ ...rest
1257
+ });
1619
1258
  }
1620
1259
  function Portal(props) {
1621
- const context = useDrawerContext();
1622
- const { container = context.container, ...portalProps } = props;
1623
- return /*#__PURE__*/ React__default.createElement(Dialog.Portal, {
1624
- container: container,
1625
- ...portalProps
1626
- });
1260
+ const context = useDrawerContext();
1261
+ const { container = context.container, ...portalProps } = props;
1262
+ return /* @__PURE__ */ jsx(Dialog.Portal, {
1263
+ container,
1264
+ ...portalProps
1265
+ });
1627
1266
  }
1628
1267
  const Drawer = {
1629
- Root,
1630
- NestedRoot,
1631
- Content,
1632
- Overlay,
1633
- Trigger: Dialog.Trigger,
1634
- Portal,
1635
- Handle,
1636
- Close: Dialog.Close,
1637
- Title: Dialog.Title,
1638
- Description: Dialog.Description
1268
+ Root,
1269
+ NestedRoot,
1270
+ Content,
1271
+ Overlay,
1272
+ Trigger: Dialog.Trigger,
1273
+ Portal,
1274
+ Handle,
1275
+ Close: Dialog.Close,
1276
+ Title: Dialog.Title,
1277
+ Description: Dialog.Description
1639
1278
  };
1640
1279
 
1280
+ //#endregion
1641
1281
  export { Content, Drawer, Handle, NestedRoot, Overlay, Portal, Root };
1282
+ //# sourceMappingURL=index.mjs.map