UNPKG

ivt

Version:

Ivt Components Library

1 lines 154 kB
{"version":3,"file":"index.mjs","sources":["../../node_modules/vaul/dist/index.mjs","../../src/components/ui/drawer/drawer.tsx"],"sourcesContent":["'use client';\nfunction __insertCSS(code) {\n if (!code || typeof document == 'undefined') return\n let head = document.head || document.getElementsByTagName('head')[0]\n let style = document.createElement('style')\n style.type = 'text/css'\n head.appendChild(style)\n ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))\n}\n\nimport * as DialogPrimitive from '@radix-ui/react-dialog';\nimport * as React from 'react';\nimport React__default, { useLayoutEffect, useEffect, useMemo } from 'react';\n\nconst DrawerContext = React__default.createContext({\n drawerRef: {\n current: null\n },\n overlayRef: {\n current: null\n },\n onPress: ()=>{},\n onRelease: ()=>{},\n onDrag: ()=>{},\n onNestedDrag: ()=>{},\n onNestedOpenChange: ()=>{},\n onNestedRelease: ()=>{},\n openProp: undefined,\n dismissible: false,\n isOpen: false,\n isDragging: false,\n keyboardIsOpen: {\n current: false\n },\n snapPointsOffset: null,\n snapPoints: null,\n handleOnly: false,\n modal: false,\n shouldFade: false,\n activeSnapPoint: null,\n onOpenChange: ()=>{},\n setActiveSnapPoint: ()=>{},\n closeDrawer: ()=>{},\n direction: 'bottom',\n shouldAnimate: {\n current: true\n },\n shouldScaleBackground: false,\n setBackgroundColorOnScale: true,\n noBodyStyles: false,\n container: null,\n autoFocus: false\n});\nconst useDrawerContext = ()=>{\n const context = React__default.useContext(DrawerContext);\n if (!context) {\n throw new Error('useDrawerContext must be used within a Drawer.Root');\n }\n return context;\n};\n\n__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-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=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-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=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(\\n[data-state=closed]\\n){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)}}\");\n\nfunction isMobileFirefox() {\n const userAgent = navigator.userAgent;\n return typeof window !== 'undefined' && (/Firefox/.test(userAgent) && /Mobile/.test(userAgent) || // Android Firefox\n /FxiOS/.test(userAgent) // iOS Firefox\n );\n}\nfunction isMac() {\n return testPlatform(/^Mac/);\n}\nfunction isIPhone() {\n return testPlatform(/^iPhone/);\n}\nfunction isSafari() {\n return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n}\nfunction isIPad() {\n return testPlatform(/^iPad/) || // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.\n isMac() && navigator.maxTouchPoints > 1;\n}\nfunction isIOS() {\n return isIPhone() || isIPad();\n}\nfunction testPlatform(re) {\n return typeof window !== 'undefined' && window.navigator != null ? re.test(window.navigator.platform) : undefined;\n}\n\n// This code comes from https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/usePreventScroll.ts\nconst KEYBOARD_BUFFER = 24;\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\nfunction chain$1(...callbacks) {\n return (...args)=>{\n for (let callback of callbacks){\n if (typeof callback === 'function') {\n callback(...args);\n }\n }\n };\n}\n// @ts-ignore\nconst visualViewport = typeof document !== 'undefined' && window.visualViewport;\nfunction isScrollable(node) {\n let style = window.getComputedStyle(node);\n return /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);\n}\nfunction getScrollParent(node) {\n if (isScrollable(node)) {\n node = node.parentElement;\n }\n while(node && !isScrollable(node)){\n node = node.parentElement;\n }\n return node || document.scrollingElement || document.documentElement;\n}\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore;\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */ function usePreventScroll(options = {}) {\n let { isDisabled } = options;\n useIsomorphicLayoutEffect(()=>{\n if (isDisabled) {\n return;\n }\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n }\n }\n return ()=>{\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore == null ? void 0 : restore();\n }\n };\n }, [\n isDisabled\n ]);\n}\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Prevent default on `touchmove` events inside a scrollable element when the scroll position is at the\n// top or bottom. This avoids the whole page scrolling instead, but does prevent overscrolling.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable;\n let lastY = 0;\n let onTouchStart = (e)=>{\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target);\n if (scrollable === document.documentElement && scrollable === document.body) {\n return;\n }\n lastY = e.changedTouches[0].pageY;\n };\n let onTouchMove = (e)=>{\n // Prevent scrolling the window.\n if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {\n e.preventDefault();\n return;\n }\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead. Unfortunately, this disables bounce scrolling when at\n // the top but it's the best we can do.\n let y = e.changedTouches[0].pageY;\n let scrollTop = scrollable.scrollTop;\n let bottom = scrollable.scrollHeight - scrollable.clientHeight;\n if (bottom === 0) {\n return;\n }\n if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {\n e.preventDefault();\n }\n lastY = y;\n };\n let onTouchEnd = (e)=>{\n let target = e.target;\n // Apply this change if we're not already focused on the target element\n if (isInput(target) && target !== document.activeElement) {\n e.preventDefault();\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(()=>{\n target.style.transform = '';\n });\n }\n };\n let onFocus = (e)=>{\n let target = e.target;\n if (isInput(target)) {\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(()=>{\n target.style.transform = '';\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(()=>{\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener('resize', ()=>scrollIntoView(target), {\n once: true\n });\n }\n }\n });\n }\n };\n let onWindowScroll = ()=>{\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n let restoreStyles = chain$1(setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`));\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n let removeEvents = chain$1(addEvent(document, 'touchstart', onTouchStart, {\n passive: false,\n capture: true\n }), addEvent(document, 'touchmove', onTouchMove, {\n passive: false,\n capture: true\n }), addEvent(document, 'touchend', onTouchEnd, {\n passive: false,\n capture: true\n }), addEvent(document, 'focus', onFocus, true), addEvent(window, 'scroll', onWindowScroll));\n return ()=>{\n // Restore styles and scroll the page back to where it was.\n restoreStyles();\n removeEvents();\n window.scrollTo(scrollX, scrollY);\n };\n}\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element, style, value) {\n // https://github.com/microsoft/TypeScript/issues/17827#issuecomment-391663310\n // @ts-ignore\n let cur = element.style[style];\n // @ts-ignore\n element.style[style] = value;\n return ()=>{\n // @ts-ignore\n element.style[style] = cur;\n };\n}\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent(target, event, handler, options) {\n // @ts-ignore\n target.addEventListener(event, handler, options);\n return ()=>{\n // @ts-ignore\n target.removeEventListener(event, handler, options);\n };\n}\nfunction scrollIntoView(target) {\n let root = document.scrollingElement || document.documentElement;\n while(target && target !== root){\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n let targetBottom = target.getBoundingClientRect().bottom;\n // Buffer is needed for some edge cases\n const keyboardHeight = scrollable.getBoundingClientRect().bottom + KEYBOARD_BUFFER;\n if (targetBottom > keyboardHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n // @ts-ignore\n target = scrollable.parentElement;\n }\n}\nfunction isInput(target) {\n return target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;\n}\n\n// This code comes from https://github.com/radix-ui/primitives/tree/main/packages/react/compose-refs\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and RefObject(s)\n */ function setRef(ref, value) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref !== null && ref !== undefined) {\n ref.current = value;\n }\n}\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and RefObject(s)\n */ function composeRefs(...refs) {\n return (node)=>refs.forEach((ref)=>setRef(ref, node));\n}\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and RefObject(s)\n */ function useComposedRefs(...refs) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(composeRefs(...refs), refs);\n}\n\nconst cache = new WeakMap();\nfunction set(el, styles, ignoreCache = false) {\n if (!el || !(el instanceof HTMLElement)) return;\n let originalStyles = {};\n Object.entries(styles).forEach(([key, value])=>{\n if (key.startsWith('--')) {\n el.style.setProperty(key, value);\n return;\n }\n originalStyles[key] = el.style[key];\n el.style[key] = value;\n });\n if (ignoreCache) return;\n cache.set(el, originalStyles);\n}\nfunction reset(el, prop) {\n if (!el || !(el instanceof HTMLElement)) return;\n let originalStyles = cache.get(el);\n if (!originalStyles) {\n return;\n }\n {\n el.style[prop] = originalStyles[prop];\n }\n}\nconst isVertical = (direction)=>{\n switch(direction){\n case 'top':\n case 'bottom':\n return true;\n case 'left':\n case 'right':\n return false;\n default:\n return direction;\n }\n};\nfunction getTranslate(element, direction) {\n if (!element) {\n return null;\n }\n const style = window.getComputedStyle(element);\n const transform = // @ts-ignore\n style.transform || style.webkitTransform || style.mozTransform;\n let mat = transform.match(/^matrix3d\\((.+)\\)$/);\n if (mat) {\n // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix3d\n return parseFloat(mat[1].split(', ')[isVertical(direction) ? 13 : 12]);\n }\n // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix\n mat = transform.match(/^matrix\\((.+)\\)$/);\n return mat ? parseFloat(mat[1].split(', ')[isVertical(direction) ? 5 : 4]) : null;\n}\nfunction dampenValue(v) {\n return 8 * (Math.log(v + 1) - 2);\n}\nfunction assignStyle(element, style) {\n if (!element) return ()=>{};\n const prevStyle = element.style.cssText;\n Object.assign(element.style, style);\n return ()=>{\n element.style.cssText = prevStyle;\n };\n}\n/**\n * Receives functions as arguments and returns a new function that calls all.\n */ function chain(...fns) {\n return (...args)=>{\n for (const fn of fns){\n if (typeof fn === 'function') {\n // @ts-ignore\n fn(...args);\n }\n }\n };\n}\n\nconst TRANSITIONS = {\n DURATION: 0.5,\n EASE: [\n 0.32,\n 0.72,\n 0,\n 1\n ]\n};\nconst VELOCITY_THRESHOLD = 0.4;\nconst CLOSE_THRESHOLD = 0.25;\nconst SCROLL_LOCK_TIMEOUT = 100;\nconst BORDER_RADIUS = 8;\nconst NESTED_DISPLACEMENT = 16;\nconst WINDOW_TOP_OFFSET = 26;\nconst DRAG_CLASS = 'vaul-dragging';\n\n// This code comes from https://github.com/radix-ui/primitives/blob/main/packages/react/use-controllable-state/src/useControllableState.tsx\nfunction useCallbackRef(callback) {\n const callbackRef = React__default.useRef(callback);\n React__default.useEffect(()=>{\n callbackRef.current = callback;\n });\n // https://github.com/facebook/react/issues/19240\n return React__default.useMemo(()=>(...args)=>callbackRef.current == null ? void 0 : callbackRef.current.call(callbackRef, ...args), []);\n}\nfunction useUncontrolledState({ defaultProp, onChange }) {\n const uncontrolledState = React__default.useState(defaultProp);\n const [value] = uncontrolledState;\n const prevValueRef = React__default.useRef(value);\n const handleChange = useCallbackRef(onChange);\n React__default.useEffect(()=>{\n if (prevValueRef.current !== value) {\n handleChange(value);\n prevValueRef.current = value;\n }\n }, [\n value,\n prevValueRef,\n handleChange\n ]);\n return uncontrolledState;\n}\nfunction useControllableState({ prop, defaultProp, onChange = ()=>{} }) {\n const [uncontrolledProp, setUncontrolledProp] = useUncontrolledState({\n defaultProp,\n onChange\n });\n const isControlled = prop !== undefined;\n const value = isControlled ? prop : uncontrolledProp;\n const handleChange = useCallbackRef(onChange);\n const setValue = React__default.useCallback((nextValue)=>{\n if (isControlled) {\n const setter = nextValue;\n const value = typeof nextValue === 'function' ? setter(prop) : nextValue;\n if (value !== prop) handleChange(value);\n } else {\n setUncontrolledProp(nextValue);\n }\n }, [\n isControlled,\n prop,\n setUncontrolledProp,\n handleChange\n ]);\n return [\n value,\n setValue\n ];\n}\n\nfunction useSnapPoints({ activeSnapPointProp, setActiveSnapPointProp, snapPoints, drawerRef, overlayRef, fadeFromIndex, onSnapPointChange, direction = 'bottom', container, snapToSequentialPoint }) {\n const [activeSnapPoint, setActiveSnapPoint] = useControllableState({\n prop: activeSnapPointProp,\n defaultProp: snapPoints == null ? void 0 : snapPoints[0],\n onChange: setActiveSnapPointProp\n });\n const [windowDimensions, setWindowDimensions] = React__default.useState(typeof window !== 'undefined' ? {\n innerWidth: window.innerWidth,\n innerHeight: window.innerHeight\n } : undefined);\n React__default.useEffect(()=>{\n function onResize() {\n setWindowDimensions({\n innerWidth: window.innerWidth,\n innerHeight: window.innerHeight\n });\n }\n window.addEventListener('resize', onResize);\n return ()=>window.removeEventListener('resize', onResize);\n }, []);\n const isLastSnapPoint = React__default.useMemo(()=>activeSnapPoint === (snapPoints == null ? void 0 : snapPoints[snapPoints.length - 1]) || null, [\n snapPoints,\n activeSnapPoint\n ]);\n const activeSnapPointIndex = React__default.useMemo(()=>{\n var _snapPoints_findIndex;\n return (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : null;\n }, [\n snapPoints,\n activeSnapPoint\n ]);\n const shouldFade = snapPoints && snapPoints.length > 0 && (fadeFromIndex || fadeFromIndex === 0) && !Number.isNaN(fadeFromIndex) && snapPoints[fadeFromIndex] === activeSnapPoint || !snapPoints;\n const snapPointsOffset = React__default.useMemo(()=>{\n const containerSize = container ? {\n width: container.getBoundingClientRect().width,\n height: container.getBoundingClientRect().height\n } : typeof window !== 'undefined' ? {\n width: window.innerWidth,\n height: window.innerHeight\n } : {\n width: 0,\n height: 0\n };\n var _snapPoints_map;\n return (_snapPoints_map = snapPoints == null ? void 0 : snapPoints.map((snapPoint)=>{\n const isPx = typeof snapPoint === 'string';\n let snapPointAsNumber = 0;\n if (isPx) {\n snapPointAsNumber = parseInt(snapPoint, 10);\n }\n if (isVertical(direction)) {\n const height = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.height : 0;\n if (windowDimensions) {\n return direction === 'bottom' ? containerSize.height - height : -containerSize.height + height;\n }\n return height;\n }\n const width = isPx ? snapPointAsNumber : windowDimensions ? snapPoint * containerSize.width : 0;\n if (windowDimensions) {\n return direction === 'right' ? containerSize.width - width : -containerSize.width + width;\n }\n return width;\n })) != null ? _snapPoints_map : [];\n }, [\n snapPoints,\n windowDimensions,\n container\n ]);\n const activeSnapPointOffset = React__default.useMemo(()=>activeSnapPointIndex !== null ? snapPointsOffset == null ? void 0 : snapPointsOffset[activeSnapPointIndex] : null, [\n snapPointsOffset,\n activeSnapPointIndex\n ]);\n const snapToPoint = React__default.useCallback((dimension)=>{\n var _snapPointsOffset_findIndex;\n const newSnapPointIndex = (_snapPointsOffset_findIndex = snapPointsOffset == null ? void 0 : snapPointsOffset.findIndex((snapPointDim)=>snapPointDim === dimension)) != null ? _snapPointsOffset_findIndex : null;\n onSnapPointChange(newSnapPointIndex);\n set(drawerRef.current, {\n transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,\n transform: isVertical(direction) ? `translate3d(0, ${dimension}px, 0)` : `translate3d(${dimension}px, 0, 0)`\n });\n if (snapPointsOffset && newSnapPointIndex !== snapPointsOffset.length - 1 && fadeFromIndex !== undefined && newSnapPointIndex !== fadeFromIndex && newSnapPointIndex < fadeFromIndex) {\n set(overlayRef.current, {\n transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,\n opacity: '0'\n });\n } else {\n set(overlayRef.current, {\n transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`,\n opacity: '1'\n });\n }\n setActiveSnapPoint(snapPoints == null ? void 0 : snapPoints[Math.max(newSnapPointIndex, 0)]);\n }, [\n drawerRef.current,\n snapPoints,\n snapPointsOffset,\n fadeFromIndex,\n overlayRef,\n setActiveSnapPoint\n ]);\n React__default.useEffect(()=>{\n if (activeSnapPoint || activeSnapPointProp) {\n var _snapPoints_findIndex;\n const newIndex = (_snapPoints_findIndex = snapPoints == null ? void 0 : snapPoints.findIndex((snapPoint)=>snapPoint === activeSnapPointProp || snapPoint === activeSnapPoint)) != null ? _snapPoints_findIndex : -1;\n if (snapPointsOffset && newIndex !== -1 && typeof snapPointsOffset[newIndex] === 'number') {\n snapToPoint(snapPointsOffset[newIndex]);\n }\n }\n }, [\n activeSnapPoint,\n activeSnapPointProp,\n snapPoints,\n snapPointsOffset,\n snapToPoint\n ]);\n function onRelease({ draggedDistance, closeDrawer, velocity, dismissible }) {\n if (fadeFromIndex === undefined) return;\n const currentPosition = direction === 'bottom' || direction === 'right' ? (activeSnapPointOffset != null ? activeSnapPointOffset : 0) - draggedDistance : (activeSnapPointOffset != null ? activeSnapPointOffset : 0) + draggedDistance;\n const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;\n const isFirst = activeSnapPointIndex === 0;\n const hasDraggedUp = draggedDistance > 0;\n if (isOverlaySnapPoint) {\n set(overlayRef.current, {\n transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(',')})`\n });\n }\n if (!snapToSequentialPoint && velocity > 2 && !hasDraggedUp) {\n if (dismissible) closeDrawer();\n else snapToPoint(snapPointsOffset[0]); // snap to initial point\n return;\n }\n if (!snapToSequentialPoint && velocity > 2 && hasDraggedUp && snapPointsOffset && snapPoints) {\n snapToPoint(snapPointsOffset[snapPoints.length - 1]);\n return;\n }\n // Find the closest snap point to the current position\n const closestSnapPoint = snapPointsOffset == null ? void 0 : snapPointsOffset.reduce((prev, curr)=>{\n if (typeof prev !== 'number' || typeof curr !== 'number') return prev;\n return Math.abs(curr - currentPosition) < Math.abs(prev - currentPosition) ? curr : prev;\n });\n const dim = isVertical(direction) ? window.innerHeight : window.innerWidth;\n if (velocity > VELOCITY_THRESHOLD && Math.abs(draggedDistance) < dim * 0.4) {\n const dragDirection = hasDraggedUp ? 1 : -1; // 1 = up, -1 = down\n // Don't do anything if we swipe upwards while being on the last snap point\n if (dragDirection > 0 && isLastSnapPoint && snapPoints) {\n snapToPoint(snapPointsOffset[snapPoints.length - 1]);\n return;\n }\n if (isFirst && dragDirection < 0 && dismissible) {\n closeDrawer();\n }\n if (activeSnapPointIndex === null) return;\n snapToPoint(snapPointsOffset[activeSnapPointIndex + dragDirection]);\n return;\n }\n snapToPoint(closestSnapPoint);\n }\n function onDrag({ draggedDistance }) {\n if (activeSnapPointOffset === null) return;\n const newValue = direction === 'bottom' || direction === 'right' ? activeSnapPointOffset - draggedDistance : activeSnapPointOffset + draggedDistance;\n // Don't do anything if we exceed the last(biggest) snap point\n if ((direction === 'bottom' || direction === 'right') && newValue < snapPointsOffset[snapPointsOffset.length - 1]) {\n return;\n }\n if ((direction === 'top' || direction === 'left') && newValue > snapPointsOffset[snapPointsOffset.length - 1]) {\n return;\n }\n set(drawerRef.current, {\n transform: isVertical(direction) ? `translate3d(0, ${newValue}px, 0)` : `translate3d(${newValue}px, 0, 0)`\n });\n }\n function getPercentageDragged(absDraggedDistance, isDraggingDown) {\n if (!snapPoints || typeof activeSnapPointIndex !== 'number' || !snapPointsOffset || fadeFromIndex === undefined) return null;\n // If this is true we are dragging to a snap point that is supposed to have an overlay\n const isOverlaySnapPoint = activeSnapPointIndex === fadeFromIndex - 1;\n const isOverlaySnapPointOrHigher = activeSnapPointIndex >= fadeFromIndex;\n if (isOverlaySnapPointOrHigher && isDraggingDown) {\n return 0;\n }\n // Don't animate, but still use this one if we are dragging away from the overlaySnapPoint\n if (isOverlaySnapPoint && !isDraggingDown) return 1;\n if (!shouldFade && !isOverlaySnapPoint) return null;\n // Either fadeFrom index or the one before\n const targetSnapPointIndex = isOverlaySnapPoint ? activeSnapPointIndex + 1 : activeSnapPointIndex - 1;\n // Get the distance from overlaySnapPoint to the one before or vice-versa to calculate the opacity percentage accordingly\n const snapPointDistance = isOverlaySnapPoint ? snapPointsOffset[targetSnapPointIndex] - snapPointsOffset[targetSnapPointIndex - 1] : snapPointsOffset[targetSnapPointIndex + 1] - snapPointsOffset[targetSnapPointIndex];\n const percentageDragged = absDraggedDistance / Math.abs(snapPointDistance);\n if (isOverlaySnapPoint) {\n return 1 - percentageDragged;\n } else {\n return percentageDragged;\n }\n }\n return {\n isLastSnapPoint,\n activeSnapPoint,\n shouldFade,\n getPercentageDragged,\n setActiveSnapPoint,\n activeSnapPointIndex,\n onRelease,\n onDrag,\n snapPointsOffset\n };\n}\n\nconst noop = ()=>()=>{};\nfunction useScaleBackground() {\n const { direction, isOpen, shouldScaleBackground, setBackgroundColorOnScale, noBodyStyles } = useDrawerContext();\n const timeoutIdRef = React__default.useRef(null);\n const initialBackgroundColor = useMemo(()=>document.body.style.backgroundColor, []);\n function getScale() {\n return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;\n }\n React__default.useEffect(()=>{\n if (isOpen && shouldScaleBackground) {\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n const wrapper = document.querySelector('[data-vaul-drawer-wrapper]') || document.querySelector('[vaul-drawer-wrapper]');\n if (!wrapper) return;\n chain(setBackgroundColorOnScale && !noBodyStyles ? assignStyle(document.body, {\n background: 'black'\n }) : noop, assignStyle(wrapper, {\n transformOrigin: isVertical(direction) ? 'top' : 'left',\n transitionProperty: 'transform, border-radius',\n transitionDuration: `${TRANSITIONS.DURATION}s`,\n transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(',')})`\n }));\n const wrapperStylesCleanup = assignStyle(wrapper, {\n borderRadius: `${BORDER_RADIUS}px`,\n overflow: 'hidden',\n ...isVertical(direction) ? {\n transform: `scale(${getScale()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`\n } : {\n transform: `scale(${getScale()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`\n }\n });\n return ()=>{\n wrapperStylesCleanup();\n timeoutIdRef.current = window.setTimeout(()=>{\n if (initialBackgroundColor) {\n document.body.style.background = initialBackgroundColor;\n } else {\n document.body.style.removeProperty('background');\n }\n }, TRANSITIONS.DURATION * 1000);\n };\n }\n }, [\n isOpen,\n shouldScaleBackground,\n initialBackgroundColor\n ]);\n}\n\nlet previousBodyPosition = null;\n/**\n * This hook is necessary to prevent buggy behavior on iOS devices (need to test on Android).\n * 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.\n * Issues that this hook solves:\n * https://github.com/emilkowalski/vaul/issues/435\n * https://github.com/emilkowalski/vaul/issues/433\n * And more that I discovered, but were just not reported.\n */ function usePositionFixed({ isOpen, modal, nested, hasBeenOpened, preventScrollRestoration, noBodyStyles }) {\n const [activeUrl, setActiveUrl] = React__default.useState(()=>typeof window !== 'undefined' ? window.location.href : '');\n const scrollPos = React__default.useRef(0);\n const setPositionFixed = React__default.useCallback(()=>{\n // All browsers on iOS will return true here.\n if (!isSafari()) return;\n // If previousBodyPosition is already set, don't set it again.\n if (previousBodyPosition === null && isOpen && !noBodyStyles) {\n previousBodyPosition = {\n position: document.body.style.position,\n top: document.body.style.top,\n left: document.body.style.left,\n height: document.body.style.height,\n right: 'unset'\n };\n // Update the dom inside an animation frame\n const { scrollX, innerHeight } = window;\n document.body.style.setProperty('position', 'fixed', 'important');\n Object.assign(document.body.style, {\n top: `${-scrollPos.current}px`,\n left: `${-scrollX}px`,\n right: '0px',\n height: 'auto'\n });\n window.setTimeout(()=>window.requestAnimationFrame(()=>{\n // Attempt to check if the bottom bar appeared due to the position change\n const bottomBarHeight = innerHeight - window.innerHeight;\n if (bottomBarHeight && scrollPos.current >= innerHeight) {\n // Move the content further up so that the bottom bar doesn't hide it\n document.body.style.top = `${-(scrollPos.current + bottomBarHeight)}px`;\n }\n }), 300);\n }\n }, [\n isOpen\n ]);\n const restorePositionSetting = React__default.useCallback(()=>{\n // All browsers on iOS will return true here.\n if (!isSafari()) return;\n if (previousBodyPosition !== null && !noBodyStyles) {\n // Convert the position from \"px\" to Int\n const y = -parseInt(document.body.style.top, 10);\n const x = -parseInt(document.body.style.left, 10);\n // Restore styles\n Object.assign(document.body.style, previousBodyPosition);\n window.requestAnimationFrame(()=>{\n if (preventScrollRestoration && activeUrl !== window.location.href) {\n setActiveUrl(window.location.href);\n return;\n }\n window.scrollTo(x, y);\n });\n previousBodyPosition = null;\n }\n }, [\n activeUrl\n ]);\n React__default.useEffect(()=>{\n function onScroll() {\n scrollPos.current = window.scrollY;\n }\n onScroll();\n window.addEventListener('scroll', onScroll);\n return ()=>{\n window.removeEventListener('scroll', onScroll);\n };\n }, []);\n React__default.useEffect(()=>{\n if (!modal) return;\n return ()=>{\n if (typeof document === 'undefined') return;\n // Another drawer is opened, safe to ignore the execution\n const hasDrawerOpened = !!document.querySelector('[data-vaul-drawer]');\n if (hasDrawerOpened) return;\n restorePositionSetting();\n };\n }, [\n modal,\n restorePositionSetting\n ]);\n React__default.useEffect(()=>{\n if (nested || !hasBeenOpened) return;\n // This is needed to force Safari toolbar to show **before** the drawer starts animating to prevent a gnarly shift from happening\n if (isOpen) {\n // avoid for standalone mode (PWA)\n const isStandalone = window.matchMedia('(display-mode: standalone)').matches;\n !isStandalone && setPositionFixed();\n if (!modal) {\n window.setTimeout(()=>{\n restorePositionSetting();\n }, 500);\n }\n } else {\n restorePositionSetting();\n }\n }, [\n isOpen,\n hasBeenOpened,\n activeUrl,\n modal,\n nested,\n setPositionFixed,\n restorePositionSetting\n ]);\n return {\n restorePositionSetting\n };\n}\n\nfunction 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 }) {\n var _drawerRef_current, _drawerRef_current1;\n const [isOpen = false, setIsOpen] = useControllableState({\n defaultProp: defaultOpen,\n prop: openProp,\n onChange: (o)=>{\n onOpenChange == null ? void 0 : onOpenChange(o);\n if (!o && !nested) {\n restorePositionSetting();\n }\n setTimeout(()=>{\n onAnimationEnd == null ? void 0 : onAnimationEnd(o);\n }, TRANSITIONS.DURATION * 1000);\n if (o && !modal) {\n if (typeof window !== 'undefined') {\n window.requestAnimationFrame(()=>{\n document.body.style.pointerEvents = 'auto';\n });\n }\n }\n if (!o) {\n // This will be removed when the exit animation ends (`500ms`)\n document.body.style.pointerEvents = 'auto';\n }\n }\n });\n const [hasBeenOpened, setHasBeenOpened] = React__default.useState(false);\n const [isDragging, setIsDragging] = React__default.useState(false);\n const [justReleased, setJustReleased] = React__default.useState(false);\n const overlayRef = React__default.useRef(null);\n const openTime = React__default.useRef(null);\n const dragStartTime = React__default.useRef(null);\n const dragEndTime = React__default.useRef(null);\n const lastTimeDragPrevented = React__default.useRef(null);\n const isAllowedToDrag = React__default.useRef(false);\n const nestedOpenChangeTimer = React__default.useRef(null);\n const pointerStart = React__default.useRef(0);\n const keyboardIsOpen = React__default.useRef(false);\n const shouldAnimate = React__default.useRef(!defaultOpen);\n const previousDiffFromInitial = React__default.useRef(0);\n const drawerRef = React__default.useRef(null);\n const drawerHeightRef = React__default.useRef(((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0);\n const drawerWidthRef = React__default.useRef(((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0);\n const initialDrawerHeight = React__default.useRef(0);\n const onSnapPointChange = React__default.useCallback((activeSnapPointIndex)=>{\n // Change openTime ref when we reach the last snap point to prevent dragging for 500ms incase it's scrollable.\n if (snapPoints && activeSnapPointIndex === snapPointsOffset.length - 1) openTime.current = new Date();\n }, []);\n const { activeSnapPoint, activeSnapPointIndex, setActiveSnapPoint, onRelease: onReleaseSnapPoints, snapPointsOffset, onDrag: onDragSnapPoints, shouldFade, getPercentageDragged: getSnapPointsPercentageDragged } = useSnapPoints({\n snapPoints,\n activeSnapPointProp,\n setActiveSnapPointProp,\n drawerRef,\n fadeFromIndex,\n overlayRef,\n onSnapPointChange,\n direction,\n container,\n snapToSequentialPoint\n });\n usePreventScroll({\n isDisabled: !isOpen || isDragging || !modal || justReleased || !hasBeenOpened || !repositionInputs || !disablePreventScroll\n });\n const { restorePositionSetting } = usePositionFixed({\n isOpen,\n modal,\n nested: nested != null ? nested : false,\n hasBeenOpened,\n preventScrollRestoration,\n noBodyStyles\n });\n function getScale() {\n return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;\n }\n function onPress(event) {\n var _drawerRef_current, _drawerRef_current1;\n if (!dismissible && !snapPoints) return;\n if (drawerRef.current && !drawerRef.current.contains(event.target)) return;\n drawerHeightRef.current = ((_drawerRef_current = drawerRef.current) == null ? void 0 : _drawerRef_current.getBoundingClientRect().height) || 0;\n drawerWidthRef.current = ((_drawerRef_current1 = drawerRef.current) == null ? void 0 : _drawerRef_current1.getBoundingClientRect().width) || 0;\n setIsDragging(true);\n dragStartTime.current = new Date();\n // iOS doesn't trigger mouseUp after scrolling so we need to listen to touched in order to disallow dragging\n if (isIOS()) {\n window.addEventListener('touchend', ()=>isAllowedToDrag.current = false, {\n once: true\n });\n }\n // Ensure we maintain correct pointer capture even when going outside of the drawer\n event.target.setPointerCapture(event.pointerId);\n pointerStart.current = isVertical(direction) ? event.pageY : event.pageX;\n }\n function shouldDrag(el, isDraggingInDirection) {\n var _window_getSelection;\n let element = el;\n const highlightedText = (_window_getSelection = window.getSelection()) == null ? void 0 : _window_getSelection.toString();\n const swipeAmount = drawerRef.current ? getTranslate(drawerRef.current, direction) : null;\n const date = new Date();\n // Fixes https://github.com/emilkowalski/vaul/issues/483\n if (element.tagName === 'SELECT') {\n return false;\n }\n if (element.hasAttribute('data-vaul-no-drag') || element.closest('[data-vaul-no-drag]')) {\n return false;\n }\n if (direction === 'right' || direction === 'left') {\n return true;\n }\n // Allow scrolling when animating\n if (openTime.current && date.getTime() - openTime.current.getTime() < 500) {\n return false;\n }\n if (swipeAmount !== null) {\n if (direction === 'bottom' ? swipeAmount > 0 : swipeAmount < 0) {\n return true;\n }\n }\n // Don't drag if there's highlighted text\n if (highlightedText && highlightedText.length > 0) {\n return false;\n }\n // Disallow dragging if drawer was scrolled within `scrollLockTimeout`\n if (lastTimeDragPrevented.current && date.getTime() - lastTimeDragPrevented.current.getTime() < scrollLockTimeout && swipeAmount === 0) {\n