ivt 0.4.5 → 0.4.7

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