Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-spring-bottom-sheet-updated

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-spring-bottom-sheet-updated - npm Package Compare versions

Comparing version 3.5.3 to 3.5.4

2

dist/index.es.js

@@ -1,2 +0,2 @@

import*as e from"@radix-ui/react-portal";import n,{useRef as r,useDebugValue as t,useEffect as o,useLayoutEffect as i,useState as a,useCallback as c,useMemo as u,useImperativeHandle as s,forwardRef as l}from"react";import{useMachine as d}from"@xstate/react";import{useSpring as f,to as v,animated as m,config as p}from"react-spring";import{useDrag as y,rubberbandIfOutOfBounds as h}from"react-use-gesture";import{createFocusTrap as g}from"focus-trap";import{disableBodyScroll as S,enableBodyScroll as E}from"body-scroll-lock";import{ResizeObserver as P}from"@juggle/resize-observer";import{Machine as b,assign as R}from"xstate";function x(){return x=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},x.apply(this,arguments)}function O(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)n.indexOf(r=i[t])>=0||(o[r]=e[r]);return o}var C="undefined"!=typeof window?i:o;function N(e,n,r){return n=(n=+n)==n?n:0,r=(r=+r)==r?r:0,(e=+e)==e&&(e=(e=e<=r?e:r)>=n?e:n),e}function w(e){var n=Math.round(e);if(Number.isNaN(e))throw new TypeError("Found a NaN! Check your snapPoints / defaultSnap / snapTo ");return n}var H={box:"border-box"};function D(e,n){var r=n.label,o=n.enabled,i=n.resizeSourceRef,u=a(0),s=u[0],l=u[1];t(r+": "+s);var d=c(function(e){l(e[0].borderBoxSize[0].blockSize),i.current="element"},[i]);return C(function(){if(e.current&&o){var n=new P(d);return n.observe(e.current,H),function(){n.disconnect()}}},[e,d,o]),o?s:0}function k(e){return void 0===e&&(e=1e3),new Promise(function(n){return setTimeout(n,e)})}var j={DRAG:{target:"#overlay.dragging",actions:"onOpenEnd"}},z={RESIZE:{target:"#overlay.resizing",actions:"onOpenEnd"}},A=b({id:"overlay",initial:"closed",context:{initialState:"CLOSED"},states:{closed:{on:{OPEN:"opening",CLOSE:void 0}},opening:{initial:"start",states:{start:{invoke:{src:"onOpenStart",onDone:"transition"}},transition:{always:[{target:"immediately",cond:"initiallyOpen"},{target:"smoothly",cond:"initiallyClosed"}]},immediately:{initial:"open",states:{open:{invoke:{src:"openImmediately",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"#overlay.opening.end"},on:x({},j,z)}}},smoothly:{initial:"visuallyHidden",states:{visuallyHidden:{invoke:{src:"renderVisuallyHidden",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"open"}},open:{invoke:{src:"openSmoothly",onDone:"#overlay.opening.end"},on:x({},j,z)}}},end:{invoke:{src:"onOpenEnd",onDone:"done"},on:{CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:x({},{CLOSE:{target:"#overlay.closing",actions:"onOpenCancel"}}),onDone:"open"},open:{on:{DRAG:"#overlay.dragging",SNAP:"snapping",RESIZE:"resizing"}},dragging:{on:{SNAP:"snapping"}},snapping:{initial:"start",states:{start:{invoke:{src:"onSnapStart",onDone:"snappingSmoothly"},entry:[R({y:function(e,n){return n.payload.y},velocity:function(e,n){return n.payload.velocity},snapSource:function(e,n){var r=n.payload.source;return void 0===r?"custom":r}})]},snappingSmoothly:{invoke:{src:"snapSmoothly",onDone:"end"}},end:{invoke:{src:"onSnapEnd",onDone:"done"},on:{RESIZE:"#overlay.resizing",SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{SNAP:{target:"snapping",actions:"onSnapEnd"},RESIZE:{target:"#overlay.resizing",actions:"onSnapCancel"},DRAG:{target:"#overlay.dragging",actions:"onSnapCancel"},CLOSE:{target:"#overlay.closing",actions:"onSnapCancel"}},onDone:"open"},resizing:{initial:"start",states:{start:{invoke:{src:"onResizeStart",onDone:"resizingSmoothly"}},resizingSmoothly:{invoke:{src:"resizeSmoothly",onDone:"end"}},end:{invoke:{src:"onResizeEnd",onDone:"done"},on:{SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{RESIZE:{target:"resizing",actions:"onResizeEnd"},SNAP:{target:"snapping",actions:"onResizeCancel"},DRAG:{target:"#overlay.dragging",actions:"onResizeCancel"},CLOSE:{target:"#overlay.closing",actions:"onResizeCancel"}},onDone:"open"},closing:{initial:"start",states:{start:{invoke:{src:"onCloseStart",onDone:"deactivating"},on:{OPEN:{target:"#overlay.open",actions:"onCloseCancel"}}},deactivating:{invoke:{src:"deactivate",onDone:"closingSmoothly"}},closingSmoothly:{invoke:{src:"closeSmoothly",onDone:"end"}},end:{invoke:{src:"onCloseEnd",onDone:"done"},on:{OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}}},done:{type:"final"}},on:{CLOSE:void 0,OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}},onDone:"closed"}},on:{CLOSE:"closing"}},{actions:{onOpenCancel:function(e,n){},onSnapCancel:function(e,n){},onResizeCancel:function(e,n){},onCloseCancel:function(e,n){},onOpenEnd:function(e,n){},onSnapEnd:function(e,n){},onResizeEnd:function(e,n){}},services:{onSnapStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onSnapEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},renderVisuallyHidden:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},activate:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},deactivate:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},openSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},openImmediately:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},snapSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},resizeSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},closeSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}}},guards:{initiallyClosed:function(e){return"CLOSED"===e.initialState},initiallyOpen:function(e){return"OPEN"===e.initialState}}}),L=["children","sibling","className","footer","header","open","initialState","lastSnapRef","initialFocusRef","onDismiss","maxHeight","defaultSnap","snapPoints","blocking","scrollLocking","style","onSpringStart","onSpringCancel","onSpringEnd","reserveScrollBarGap","expandOnContentDrag","disableExpandList"],T=["velocity"],M=["onRest","config"],I=p.default,F=I.tension,G=I.friction,Z=n.forwardRef(function(e,i){var l=e.children,p=e.sibling,P=e.className,b=e.footer,R=e.header,H=e.open,k=e.initialState,j=e.lastSnapRef,z=e.initialFocusRef,I=e.onDismiss,Z=e.maxHeight,K=e.defaultSnap,J=void 0===K?q:K,Q=e.snapPoints,U=void 0===Q?V:Q,W=e.blocking,X=void 0===W||W,Y=e.scrollLocking,$=void 0===Y||Y,_=e.style,ee=e.onSpringStart,ne=e.onSpringCancel,re=e.onSpringEnd,te=e.reserveScrollBarGap,oe=void 0===te?X:te,ie=e.expandOnContentDrag,ae=void 0!==ie&&ie,ce=e.disableExpandList,ue=void 0===ce?[]:ce,se=O(e,L),le=function(){var e=a(!1),n=e[0],r=e[1],t=a({}),i=t[0],u=t[1],s=c(function(e){return u(function(n){var r;return x({},n,((r={})[e]=!1,r))}),function(){u(function(n){var r;return x({},n,((r={})[e]=!0,r))})}},[]);return o(function(){var e=Object.values(i);0!==e.length&&e.every(Boolean)&&r(!0)},[i]),{ready:n,registerReady:s}}(),de=le.ready,fe=le.registerReady,ve=r(!1),me=r(ee),pe=r(ne),ye=r(re);o(function(){me.current=ee,pe.current=ne,ye.current=re},[ne,ee,re]);var he,ge,Se=f(function(){return{y:0,ready:0,maxHeight:0,minSnap:0,maxSnap:0}}),Ee=Se[0],Pe=Se[1],be=r(null),Re=r(null),xe=r(null),Oe=r(null),Ce=r(null),Ne=r(null),we=r(0),He=r(),De=r(!1),ke=(he=u(function(){return"undefined"!=typeof window?window.matchMedia("(prefers-reduced-motion: reduce)"):null},[]),ge=r(null==he?void 0:he.matches),t(ge.current?"reduce":"no-preference"),o(function(){var e=function(e){ge.current=e.matches};return null==he||he.addListener(e),function(){return null==he?void 0:he.removeListener(e)}},[he]),ge),je=function(e){var n=e.targetRef,i=e.enabled,a=e.reserveScrollBarGap,c=r({activate:function(){throw new TypeError("Tried to activate scroll lock too early")},deactivate:function(){}});return t(i?"Enabled":"Disabled"),o(function(){if(!i)return c.current.deactivate(),void(c.current={activate:function(){},deactivate:function(){}});var e=n.current,r=!1;c.current={activate:function(){r||(r=!0,S(e,{allowTouchMove:function(e){return e.closest("[data-body-scroll-lock-ignore]")},reserveScrollBarGap:a}))},deactivate:function(){r&&(r=!1,E(e))}}},[i,n,a]),c}({targetRef:Re,enabled:de&&$,reserveScrollBarGap:oe}),ze=function(e){var n=e.targetRef,i=e.enabled,a=r({activate:function(){throw new TypeError("Tried to activate aria hider too early")},deactivate:function(){}});return t(i?"Enabled":"Disabled"),o(function(){if(!i)return a.current.deactivate(),void(a.current={activate:function(){},deactivate:function(){}});var e=n.current,r=!1,t=[],o=[];a.current={activate:function(){if(!r){r=!0;var n=e.parentNode;document.querySelectorAll("body > *").forEach(function(e){if(e!==n){var r=e.getAttribute("aria-hidden");null!==r&&"false"!==r||(t.push(r),o.push(e),e.setAttribute("aria-hidden","true"))}})}},deactivate:function(){r&&(r=!1,o.forEach(function(e,n){var r=t[n];null===r?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",r)}),t=[],o=[])}}},[n,i]),a}({targetRef:be,enabled:de&&X}),Ae=function(e){var n=e.targetRef,i=e.fallbackRef,a=e.initialFocusRef,c=e.enabled,u=r({activate:function(){throw new TypeError("Tried to activate focus trap too early")},deactivate:function(){}});return t(c?"Enabled":"Disabled"),o(function(){if(!c)return u.current.deactivate(),void(u.current={activate:function(){},deactivate:function(){}});var e=i.current,r=g(n.current,{onActivate:void 0,initialFocus:a?function(){return(null==a?void 0:a.current)||e}:void 0,fallbackFocus:e,escapeDeactivates:!1,clickOutsideDeactivates:!1}),t=!1;u.current={activate:function(){try{return t?Promise.resolve():(t=!0,Promise.resolve(r.activate()).then(function(){return Promise.resolve(new Promise(function(e){return setTimeout(function(){return e(void 0)},0)})).then(function(){})}))}catch(e){return Promise.reject(e)}},deactivate:function(){t&&(t=!1,r.deactivate())}}},[c,i,a,n]),u}({targetRef:be,fallbackRef:Ne,initialFocusRef:z||void 0,enabled:de&&X&&!1!==z}),Le=function(e){var n=e.getSnapPoints,i=e.heightRef,c=e.lastSnapRef,s=e.ready,l=function(e){var n=e.contentRef,i=e.controlledMaxHeight,c=e.footerEnabled,s=e.footerRef,l=e.headerEnabled,d=e.headerRef,f=e.registerReady,v=e.resizeSourceRef,m=u(function(){return f("contentHeight")},[f]),p=function(e,n,i){var c=u(function(){return n("maxHeight")},[n]),s=a(function(){return w(e)||"undefined"!=typeof window?window.innerHeight:0}),l=s[0],d=s[1],f=l>0,v=r(0);return t(e?"controlled":"auto"),o(function(){f&&c()},[f,c]),C(function(){if(e)return d(w(e)),void(i.current="maxheightprop");var n=function(){v.current||(v.current=requestAnimationFrame(function(){d(window.innerHeight),i.current="window",v.current=0}))};return window.addEventListener("resize",n),d(window.innerHeight),i.current="window",c(),function(){window.removeEventListener("resize",n),cancelAnimationFrame(v.current)}},[e,c,i]),l}(i,f,v),y=D(d,{label:"headerHeight",enabled:l,resizeSourceRef:v}),h=D(n,{label:"contentHeight",enabled:!0,resizeSourceRef:v}),g=D(s,{label:"footerHeight",enabled:c,resizeSourceRef:v}),S=Math.min(p-y-g,h)+y+g;t("minHeight: "+S);var E=h>0;return o(function(){E&&m()},[E,m]),{maxHeight:p,minHeight:S,headerHeight:y,footerHeight:g}}({contentRef:e.contentRef,controlledMaxHeight:e.controlledMaxHeight,footerEnabled:e.footerEnabled,footerRef:e.footerRef,headerEnabled:e.headerEnabled,headerRef:e.headerRef,registerReady:e.registerReady,resizeSourceRef:e.resizeSourceRef}),d=l.maxHeight,f=l.minHeight,v=l.headerHeight,m=l.footerHeight,p=function(e,n){var r=[].concat(e).map(w).reduce(function(e,r){return e.add(N(r,0,n)),e},new Set),t=Array.from(r),o=Math.min.apply(Math,t);if(Number.isNaN(o))throw new TypeError("minSnap is NaN");var i=Math.max.apply(Math,t);if(Number.isNaN(i))throw new TypeError("maxSnap is NaN");return{snapPoints:t,minSnap:o,maxSnap:i}}(s?n({height:i.current,footerHeight:m,headerHeight:v,minHeight:f,maxHeight:d}):[0],d),y=p.snapPoints,h=p.minSnap,g=p.maxSnap;return t("minSnap: "+h+", maxSnap:"+g),{minSnap:h,maxSnap:g,findSnap:function(e){var n=w("function"==typeof e?e({footerHeight:m,headerHeight:v,height:i.current,minHeight:f,maxHeight:d,snapPoints:y,lastSnap:c.current}):e);return y.reduce(function(e,r){return Math.abs(r-n)<Math.abs(e-n)?r:e},h)},maxHeight:d}}({contentRef:xe,controlledMaxHeight:Z,footerEnabled:!!b,footerRef:Ce,getSnapPoints:U,headerEnabled:!1!==R,headerRef:Oe,heightRef:we,lastSnapRef:j,ready:de,registerReady:fe,resizeSourceRef:He}),Te=Le.minSnap,Me=Le.maxSnap,Ie=Le.maxHeight,Fe=Le.findSnap,Ge=r(Ie),Ze=r(Te),Be=r(Me),qe=r(Fe),Ve=r(0);C(function(){Ge.current=Ie,Be.current=Me,Ze.current=Te,qe.current=Fe,Ve.current=Fe(J)},[Fe,J,Ie,Me,Te]);var Ke=c(function(e){var n=e.onRest,r=e.config,t=(r=void 0===r?{}:r).velocity,o=void 0===t?1:t,i=O(r,T),a=O(e,M);return new Promise(function(e){return Pe(x({},a,{config:x({velocity:o},i,{mass:1,tension:F,friction:Math.max(G,G+(G-G*o))}),onRest:function(){var r=[].slice.call(arguments);e.apply(void 0,r),null==n||n.apply(void 0,r)}}))})},[Pe]),Je=d(A,{devTools:!1,actions:{onOpenCancel:c(function(){return null==pe.current?void 0:pe.current({type:"OPEN"})},[]),onSnapCancel:c(function(e){return null==pe.current?void 0:pe.current({type:"SNAP",source:e.snapSource})},[]),onCloseCancel:c(function(){return null==pe.current?void 0:pe.current({type:"CLOSE"})},[]),onResizeCancel:c(function(){return null==pe.current?void 0:pe.current({type:"RESIZE",source:He.current})},[]),onOpenEnd:c(function(){return null==ye.current?void 0:ye.current({type:"OPEN"})},[]),onSnapEnd:c(function(e,n){return null==ye.current?void 0:ye.current({type:"SNAP",source:e.snapSource})},[]),onResizeEnd:c(function(){return null==ye.current?void 0:ye.current({type:"RESIZE",source:He.current})},[])},context:{initialState:k},services:{onSnapStart:c(function(e,n){try{return Promise.resolve(null==me.current?void 0:me.current({type:"SNAP",source:n.payload.source||"custom"}))}catch(e){return Promise.reject(e)}},[]),onOpenStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"RESIZE",source:He.current}))}catch(e){return Promise.reject(e)}},[]),onSnapEnd:c(function(e,n){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"SNAP",source:e.snapSource}))}catch(e){return Promise.reject(e)}},[]),onOpenEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"RESIZE",source:He.current}))}catch(e){return Promise.reject(e)}},[]),renderVisuallyHidden:c(function(e,n){try{return Promise.resolve(Ke({y:Ve.current,ready:0,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke]),activate:c(function(e,n){try{return ve.current=!0,Promise.resolve(Promise.all([je.current.activate(),Ae.current.activate(),ze.current.activate()])).then(function(){})}catch(e){return Promise.reject(e)}},[ze,Ae,je]),deactivate:c(function(){try{return je.current.deactivate(),Ae.current.deactivate(),ze.current.deactivate(),ve.current=!1,Promise.resolve()}catch(e){return Promise.reject(e)}},[ze,Ae,je]),openImmediately:c(function(){try{return we.current=Ve.current,Promise.resolve(Ke({y:Ve.current,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke]),openSmoothly:c(function(){try{return Promise.resolve(Ke({y:0,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){return we.current=Ve.current,Promise.resolve(Ke({y:Ve.current,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ve.current,immediate:ke.current})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ke,ke]),snapSmoothly:c(function(e,n){try{var r=qe.current(e.y);return we.current=r,j.current=r,Promise.resolve(Ke({y:r,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ze.current,immediate:ke.current,config:{velocity:e.velocity}})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke,j,ke]),resizeSmoothly:c(function(){try{var e=qe.current(we.current);return we.current=e,j.current=e,Promise.resolve(Ke({y:e,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ze.current,immediate:"element"!==He.current||ke.current})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke,j,ke]),closeSmoothly:c(function(e,n){try{return Ke({minSnap:we.current,immediate:!0}),we.current=0,Promise.resolve(Ke({y:0,maxHeight:Ge.current,maxSnap:Be.current,immediate:ke.current})).then(function(){return Promise.resolve(Ke({ready:0,immediate:!0})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ke,ke])}}),Qe=Je[0],Ue=Je[1];o(function(){de&&Ue(H?"OPEN":"CLOSE")},[H,Ue,de]),C(function(){(Ie||Me||Te)&&Ue("RESIZE")},[Ie,Me,Te,Ue]),o(function(){return function(){je.current.deactivate(),Ae.current.deactivate(),ze.current.deactivate()}},[ze,Ae,je]),s(i,function(){return{snapTo:function(e,n){var r=void 0===n?{}:n,t=r.velocity,o=void 0===t?1:t,i=r.source,a=void 0===i?"custom":i;Ue("SNAP",{payload:{y:qe.current(e),velocity:o,source:a}})},get height(){return we.current}}},[Ue]),o(function(){var e=Re.current,n=function(e){var n=ue.map(function(e){return be.current.querySelector(e)}).filter(Boolean);if(n.length&&n.some(function(n){return n.contains(e.target)}))return!0;De.current&&e.preventDefault()},r=function(n){e.scrollTop<0&&(requestAnimationFrame(function(){e.style.overflow="hidden",e.scrollTop=0,e.style.removeProperty("overflow")}),n.preventDefault())};return ae&&(e.addEventListener("scroll",n),e.addEventListener("touchmove",n),e.addEventListener("touchstart",r)),function(){e.removeEventListener("scroll",n),e.removeEventListener("touchmove",n),e.removeEventListener("touchstart",r)}},[ae,Re,ue]);var We=y(function(e){var n=e.args,r=(n=void 0===n?[]:n)[0],t=(r=void 0===r?{}:r).closeOnTap,o=void 0!==t&&t,i=r.isContentDragging,a=void 0!==i&&i,c=e.cancel,u=e.direction[1],s=e.down,l=e.first,d=e.last,f=e.memo,v=void 0===f?Ee.y.get():f,m=e.tap,p=e.velocity,y=e.event,g=-1*e.movement[1];if(be.current&&ue.length){var S=ue.map(function(e){return be.current.querySelector(e)}).filter(Boolean);if(S.length&&S.some(function(e){return e.contains(y.target)}))return c(),v}if(!ve.current)return c(),v;if(I&&o&&m)return c(),setTimeout(function(){return I()},10),v;if(m)return v;var E=v+g,P=g*p,b=Math.max(Ze.current,Math.min(Be.current,E+2*P));if(!s&&I&&u>0&&E+P<Ze.current/2)return c(),I(),v;var R=s?I||Ze.current!==Be.current?h(E,I?0:Ze.current,Be.current,.55):E<Ze.current?h(E,Ze.current,2*Be.current,.55):h(E,Ze.current/2,Be.current,.55):b;return ae&&a?(R>=Be.current&&(R=Be.current),v===Be.current&&Re.current.scrollTop>0&&(R=Be.current),De.current=R<Be.current):De.current=!1,l&&Ue("DRAG"),d?(Ue("SNAP",{payload:{y:R,velocity:p>.05?p:1,source:"dragging"}}),v):(Pe({y:R,ready:1,maxHeight:Ge.current,maxSnap:Be.current,minSnap:Ze.current,immediate:!0,config:{velocity:p}}),v)},{filterTaps:!0});if(Number.isNaN(Be.current))throw new TypeError("maxSnapRef is NaN!!");if(Number.isNaN(Ze.current))throw new TypeError("minSnapRef is NaN!!");var Xe=function(e){var n,r=e.spring,t=v([r.y,r.maxHeight],function(e,n){return Math.round(N(n-e,0,16))+"px"}),o=v([r.y,r.minSnap,r.maxSnap],function(e,n,r){return N(e,n,r)+"px"}),i=v([r.y,r.minSnap,r.maxSnap],function(e,n,r){return e<n?n-e+"px":e>r?r-e+"px":"0px"}),a=v([r.y,r.maxSnap],function(e,n){return e>=n?Math.ceil(e-n):0}),c=v([r.y,r.minSnap],function(e,n){if(!n)return 0;var r=Math.max(n/2-45,0);return N((e-r)*(1/(Math.min(n/2+45,n)-r)+0),0,1)}),u=v([r.y,r.minSnap],function(e,n){return n?N(e/n,0,1):0});return(n={})["--rsbs-content-opacity"]=c,n["--rsbs-backdrop-opacity"]=u,n["--rsbs-antigap-scale-y"]=a,n["--rsbs-overlay-translate-y"]=i,n["--rsbs-overlay-rounded"]=t,n["--rsbs-overlay-h"]=o,n}({spring:Ee});/*#__PURE__*/return n.createElement(m.div,x({},se,{"data-rsbs-root":!0,"data-rsbs-state":B.find(Qe.matches),"data-rsbs-is-blocking":X,"data-rsbs-is-dismissable":!!I,"data-rsbs-has-header":!!R,"data-rsbs-has-footer":!!b,className:P,ref:be,style:x({},Xe,_,{opacity:Ee.ready})}),p,X&&/*#__PURE__*/n.createElement("div",x({key:"backdrop","data-rsbs-backdrop":!0},We({closeOnTap:!0}))),/*#__PURE__*/n.createElement("div",{key:"overlay","aria-modal":"true",role:"dialog","data-rsbs-overlay":!0,tabIndex:-1,ref:Ne,onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),I&&I())}},!1!==R&&/*#__PURE__*/n.createElement("div",x({key:"header","data-rsbs-header":!0,ref:Oe},We()),R),/*#__PURE__*/n.createElement("div",x({key:"scroll","data-rsbs-scroll":!0,ref:Re},ae?We({isContentDragging:!0}):{}),/*#__PURE__*/n.createElement("div",{"data-rsbs-content":!0,ref:xe},l)),b&&/*#__PURE__*/n.createElement("div",x({key:"footer",ref:Ce,"data-rsbs-footer":!0},We()),b)))}),B=["closed","opening","open","closing","dragging","snapping","resizing"];function q(e){var n=e.lastSnap;return null!=n?n:Math.min.apply(Math,e.snapPoints)}function V(e){return e.minHeight}var K=["onSpringStart","onSpringEnd","skipInitialTransition"],J=l(function(t,o){var i=t.onSpringStart,u=t.onSpringEnd,s=t.skipInitialTransition,l=O(t,K),d=a(!1),f=d[0],v=d[1],m=r(),p=r(null),y=r(s&&l.open?"OPEN":"CLOSED");C(function(){if(l.open)return cancelAnimationFrame(m.current),v(!0),function(){y.current="CLOSED"}},[l.open]);var h=c(function(e){return Promise.resolve(null==i?void 0:i(e)).then(function(){"OPEN"===e.type&&cancelAnimationFrame(m.current)})},[i]),g=c(function(e){return Promise.resolve(null==u?void 0:u(e)).then(function(){"CLOSE"===e.type&&(m.current=requestAnimationFrame(function(){return v(!1)}))})},[u]);return f?/*#__PURE__*/n.createElement(e.Root,{"data-rsbs-portal":!0},/*#__PURE__*/n.createElement(Z,x({},l,{lastSnapRef:p,ref:o,initialState:y.current,onSpringStart:h,onSpringEnd:g}))):null});export{J as BottomSheet};
import*as e from"@radix-ui/react-portal";import n,{useRef as r,useDebugValue as t,useEffect as o,useLayoutEffect as i,useState as a,useCallback as c,useMemo as u,useImperativeHandle as s,forwardRef as l}from"react";import{useMachine as d}from"@xstate/react";import{useSpring as f,to as v,animated as m,config as p}from"react-spring";import{useDrag as y,rubberbandIfOutOfBounds as h}from"react-use-gesture";import{createFocusTrap as g}from"focus-trap";import{disableBodyScroll as S,enableBodyScroll as E}from"body-scroll-lock";import{ResizeObserver as P}from"@juggle/resize-observer";import{Machine as b,assign as R}from"xstate";function x(){return x=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},x.apply(this,arguments)}function O(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)n.indexOf(r=i[t])>=0||(o[r]=e[r]);return o}var C="undefined"!=typeof window?i:o;function N(e,n,r){return n=(n=+n)==n?n:0,r=(r=+r)==r?r:0,(e=+e)==e&&(e=(e=e<=r?e:r)>=n?e:n),e}function H(e){var n=Math.round(e);if(Number.isNaN(e))throw new TypeError("Found a NaN! Check your snapPoints / defaultSnap / snapTo ");return n}var w={box:"border-box"};function D(e,n){var r=n.label,o=n.enabled,i=n.resizeSourceRef,u=a(0),s=u[0],l=u[1];t(r+": "+s);var d=c(function(e){l(e[0].borderBoxSize[0].blockSize),i.current="element"},[i]);return C(function(){if(e.current&&o){var n=new P(d);return n.observe(e.current,w),function(){n.disconnect()}}},[e,d,o]),o?s:0}function k(e){return void 0===e&&(e=1e3),new Promise(function(n){return setTimeout(n,e)})}var j={DRAG:{target:"#overlay.dragging",actions:"onOpenEnd"}},z={RESIZE:{target:"#overlay.resizing",actions:"onOpenEnd"}},L=b({id:"overlay",initial:"closed",context:{initialState:"CLOSED"},states:{closed:{on:{OPEN:"opening",CLOSE:void 0}},opening:{initial:"start",states:{start:{invoke:{src:"onOpenStart",onDone:"transition"}},transition:{always:[{target:"immediately",cond:"initiallyOpen"},{target:"smoothly",cond:"initiallyClosed"}]},immediately:{initial:"open",states:{open:{invoke:{src:"openImmediately",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"#overlay.opening.end"},on:x({},j,z)}}},smoothly:{initial:"visuallyHidden",states:{visuallyHidden:{invoke:{src:"renderVisuallyHidden",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"open"}},open:{invoke:{src:"openSmoothly",onDone:"#overlay.opening.end"},on:x({},j,z)}}},end:{invoke:{src:"onOpenEnd",onDone:"done"},on:{CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:x({},{CLOSE:{target:"#overlay.closing",actions:"onOpenCancel"}}),onDone:"open"},open:{on:{DRAG:"#overlay.dragging",SNAP:"snapping",RESIZE:"resizing"}},dragging:{on:{SNAP:"snapping"}},snapping:{initial:"start",states:{start:{invoke:{src:"onSnapStart",onDone:"snappingSmoothly"},entry:[R({y:function(e,n){return n.payload.y},velocity:function(e,n){return n.payload.velocity},snapSource:function(e,n){var r=n.payload.source;return void 0===r?"custom":r}})]},snappingSmoothly:{invoke:{src:"snapSmoothly",onDone:"end"}},end:{invoke:{src:"onSnapEnd",onDone:"done"},on:{RESIZE:"#overlay.resizing",SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{SNAP:{target:"snapping",actions:"onSnapEnd"},RESIZE:{target:"#overlay.resizing",actions:"onSnapCancel"},DRAG:{target:"#overlay.dragging",actions:"onSnapCancel"},CLOSE:{target:"#overlay.closing",actions:"onSnapCancel"}},onDone:"open"},resizing:{initial:"start",states:{start:{invoke:{src:"onResizeStart",onDone:"resizingSmoothly"}},resizingSmoothly:{invoke:{src:"resizeSmoothly",onDone:"end"}},end:{invoke:{src:"onResizeEnd",onDone:"done"},on:{SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{RESIZE:{target:"resizing",actions:"onResizeEnd"},SNAP:{target:"snapping",actions:"onResizeCancel"},DRAG:{target:"#overlay.dragging",actions:"onResizeCancel"},CLOSE:{target:"#overlay.closing",actions:"onResizeCancel"}},onDone:"open"},closing:{initial:"start",states:{start:{invoke:{src:"onCloseStart",onDone:"deactivating"},on:{OPEN:{target:"#overlay.open",actions:"onCloseCancel"}}},deactivating:{invoke:{src:"deactivate",onDone:"closingSmoothly"}},closingSmoothly:{invoke:{src:"closeSmoothly",onDone:"end"}},end:{invoke:{src:"onCloseEnd",onDone:"done"},on:{OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}}},done:{type:"final"}},on:{CLOSE:void 0,OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}},onDone:"closed"}},on:{CLOSE:"closing"}},{actions:{onOpenCancel:function(e,n){},onSnapCancel:function(e,n){},onResizeCancel:function(e,n){},onCloseCancel:function(e,n){},onOpenEnd:function(e,n){},onSnapEnd:function(e,n){},onResizeEnd:function(e,n){}},services:{onSnapStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeStart:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onSnapEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeEnd:function(){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},renderVisuallyHidden:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},activate:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},deactivate:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},openSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},openImmediately:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},snapSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},resizeSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}},closeSmoothly:function(e,n){try{return Promise.resolve(k()).then(function(){})}catch(e){return Promise.reject(e)}}},guards:{initiallyClosed:function(e){return"CLOSED"===e.initialState},initiallyOpen:function(e){return"OPEN"===e.initialState}}}),A=["children","sibling","className","footer","header","open","initialState","lastSnapRef","initialFocusRef","onDismiss","maxHeight","defaultSnap","snapPoints","blocking","scrollLocking","style","onSpringStart","onSpringCancel","onSpringEnd","reserveScrollBarGap","expandOnContentDrag","disableExpandList"],T=["velocity"],M=["onRest","config"],I=p.default,G=I.tension,F=I.friction,Z=n.forwardRef(function(e,i){var l=e.children,p=e.sibling,P=e.className,b=e.footer,R=e.header,w=e.open,k=e.initialState,j=e.lastSnapRef,z=e.initialFocusRef,I=e.onDismiss,Z=e.maxHeight,K=e.defaultSnap,J=void 0===K?q:K,Q=e.snapPoints,U=void 0===Q?V:Q,W=e.blocking,X=void 0===W||W,Y=e.scrollLocking,$=void 0===Y||Y,_=e.style,ee=e.onSpringStart,ne=e.onSpringCancel,re=e.onSpringEnd,te=e.reserveScrollBarGap,oe=void 0===te?X:te,ie=e.expandOnContentDrag,ae=void 0!==ie&&ie,ce=e.disableExpandList,ue=void 0===ce?[]:ce,se=O(e,A),le=function(){var e=a(!1),n=e[0],r=e[1],t=a({}),i=t[0],u=t[1],s=c(function(e){return u(function(n){var r;return x({},n,((r={})[e]=!1,r))}),function(){u(function(n){var r;return x({},n,((r={})[e]=!0,r))})}},[]);return o(function(){var e=Object.values(i);0!==e.length&&e.every(Boolean)&&r(!0)},[i]),{ready:n,registerReady:s}}(),de=le.ready,fe=le.registerReady,ve=r(!1),me=r(ee),pe=r(ne),ye=r(re);o(function(){me.current=ee,pe.current=ne,ye.current=re},[ne,ee,re]);var he,ge,Se=f(function(){return{y:0,ready:0,maxHeight:0,minSnap:0,maxSnap:0}}),Ee=Se[0],Pe=Se[1],be=r(null),Re=r(null),xe=r(null),Oe=r(null),Ce=r(null),Ne=r(null),He=r(0),we=r(),De=r(!1),ke=(he=u(function(){return"undefined"!=typeof window?window.matchMedia("(prefers-reduced-motion: reduce)"):null},[]),ge=r(null==he?void 0:he.matches),t(ge.current?"reduce":"no-preference"),o(function(){var e=function(e){ge.current=e.matches};return null==he||he.addListener(e),function(){return null==he?void 0:he.removeListener(e)}},[he]),ge),je=function(e){var n=e.targetRef,i=e.enabled,a=e.reserveScrollBarGap,c=r({activate:function(){throw new TypeError("Tried to activate scroll lock too early")},deactivate:function(){}});return t(i?"Enabled":"Disabled"),o(function(){if(!i)return c.current.deactivate(),void(c.current={activate:function(){},deactivate:function(){}});var e=n.current,r=!1;c.current={activate:function(){r||(r=!0,S(e,{allowTouchMove:function(e){return e.closest("[data-body-scroll-lock-ignore]")},reserveScrollBarGap:a}))},deactivate:function(){r&&(r=!1,E(e))}}},[i,n,a]),c}({targetRef:Re,enabled:de&&$,reserveScrollBarGap:oe}),ze=function(e){var n=e.targetRef,i=e.enabled,a=r({activate:function(){throw new TypeError("Tried to activate aria hider too early")},deactivate:function(){}});return t(i?"Enabled":"Disabled"),o(function(){if(!i)return a.current.deactivate(),void(a.current={activate:function(){},deactivate:function(){}});var e=n.current,r=!1,t=[],o=[];a.current={activate:function(){if(!r){r=!0;var n=e.parentNode;document.querySelectorAll("body > *").forEach(function(e){if(e!==n){var r=e.getAttribute("aria-hidden");null!==r&&"false"!==r||(t.push(r),o.push(e),e.setAttribute("aria-hidden","true"))}})}},deactivate:function(){r&&(r=!1,o.forEach(function(e,n){var r=t[n];null===r?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",r)}),t=[],o=[])}}},[n,i]),a}({targetRef:be,enabled:de&&X}),Le=function(e){var n=e.targetRef,i=e.fallbackRef,a=e.initialFocusRef,c=e.enabled,u=r({activate:function(){throw new TypeError("Tried to activate focus trap too early")},deactivate:function(){}});return t(c?"Enabled":"Disabled"),o(function(){if(!c)return u.current.deactivate(),void(u.current={activate:function(){},deactivate:function(){}});var e=i.current,r=g(n.current,{onActivate:void 0,initialFocus:a?function(){return(null==a?void 0:a.current)||e}:void 0,fallbackFocus:e,escapeDeactivates:!1,clickOutsideDeactivates:!1}),t=!1;u.current={activate:function(){try{return t?Promise.resolve():(t=!0,Promise.resolve(r.activate()).then(function(){return Promise.resolve(new Promise(function(e){return setTimeout(function(){return e(void 0)},0)})).then(function(){})}))}catch(e){return Promise.reject(e)}},deactivate:function(){t&&(t=!1,r.deactivate())}}},[c,i,a,n]),u}({targetRef:be,fallbackRef:Ne,initialFocusRef:z||void 0,enabled:de&&X&&!1!==z}),Ae=function(e){var n=e.getSnapPoints,i=e.heightRef,c=e.lastSnapRef,s=e.ready,l=function(e){var n=e.contentRef,i=e.controlledMaxHeight,c=e.footerEnabled,s=e.footerRef,l=e.headerEnabled,d=e.headerRef,f=e.registerReady,v=e.resizeSourceRef,m=u(function(){return f("contentHeight")},[f]),p=function(e,n,i){var c=u(function(){return n("maxHeight")},[n]),s=a(function(){return H(e)||"undefined"!=typeof window?window.innerHeight:0}),l=s[0],d=s[1],f=l>0,v=r(0);return t(e?"controlled":"auto"),o(function(){f&&c()},[f,c]),C(function(){if(e)return d(H(e)),void(i.current="maxheightprop");var n=function(){v.current||(v.current=requestAnimationFrame(function(){d(window.innerHeight),i.current="window",v.current=0}))};return window.addEventListener("resize",n),d(window.innerHeight),i.current="window",c(),function(){window.removeEventListener("resize",n),cancelAnimationFrame(v.current)}},[e,c,i]),l}(i,f,v),y=D(d,{label:"headerHeight",enabled:l,resizeSourceRef:v}),h=D(n,{label:"contentHeight",enabled:!0,resizeSourceRef:v}),g=D(s,{label:"footerHeight",enabled:c,resizeSourceRef:v}),S=Math.min(p-y-g,h)+y+g;t("minHeight: "+S);var E=h>0;return o(function(){E&&m()},[E,m]),{maxHeight:p,minHeight:S,headerHeight:y,footerHeight:g}}({contentRef:e.contentRef,controlledMaxHeight:e.controlledMaxHeight,footerEnabled:e.footerEnabled,footerRef:e.footerRef,headerEnabled:e.headerEnabled,headerRef:e.headerRef,registerReady:e.registerReady,resizeSourceRef:e.resizeSourceRef}),d=l.maxHeight,f=l.minHeight,v=l.headerHeight,m=l.footerHeight,p=function(e,n){var r=[].concat(e).map(H).reduce(function(e,r){return e.add(N(r,0,n)),e},new Set),t=Array.from(r),o=Math.min.apply(Math,t);if(Number.isNaN(o))throw new TypeError("minSnap is NaN");var i=Math.max.apply(Math,t);if(Number.isNaN(i))throw new TypeError("maxSnap is NaN");return{snapPoints:t,minSnap:o,maxSnap:i}}(s?n({height:i.current,footerHeight:m,headerHeight:v,minHeight:f,maxHeight:d}):[0],d),y=p.snapPoints,h=p.minSnap,g=p.maxSnap;return t("minSnap: "+h+", maxSnap:"+g),{minSnap:h,maxSnap:g,findSnap:function(e){var n=H("function"==typeof e?e({footerHeight:m,headerHeight:v,height:i.current,minHeight:f,maxHeight:d,snapPoints:y,lastSnap:c.current}):e);return y.reduce(function(e,r){return Math.abs(r-n)<Math.abs(e-n)?r:e},h)},maxHeight:d}}({contentRef:xe,controlledMaxHeight:Z,footerEnabled:!!b,footerRef:Ce,getSnapPoints:U,headerEnabled:!1!==R,headerRef:Oe,heightRef:He,lastSnapRef:j,ready:de,registerReady:fe,resizeSourceRef:we}),Te=Ae.minSnap,Me=Ae.maxSnap,Ie=Ae.maxHeight,Ge=Ae.findSnap,Fe=r(Ie),Ze=r(Te),Be=r(Me),qe=r(Ge),Ve=r(0);C(function(){Fe.current=Ie,Be.current=Me,Ze.current=Te,qe.current=Ge,Ve.current=Ge(J)},[Ge,J,Ie,Me,Te]);var Ke=c(function(e){var n=e.onRest,r=e.config,t=(r=void 0===r?{}:r).velocity,o=void 0===t?1:t,i=O(r,T),a=O(e,M);return new Promise(function(e){return Pe(x({},a,{config:x({velocity:o},i,{mass:1,tension:G,friction:Math.max(F,F+(F-F*o))}),onRest:function(){var r=[].slice.call(arguments);e.apply(void 0,r),null==n||n.apply(void 0,r)}}))})},[Pe]),Je=d(L,{devTools:!1,actions:{onOpenCancel:c(function(){return null==pe.current?void 0:pe.current({type:"OPEN"})},[]),onSnapCancel:c(function(e){return null==pe.current?void 0:pe.current({type:"SNAP",source:e.snapSource})},[]),onCloseCancel:c(function(){return null==pe.current?void 0:pe.current({type:"CLOSE"})},[]),onResizeCancel:c(function(){return null==pe.current?void 0:pe.current({type:"RESIZE",source:we.current})},[]),onOpenEnd:c(function(){return null==ye.current?void 0:ye.current({type:"OPEN"})},[]),onSnapEnd:c(function(e,n){return null==ye.current?void 0:ye.current({type:"SNAP",source:e.snapSource})},[]),onResizeEnd:c(function(){return null==ye.current?void 0:ye.current({type:"RESIZE",source:we.current})},[])},context:{initialState:k},services:{onSnapStart:c(function(e,n){try{return Promise.resolve(null==me.current?void 0:me.current({type:"SNAP",source:n.payload.source||"custom"}))}catch(e){return Promise.reject(e)}},[]),onOpenStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeStart:c(function(){try{return Promise.resolve(null==me.current?void 0:me.current({type:"RESIZE",source:we.current}))}catch(e){return Promise.reject(e)}},[]),onSnapEnd:c(function(e,n){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"SNAP",source:e.snapSource}))}catch(e){return Promise.reject(e)}},[]),onOpenEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeEnd:c(function(){try{return Promise.resolve(null==ye.current?void 0:ye.current({type:"RESIZE",source:we.current}))}catch(e){return Promise.reject(e)}},[]),renderVisuallyHidden:c(function(e,n){try{return Promise.resolve(Ke({y:Ve.current,ready:0,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke]),activate:c(function(e,n){try{return ve.current=!0,Promise.resolve(Promise.all([je.current.activate(),Le.current.activate(),ze.current.activate()])).then(function(){})}catch(e){return Promise.reject(e)}},[ze,Le,je]),deactivate:c(function(){try{return je.current.deactivate(),Le.current.deactivate(),ze.current.deactivate(),ve.current=!1,Promise.resolve()}catch(e){return Promise.reject(e)}},[ze,Le,je]),openImmediately:c(function(){try{return He.current=Ve.current,Promise.resolve(Ke({y:Ve.current,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke]),openSmoothly:c(function(){try{return Promise.resolve(Ke({y:0,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ve.current,immediate:!0})).then(function(){return He.current=Ve.current,Promise.resolve(Ke({y:Ve.current,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ve.current,immediate:ke.current})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ke,ke]),snapSmoothly:c(function(e,n){try{var r=qe.current(e.y);return He.current=r,j.current=r,Promise.resolve(Ke({y:r,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ze.current,immediate:ke.current,config:{velocity:e.velocity}})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke,j,ke]),resizeSmoothly:c(function(){try{var e=qe.current(He.current);return He.current=e,j.current=e,Promise.resolve(Ke({y:e,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ze.current,immediate:"element"!==we.current||ke.current})).then(function(){})}catch(e){return Promise.reject(e)}},[Ke,j,ke]),closeSmoothly:c(function(e,n){try{return Ke({minSnap:He.current,immediate:!0}),He.current=0,Promise.resolve(Ke({y:0,maxHeight:Fe.current,maxSnap:Be.current,immediate:ke.current})).then(function(){return Promise.resolve(Ke({ready:0,immediate:!0})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ke,ke])}}),Qe=Je[0],Ue=Je[1];o(function(){de&&Ue(w?"OPEN":"CLOSE")},[w,Ue,de]),C(function(){(Ie||Me||Te)&&Ue("RESIZE")},[Ie,Me,Te,Ue]),o(function(){return function(){je.current.deactivate(),Le.current.deactivate(),ze.current.deactivate()}},[ze,Le,je]),s(i,function(){return{snapTo:function(e,n){var r=void 0===n?{}:n,t=r.velocity,o=void 0===t?1:t,i=r.source,a=void 0===i?"custom":i;Ue("SNAP",{payload:{y:qe.current(e),velocity:o,source:a}})},get height(){return He.current}}},[Ue]),o(function(){var e=Re.current,n=function(n){var r=ue.map(function(e){return be.current.querySelector(e)}).filter(Boolean);if(r.length&&r.some(function(e){return e.contains(n.target)}))return!0;De.current&&e.scrollTop<=0&&n.preventDefault()},r=0,t=function(n){e.scrollTop<0&&(r=e.scrollTop)},o=function(n){e.scrollTop<0&&e.scrollTop<r&&n.preventDefault()};return ae&&(e.addEventListener("scroll",n),e.addEventListener("touchmove",n),e.addEventListener("touchmove",o),e.addEventListener("touchstart",t,{passive:!0})),function(){e.removeEventListener("scroll",n),e.removeEventListener("touchmove",n),e.removeEventListener("touchmove",o),e.removeEventListener("touchstart",t)}},[ae,Re,ue]);var We=y(function(e){var n=e.args,r=(n=void 0===n?[]:n)[0],t=(r=void 0===r?{}:r).closeOnTap,o=void 0!==t&&t,i=r.isContentDragging,a=void 0!==i&&i,c=e.cancel,u=e.direction[1],s=e.down,l=e.first,d=e.last,f=e.memo,v=void 0===f?Ee.y.get():f,m=e.tap,p=e.velocity,y=e.event,g=-1*e.movement[1],S=Re.current.scrollHeight>Re.current.clientHeight;if(be.current&&ue.length){var E=ue.map(function(e){return be.current.querySelector(e)}).filter(Boolean);if(E.length&&E.some(function(e){return e.contains(y.target)}))return c(),v}if(!ve.current)return c(),v;if(I&&o&&m)return c(),setTimeout(function(){return I()},10),v;if(m)return v;var P=v+g,b=g*p,R=Math.max(Ze.current,Math.min(Be.current,P+2*b));if(!s&&I&&u>0&&P+b<Ze.current/2&&(!S||Re.current.scrollTop<=0))return c(),I(),v;var x=s?I||Ze.current!==Be.current?h(P,I?0:Ze.current,Be.current,.55):P<Ze.current?h(P,Ze.current,2*Be.current,.55):h(P,Ze.current/2,Be.current,.55):R;return ae&&a?(x>=Be.current&&(x=Be.current),v===Be.current&&Re.current.scrollTop>0&&(x=Be.current),De.current=x<Be.current):De.current=!1,l&&Ue("DRAG"),d?(Ue("SNAP",{payload:{y:x,velocity:p>.05?p:1,source:"dragging"}}),v):(Pe({y:x,ready:1,maxHeight:Fe.current,maxSnap:Be.current,minSnap:Ze.current,immediate:!0,config:{velocity:p}}),v)},{filterTaps:!0});if(Number.isNaN(Be.current))throw new TypeError("maxSnapRef is NaN!!");if(Number.isNaN(Ze.current))throw new TypeError("minSnapRef is NaN!!");var Xe=function(e){var n,r=e.spring,t=v([r.y,r.maxHeight],function(e,n){return Math.round(N(n-e,0,16))+"px"}),o=v([r.y,r.minSnap,r.maxSnap],function(e,n,r){return N(e,n,r)+"px"}),i=v([r.y,r.minSnap,r.maxSnap],function(e,n,r){return e<n?n-e+"px":e>r?r-e+"px":"0px"}),a=v([r.y,r.maxSnap],function(e,n){return e>=n?Math.ceil(e-n):0}),c=v([r.y,r.minSnap],function(e,n){if(!n)return 0;var r=Math.max(n/2-45,0);return N((e-r)*(1/(Math.min(n/2+45,n)-r)+0),0,1)}),u=v([r.y,r.minSnap],function(e,n){return n?N(e/n,0,1):0});return(n={})["--rsbs-content-opacity"]=c,n["--rsbs-backdrop-opacity"]=u,n["--rsbs-antigap-scale-y"]=a,n["--rsbs-overlay-translate-y"]=i,n["--rsbs-overlay-rounded"]=t,n["--rsbs-overlay-h"]=o,n}({spring:Ee});/*#__PURE__*/return n.createElement(m.div,x({},se,{"data-rsbs-root":!0,"data-rsbs-state":B.find(Qe.matches),"data-rsbs-is-blocking":X,"data-rsbs-is-dismissable":!!I,"data-rsbs-has-header":!!R,"data-rsbs-has-footer":!!b,className:P,ref:be,style:x({},Xe,_,{opacity:Ee.ready})}),p,X&&/*#__PURE__*/n.createElement("div",x({key:"backdrop","data-rsbs-backdrop":!0},We({closeOnTap:!0}))),/*#__PURE__*/n.createElement("div",{key:"overlay","aria-modal":"true",role:"dialog","data-rsbs-overlay":!0,tabIndex:-1,ref:Ne,onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),I&&I())}},!1!==R&&/*#__PURE__*/n.createElement("div",x({key:"header","data-rsbs-header":!0,ref:Oe},We()),R),/*#__PURE__*/n.createElement("div",x({key:"scroll","data-rsbs-scroll":!0,ref:Re},ae?We({isContentDragging:!0}):{}),/*#__PURE__*/n.createElement("div",{"data-rsbs-content":!0,ref:xe},l)),b&&/*#__PURE__*/n.createElement("div",x({key:"footer",ref:Ce,"data-rsbs-footer":!0},We()),b)))}),B=["closed","opening","open","closing","dragging","snapping","resizing"];function q(e){var n=e.lastSnap;return null!=n?n:Math.min.apply(Math,e.snapPoints)}function V(e){return e.minHeight}var K=["onSpringStart","onSpringEnd","skipInitialTransition"],J=l(function(t,o){var i=t.onSpringStart,u=t.onSpringEnd,s=t.skipInitialTransition,l=O(t,K),d=a(!1),f=d[0],v=d[1],m=r(),p=r(null),y=r(s&&l.open?"OPEN":"CLOSED");C(function(){if(l.open)return cancelAnimationFrame(m.current),v(!0),function(){y.current="CLOSED"}},[l.open]);var h=c(function(e){return Promise.resolve(null==i?void 0:i(e)).then(function(){"OPEN"===e.type&&cancelAnimationFrame(m.current)})},[i]),g=c(function(e){return Promise.resolve(null==u?void 0:u(e)).then(function(){"CLOSE"===e.type&&(m.current=requestAnimationFrame(function(){return v(!1)}))})},[u]);return f?/*#__PURE__*/n.createElement(e.Root,{"data-rsbs-portal":!0},/*#__PURE__*/n.createElement(Z,x({},l,{lastSnapRef:p,ref:o,initialState:y.current,onSpringStart:h,onSpringEnd:g}))):null});export{J as BottomSheet};
//# sourceMappingURL=index.es.js.map

@@ -1,2 +0,2 @@

var e=require("@radix-ui/react-portal"),n=require("react"),r=require("@xstate/react"),t=require("react-spring"),o=require("react-use-gesture"),i=require("focus-trap"),a=require("body-scroll-lock"),c=require("@juggle/resize-observer"),u=require("xstate");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var f=/*#__PURE__*/l(e),d=/*#__PURE__*/s(n);function v(){return v=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},v.apply(this,arguments)}function m(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)n.indexOf(r=i[t])>=0||(o[r]=e[r]);return o}var p="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function y(e,n,r){return n=(n=+n)==n?n:0,r=(r=+r)==r?r:0,(e=+e)==e&&(e=(e=e<=r?e:r)>=n?e:n),e}function g(e){var n=Math.round(e);if(Number.isNaN(e))throw new TypeError("Found a NaN! Check your snapPoints / defaultSnap / snapTo ");return n}var h={box:"border-box"};function S(e,r){var t=r.label,o=r.enabled,i=r.resizeSourceRef,a=n.useState(0),u=a[0],s=a[1];n.useDebugValue(t+": "+u);var l=n.useCallback(function(e){s(e[0].borderBoxSize[0].blockSize),i.current="element"},[i]);return p(function(){if(e.current&&o){var n=new c.ResizeObserver(l);return n.observe(e.current,h),function(){n.disconnect()}}},[e,l,o]),o?u:0}function b(e){return void 0===e&&(e=1e3),new Promise(function(n){return setTimeout(n,e)})}var E={DRAG:{target:"#overlay.dragging",actions:"onOpenEnd"}},P={RESIZE:{target:"#overlay.resizing",actions:"onOpenEnd"}},R=u.Machine({id:"overlay",initial:"closed",context:{initialState:"CLOSED"},states:{closed:{on:{OPEN:"opening",CLOSE:void 0}},opening:{initial:"start",states:{start:{invoke:{src:"onOpenStart",onDone:"transition"}},transition:{always:[{target:"immediately",cond:"initiallyOpen"},{target:"smoothly",cond:"initiallyClosed"}]},immediately:{initial:"open",states:{open:{invoke:{src:"openImmediately",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"#overlay.opening.end"},on:v({},E,P)}}},smoothly:{initial:"visuallyHidden",states:{visuallyHidden:{invoke:{src:"renderVisuallyHidden",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"open"}},open:{invoke:{src:"openSmoothly",onDone:"#overlay.opening.end"},on:v({},E,P)}}},end:{invoke:{src:"onOpenEnd",onDone:"done"},on:{CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:v({},{CLOSE:{target:"#overlay.closing",actions:"onOpenCancel"}}),onDone:"open"},open:{on:{DRAG:"#overlay.dragging",SNAP:"snapping",RESIZE:"resizing"}},dragging:{on:{SNAP:"snapping"}},snapping:{initial:"start",states:{start:{invoke:{src:"onSnapStart",onDone:"snappingSmoothly"},entry:[u.assign({y:function(e,n){return n.payload.y},velocity:function(e,n){return n.payload.velocity},snapSource:function(e,n){var r=n.payload.source;return void 0===r?"custom":r}})]},snappingSmoothly:{invoke:{src:"snapSmoothly",onDone:"end"}},end:{invoke:{src:"onSnapEnd",onDone:"done"},on:{RESIZE:"#overlay.resizing",SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{SNAP:{target:"snapping",actions:"onSnapEnd"},RESIZE:{target:"#overlay.resizing",actions:"onSnapCancel"},DRAG:{target:"#overlay.dragging",actions:"onSnapCancel"},CLOSE:{target:"#overlay.closing",actions:"onSnapCancel"}},onDone:"open"},resizing:{initial:"start",states:{start:{invoke:{src:"onResizeStart",onDone:"resizingSmoothly"}},resizingSmoothly:{invoke:{src:"resizeSmoothly",onDone:"end"}},end:{invoke:{src:"onResizeEnd",onDone:"done"},on:{SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{RESIZE:{target:"resizing",actions:"onResizeEnd"},SNAP:{target:"snapping",actions:"onResizeCancel"},DRAG:{target:"#overlay.dragging",actions:"onResizeCancel"},CLOSE:{target:"#overlay.closing",actions:"onResizeCancel"}},onDone:"open"},closing:{initial:"start",states:{start:{invoke:{src:"onCloseStart",onDone:"deactivating"},on:{OPEN:{target:"#overlay.open",actions:"onCloseCancel"}}},deactivating:{invoke:{src:"deactivate",onDone:"closingSmoothly"}},closingSmoothly:{invoke:{src:"closeSmoothly",onDone:"end"}},end:{invoke:{src:"onCloseEnd",onDone:"done"},on:{OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}}},done:{type:"final"}},on:{CLOSE:void 0,OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}},onDone:"closed"}},on:{CLOSE:"closing"}},{actions:{onOpenCancel:function(e,n){},onSnapCancel:function(e,n){},onResizeCancel:function(e,n){},onCloseCancel:function(e,n){},onOpenEnd:function(e,n){},onSnapEnd:function(e,n){},onResizeEnd:function(e,n){}},services:{onSnapStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onSnapEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},renderVisuallyHidden:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},activate:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},deactivate:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},openSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},openImmediately:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},snapSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},resizeSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},closeSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}}},guards:{initiallyClosed:function(e){return"CLOSED"===e.initialState},initiallyOpen:function(e){return"OPEN"===e.initialState}}}),C=["children","sibling","className","footer","header","open","initialState","lastSnapRef","initialFocusRef","onDismiss","maxHeight","defaultSnap","snapPoints","blocking","scrollLocking","style","onSpringStart","onSpringCancel","onSpringEnd","reserveScrollBarGap","expandOnContentDrag","disableExpandList"],k=["velocity"],O=["onRest","config"],x=t.config.default,D=x.tension,w=x.friction,N=d.default.forwardRef(function(e,c){var u=e.children,s=e.sibling,l=e.className,f=e.footer,h=e.header,b=e.open,E=e.initialState,P=e.lastSnapRef,x=e.initialFocusRef,N=e.onDismiss,A=e.maxHeight,L=e.defaultSnap,M=void 0===L?j:L,T=e.snapPoints,I=void 0===T?z:T,q=e.blocking,B=void 0===q||q,F=e.scrollLocking,G=void 0===F||F,V=e.style,Z=e.onSpringStart,_=e.onSpringCancel,K=e.onSpringEnd,J=e.reserveScrollBarGap,Q=void 0===J?B:J,U=e.expandOnContentDrag,W=void 0!==U&&U,X=e.disableExpandList,Y=void 0===X?[]:X,$=m(e,C),ee=function(){var e=n.useState(!1),r=e[0],t=e[1],o=n.useState({}),i=o[0],a=o[1],c=n.useCallback(function(e){return a(function(n){var r;return v({},n,((r={})[e]=!1,r))}),function(){a(function(n){var r;return v({},n,((r={})[e]=!0,r))})}},[]);return n.useEffect(function(){var e=Object.values(i);0!==e.length&&e.every(Boolean)&&t(!0)},[i]),{ready:r,registerReady:c}}(),ne=ee.ready,re=ee.registerReady,te=n.useRef(!1),oe=n.useRef(Z),ie=n.useRef(_),ae=n.useRef(K);n.useEffect(function(){oe.current=Z,ie.current=_,ae.current=K},[_,Z,K]);var ce,ue,se=t.useSpring(function(){return{y:0,ready:0,maxHeight:0,minSnap:0,maxSnap:0}}),le=se[0],fe=se[1],de=n.useRef(null),ve=n.useRef(null),me=n.useRef(null),pe=n.useRef(null),ye=n.useRef(null),ge=n.useRef(null),he=n.useRef(0),Se=n.useRef(),be=n.useRef(!1),Ee=(ce=n.useMemo(function(){return"undefined"!=typeof window?window.matchMedia("(prefers-reduced-motion: reduce)"):null},[]),ue=n.useRef(null==ce?void 0:ce.matches),n.useDebugValue(ue.current?"reduce":"no-preference"),n.useEffect(function(){var e=function(e){ue.current=e.matches};return null==ce||ce.addListener(e),function(){return null==ce?void 0:ce.removeListener(e)}},[ce]),ue),Pe=function(e){var r=e.targetRef,t=e.enabled,o=e.reserveScrollBarGap,i=n.useRef({activate:function(){throw new TypeError("Tried to activate scroll lock too early")},deactivate:function(){}});return n.useDebugValue(t?"Enabled":"Disabled"),n.useEffect(function(){if(!t)return i.current.deactivate(),void(i.current={activate:function(){},deactivate:function(){}});var e=r.current,n=!1;i.current={activate:function(){n||(n=!0,a.disableBodyScroll(e,{allowTouchMove:function(e){return e.closest("[data-body-scroll-lock-ignore]")},reserveScrollBarGap:o}))},deactivate:function(){n&&(n=!1,a.enableBodyScroll(e))}}},[t,r,o]),i}({targetRef:ve,enabled:ne&&G,reserveScrollBarGap:Q}),Re=function(e){var r=e.targetRef,t=e.enabled,o=n.useRef({activate:function(){throw new TypeError("Tried to activate aria hider too early")},deactivate:function(){}});return n.useDebugValue(t?"Enabled":"Disabled"),n.useEffect(function(){if(!t)return o.current.deactivate(),void(o.current={activate:function(){},deactivate:function(){}});var e=r.current,n=!1,i=[],a=[];o.current={activate:function(){if(!n){n=!0;var r=e.parentNode;document.querySelectorAll("body > *").forEach(function(e){if(e!==r){var n=e.getAttribute("aria-hidden");null!==n&&"false"!==n||(i.push(n),a.push(e),e.setAttribute("aria-hidden","true"))}})}},deactivate:function(){n&&(n=!1,a.forEach(function(e,n){var r=i[n];null===r?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",r)}),i=[],a=[])}}},[r,t]),o}({targetRef:de,enabled:ne&&B}),Ce=function(e){var r=e.targetRef,t=e.fallbackRef,o=e.initialFocusRef,a=e.enabled,c=n.useRef({activate:function(){throw new TypeError("Tried to activate focus trap too early")},deactivate:function(){}});return n.useDebugValue(a?"Enabled":"Disabled"),n.useEffect(function(){if(!a)return c.current.deactivate(),void(c.current={activate:function(){},deactivate:function(){}});var e=t.current,n=i.createFocusTrap(r.current,{onActivate:void 0,initialFocus:o?function(){return(null==o?void 0:o.current)||e}:void 0,fallbackFocus:e,escapeDeactivates:!1,clickOutsideDeactivates:!1}),u=!1;c.current={activate:function(){try{return u?Promise.resolve():(u=!0,Promise.resolve(n.activate()).then(function(){return Promise.resolve(new Promise(function(e){return setTimeout(function(){return e(void 0)},0)})).then(function(){})}))}catch(e){return Promise.reject(e)}},deactivate:function(){u&&(u=!1,n.deactivate())}}},[a,t,o,r]),c}({targetRef:de,fallbackRef:ge,initialFocusRef:x||void 0,enabled:ne&&B&&!1!==x}),ke=function(e){var r=e.getSnapPoints,t=e.heightRef,o=e.lastSnapRef,i=e.ready,a=function(e){var r=e.contentRef,t=e.controlledMaxHeight,o=e.footerEnabled,i=e.footerRef,a=e.headerEnabled,c=e.headerRef,u=e.registerReady,s=e.resizeSourceRef,l=n.useMemo(function(){return u("contentHeight")},[u]),f=function(e,r,t){var o=n.useMemo(function(){return r("maxHeight")},[r]),i=n.useState(function(){return g(e)||"undefined"!=typeof window?window.innerHeight:0}),a=i[0],c=i[1],u=a>0,s=n.useRef(0);return n.useDebugValue(e?"controlled":"auto"),n.useEffect(function(){u&&o()},[u,o]),p(function(){if(e)return c(g(e)),void(t.current="maxheightprop");var n=function(){s.current||(s.current=requestAnimationFrame(function(){c(window.innerHeight),t.current="window",s.current=0}))};return window.addEventListener("resize",n),c(window.innerHeight),t.current="window",o(),function(){window.removeEventListener("resize",n),cancelAnimationFrame(s.current)}},[e,o,t]),a}(t,u,s),d=S(c,{label:"headerHeight",enabled:a,resizeSourceRef:s}),v=S(r,{label:"contentHeight",enabled:!0,resizeSourceRef:s}),m=S(i,{label:"footerHeight",enabled:o,resizeSourceRef:s}),y=Math.min(f-d-m,v)+d+m;n.useDebugValue("minHeight: "+y);var h=v>0;return n.useEffect(function(){h&&l()},[h,l]),{maxHeight:f,minHeight:y,headerHeight:d,footerHeight:m}}({contentRef:e.contentRef,controlledMaxHeight:e.controlledMaxHeight,footerEnabled:e.footerEnabled,footerRef:e.footerRef,headerEnabled:e.headerEnabled,headerRef:e.headerRef,registerReady:e.registerReady,resizeSourceRef:e.resizeSourceRef}),c=a.maxHeight,u=a.minHeight,s=a.headerHeight,l=a.footerHeight,f=function(e,n){var r=[].concat(e).map(g).reduce(function(e,r){return e.add(y(r,0,n)),e},new Set),t=Array.from(r),o=Math.min.apply(Math,t);if(Number.isNaN(o))throw new TypeError("minSnap is NaN");var i=Math.max.apply(Math,t);if(Number.isNaN(i))throw new TypeError("maxSnap is NaN");return{snapPoints:t,minSnap:o,maxSnap:i}}(i?r({height:t.current,footerHeight:l,headerHeight:s,minHeight:u,maxHeight:c}):[0],c),d=f.snapPoints,v=f.minSnap,m=f.maxSnap;return n.useDebugValue("minSnap: "+v+", maxSnap:"+m),{minSnap:v,maxSnap:m,findSnap:function(e){var n=g("function"==typeof e?e({footerHeight:l,headerHeight:s,height:t.current,minHeight:u,maxHeight:c,snapPoints:d,lastSnap:o.current}):e);return d.reduce(function(e,r){return Math.abs(r-n)<Math.abs(e-n)?r:e},v)},maxHeight:c}}({contentRef:me,controlledMaxHeight:A,footerEnabled:!!f,footerRef:ye,getSnapPoints:I,headerEnabled:!1!==h,headerRef:pe,heightRef:he,lastSnapRef:P,ready:ne,registerReady:re,resizeSourceRef:Se}),Oe=ke.minSnap,xe=ke.maxSnap,De=ke.maxHeight,we=ke.findSnap,Ne=n.useRef(De),He=n.useRef(Oe),je=n.useRef(xe),ze=n.useRef(we),Ae=n.useRef(0);p(function(){Ne.current=De,je.current=xe,He.current=Oe,ze.current=we,Ae.current=we(M)},[we,M,De,xe,Oe]);var Le=n.useCallback(function(e){var n=e.onRest,r=e.config,t=(r=void 0===r?{}:r).velocity,o=void 0===t?1:t,i=m(r,k),a=m(e,O);return new Promise(function(e){return fe(v({},a,{config:v({velocity:o},i,{mass:1,tension:D,friction:Math.max(w,w+(w-w*o))}),onRest:function(){var r=[].slice.call(arguments);e.apply(void 0,r),null==n||n.apply(void 0,r)}}))})},[fe]),Me=r.useMachine(R,{devTools:!1,actions:{onOpenCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"OPEN"})},[]),onSnapCancel:n.useCallback(function(e){return null==ie.current?void 0:ie.current({type:"SNAP",source:e.snapSource})},[]),onCloseCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"CLOSE"})},[]),onResizeCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"RESIZE",source:Se.current})},[]),onOpenEnd:n.useCallback(function(){return null==ae.current?void 0:ae.current({type:"OPEN"})},[]),onSnapEnd:n.useCallback(function(e,n){return null==ae.current?void 0:ae.current({type:"SNAP",source:e.snapSource})},[]),onResizeEnd:n.useCallback(function(){return null==ae.current?void 0:ae.current({type:"RESIZE",source:Se.current})},[])},context:{initialState:E},services:{onSnapStart:n.useCallback(function(e,n){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"SNAP",source:n.payload.source||"custom"}))}catch(e){return Promise.reject(e)}},[]),onOpenStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"RESIZE",source:Se.current}))}catch(e){return Promise.reject(e)}},[]),onSnapEnd:n.useCallback(function(e,n){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"SNAP",source:e.snapSource}))}catch(e){return Promise.reject(e)}},[]),onOpenEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"RESIZE",source:Se.current}))}catch(e){return Promise.reject(e)}},[]),renderVisuallyHidden:n.useCallback(function(e,n){try{return Promise.resolve(Le({y:Ae.current,ready:0,maxHeight:Ne.current,maxSnap:je.current,minSnap:Ae.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Le]),activate:n.useCallback(function(e,n){try{return te.current=!0,Promise.resolve(Promise.all([Pe.current.activate(),Ce.current.activate(),Re.current.activate()])).then(function(){})}catch(e){return Promise.reject(e)}},[Re,Ce,Pe]),deactivate:n.useCallback(function(){try{return Pe.current.deactivate(),Ce.current.deactivate(),Re.current.deactivate(),te.current=!1,Promise.resolve()}catch(e){return Promise.reject(e)}},[Re,Ce,Pe]),openImmediately:n.useCallback(function(){try{return he.current=Ae.current,Promise.resolve(Le({y:Ae.current,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:Ae.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Le]),openSmoothly:n.useCallback(function(){try{return Promise.resolve(Le({y:0,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:Ae.current,immediate:!0})).then(function(){return he.current=Ae.current,Promise.resolve(Le({y:Ae.current,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:Ae.current,immediate:Ee.current})).then(function(){})})}catch(e){return Promise.reject(e)}},[Le,Ee]),snapSmoothly:n.useCallback(function(e,n){try{var r=ze.current(e.y);return he.current=r,P.current=r,Promise.resolve(Le({y:r,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:He.current,immediate:Ee.current,config:{velocity:e.velocity}})).then(function(){})}catch(e){return Promise.reject(e)}},[Le,P,Ee]),resizeSmoothly:n.useCallback(function(){try{var e=ze.current(he.current);return he.current=e,P.current=e,Promise.resolve(Le({y:e,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:He.current,immediate:"element"!==Se.current||Ee.current})).then(function(){})}catch(e){return Promise.reject(e)}},[Le,P,Ee]),closeSmoothly:n.useCallback(function(e,n){try{return Le({minSnap:he.current,immediate:!0}),he.current=0,Promise.resolve(Le({y:0,maxHeight:Ne.current,maxSnap:je.current,immediate:Ee.current})).then(function(){return Promise.resolve(Le({ready:0,immediate:!0})).then(function(){})})}catch(e){return Promise.reject(e)}},[Le,Ee])}}),Te=Me[0],Ie=Me[1];n.useEffect(function(){ne&&Ie(b?"OPEN":"CLOSE")},[b,Ie,ne]),p(function(){(De||xe||Oe)&&Ie("RESIZE")},[De,xe,Oe,Ie]),n.useEffect(function(){return function(){Pe.current.deactivate(),Ce.current.deactivate(),Re.current.deactivate()}},[Re,Ce,Pe]),n.useImperativeHandle(c,function(){return{snapTo:function(e,n){var r=void 0===n?{}:n,t=r.velocity,o=void 0===t?1:t,i=r.source,a=void 0===i?"custom":i;Ie("SNAP",{payload:{y:ze.current(e),velocity:o,source:a}})},get height(){return he.current}}},[Ie]),n.useEffect(function(){var e=ve.current,n=function(e){var n=Y.map(function(e){return de.current.querySelector(e)}).filter(Boolean);if(n.length&&n.some(function(n){return n.contains(e.target)}))return!0;be.current&&e.preventDefault()},r=function(n){e.scrollTop<0&&(requestAnimationFrame(function(){e.style.overflow="hidden",e.scrollTop=0,e.style.removeProperty("overflow")}),n.preventDefault())};return W&&(e.addEventListener("scroll",n),e.addEventListener("touchmove",n),e.addEventListener("touchstart",r)),function(){e.removeEventListener("scroll",n),e.removeEventListener("touchmove",n),e.removeEventListener("touchstart",r)}},[W,ve,Y]);var qe=o.useDrag(function(e){var n=e.args,r=(n=void 0===n?[]:n)[0],t=(r=void 0===r?{}:r).closeOnTap,i=void 0!==t&&t,a=r.isContentDragging,c=void 0!==a&&a,u=e.cancel,s=e.direction[1],l=e.down,f=e.first,d=e.last,v=e.memo,m=void 0===v?le.y.get():v,p=e.tap,y=e.velocity,g=e.event,h=-1*e.movement[1];if(de.current&&Y.length){var S=Y.map(function(e){return de.current.querySelector(e)}).filter(Boolean);if(S.length&&S.some(function(e){return e.contains(g.target)}))return u(),m}if(!te.current)return u(),m;if(N&&i&&p)return u(),setTimeout(function(){return N()},10),m;if(p)return m;var b=m+h,E=h*y,P=Math.max(He.current,Math.min(je.current,b+2*E));if(!l&&N&&s>0&&b+E<He.current/2)return u(),N(),m;var R=l?N||He.current!==je.current?o.rubberbandIfOutOfBounds(b,N?0:He.current,je.current,.55):b<He.current?o.rubberbandIfOutOfBounds(b,He.current,2*je.current,.55):o.rubberbandIfOutOfBounds(b,He.current/2,je.current,.55):P;return W&&c?(R>=je.current&&(R=je.current),m===je.current&&ve.current.scrollTop>0&&(R=je.current),be.current=R<je.current):be.current=!1,f&&Ie("DRAG"),d?(Ie("SNAP",{payload:{y:R,velocity:y>.05?y:1,source:"dragging"}}),m):(fe({y:R,ready:1,maxHeight:Ne.current,maxSnap:je.current,minSnap:He.current,immediate:!0,config:{velocity:y}}),m)},{filterTaps:!0});if(Number.isNaN(je.current))throw new TypeError("maxSnapRef is NaN!!");if(Number.isNaN(He.current))throw new TypeError("minSnapRef is NaN!!");var Be=function(e){var n,r=e.spring,o=t.to([r.y,r.maxHeight],function(e,n){return Math.round(y(n-e,0,16))+"px"}),i=t.to([r.y,r.minSnap,r.maxSnap],function(e,n,r){return y(e,n,r)+"px"}),a=t.to([r.y,r.minSnap,r.maxSnap],function(e,n,r){return e<n?n-e+"px":e>r?r-e+"px":"0px"}),c=t.to([r.y,r.maxSnap],function(e,n){return e>=n?Math.ceil(e-n):0}),u=t.to([r.y,r.minSnap],function(e,n){if(!n)return 0;var r=Math.max(n/2-45,0);return y((e-r)*(1/(Math.min(n/2+45,n)-r)+0),0,1)}),s=t.to([r.y,r.minSnap],function(e,n){return n?y(e/n,0,1):0});return(n={})["--rsbs-content-opacity"]=u,n["--rsbs-backdrop-opacity"]=s,n["--rsbs-antigap-scale-y"]=c,n["--rsbs-overlay-translate-y"]=a,n["--rsbs-overlay-rounded"]=o,n["--rsbs-overlay-h"]=i,n}({spring:le});/*#__PURE__*/return d.default.createElement(t.animated.div,v({},$,{"data-rsbs-root":!0,"data-rsbs-state":H.find(Te.matches),"data-rsbs-is-blocking":B,"data-rsbs-is-dismissable":!!N,"data-rsbs-has-header":!!h,"data-rsbs-has-footer":!!f,className:l,ref:de,style:v({},Be,V,{opacity:le.ready})}),s,B&&/*#__PURE__*/d.default.createElement("div",v({key:"backdrop","data-rsbs-backdrop":!0},qe({closeOnTap:!0}))),/*#__PURE__*/d.default.createElement("div",{key:"overlay","aria-modal":"true",role:"dialog","data-rsbs-overlay":!0,tabIndex:-1,ref:ge,onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),N&&N())}},!1!==h&&/*#__PURE__*/d.default.createElement("div",v({key:"header","data-rsbs-header":!0,ref:pe},qe()),h),/*#__PURE__*/d.default.createElement("div",v({key:"scroll","data-rsbs-scroll":!0,ref:ve},W?qe({isContentDragging:!0}):{}),/*#__PURE__*/d.default.createElement("div",{"data-rsbs-content":!0,ref:me},u)),f&&/*#__PURE__*/d.default.createElement("div",v({key:"footer",ref:ye,"data-rsbs-footer":!0},qe()),f)))}),H=["closed","opening","open","closing","dragging","snapping","resizing"];function j(e){var n=e.lastSnap;return null!=n?n:Math.min.apply(Math,e.snapPoints)}function z(e){return e.minHeight}var A=["onSpringStart","onSpringEnd","skipInitialTransition"],L=n.forwardRef(function(e,r){var t=e.onSpringStart,o=e.onSpringEnd,i=e.skipInitialTransition,a=m(e,A),c=n.useState(!1),u=c[0],s=c[1],l=n.useRef(),y=n.useRef(null),g=n.useRef(i&&a.open?"OPEN":"CLOSED");p(function(){if(a.open)return cancelAnimationFrame(l.current),s(!0),function(){g.current="CLOSED"}},[a.open]);var h=n.useCallback(function(e){return Promise.resolve(null==t?void 0:t(e)).then(function(){"OPEN"===e.type&&cancelAnimationFrame(l.current)})},[t]),S=n.useCallback(function(e){return Promise.resolve(null==o?void 0:o(e)).then(function(){"CLOSE"===e.type&&(l.current=requestAnimationFrame(function(){return s(!1)}))})},[o]);return u?/*#__PURE__*/d.default.createElement(f.Root,{"data-rsbs-portal":!0},/*#__PURE__*/d.default.createElement(N,v({},a,{lastSnapRef:y,ref:r,initialState:g.current,onSpringStart:h,onSpringEnd:S}))):null});exports.BottomSheet=L;
var e=require("@radix-ui/react-portal"),n=require("react"),r=require("@xstate/react"),t=require("react-spring"),o=require("react-use-gesture"),i=require("focus-trap"),a=require("body-scroll-lock"),c=require("@juggle/resize-observer"),u=require("xstate");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function l(e){if(e&&e.__esModule)return e;var n=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var t=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,t.get?t:{enumerable:!0,get:function(){return e[r]}})}}),n.default=e,n}var f=/*#__PURE__*/l(e),d=/*#__PURE__*/s(n);function v(){return v=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},v.apply(this,arguments)}function p(e,n){if(null==e)return{};var r,t,o={},i=Object.keys(e);for(t=0;t<i.length;t++)n.indexOf(r=i[t])>=0||(o[r]=e[r]);return o}var m="undefined"!=typeof window?n.useLayoutEffect:n.useEffect;function y(e,n,r){return n=(n=+n)==n?n:0,r=(r=+r)==r?r:0,(e=+e)==e&&(e=(e=e<=r?e:r)>=n?e:n),e}function g(e){var n=Math.round(e);if(Number.isNaN(e))throw new TypeError("Found a NaN! Check your snapPoints / defaultSnap / snapTo ");return n}var h={box:"border-box"};function S(e,r){var t=r.label,o=r.enabled,i=r.resizeSourceRef,a=n.useState(0),u=a[0],s=a[1];n.useDebugValue(t+": "+u);var l=n.useCallback(function(e){s(e[0].borderBoxSize[0].blockSize),i.current="element"},[i]);return m(function(){if(e.current&&o){var n=new c.ResizeObserver(l);return n.observe(e.current,h),function(){n.disconnect()}}},[e,l,o]),o?u:0}function b(e){return void 0===e&&(e=1e3),new Promise(function(n){return setTimeout(n,e)})}var E={DRAG:{target:"#overlay.dragging",actions:"onOpenEnd"}},P={RESIZE:{target:"#overlay.resizing",actions:"onOpenEnd"}},R=u.Machine({id:"overlay",initial:"closed",context:{initialState:"CLOSED"},states:{closed:{on:{OPEN:"opening",CLOSE:void 0}},opening:{initial:"start",states:{start:{invoke:{src:"onOpenStart",onDone:"transition"}},transition:{always:[{target:"immediately",cond:"initiallyOpen"},{target:"smoothly",cond:"initiallyClosed"}]},immediately:{initial:"open",states:{open:{invoke:{src:"openImmediately",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"#overlay.opening.end"},on:v({},E,P)}}},smoothly:{initial:"visuallyHidden",states:{visuallyHidden:{invoke:{src:"renderVisuallyHidden",onDone:"activating"}},activating:{invoke:{src:"activate",onDone:"open"}},open:{invoke:{src:"openSmoothly",onDone:"#overlay.opening.end"},on:v({},E,P)}}},end:{invoke:{src:"onOpenEnd",onDone:"done"},on:{CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:v({},{CLOSE:{target:"#overlay.closing",actions:"onOpenCancel"}}),onDone:"open"},open:{on:{DRAG:"#overlay.dragging",SNAP:"snapping",RESIZE:"resizing"}},dragging:{on:{SNAP:"snapping"}},snapping:{initial:"start",states:{start:{invoke:{src:"onSnapStart",onDone:"snappingSmoothly"},entry:[u.assign({y:function(e,n){return n.payload.y},velocity:function(e,n){return n.payload.velocity},snapSource:function(e,n){var r=n.payload.source;return void 0===r?"custom":r}})]},snappingSmoothly:{invoke:{src:"snapSmoothly",onDone:"end"}},end:{invoke:{src:"onSnapEnd",onDone:"done"},on:{RESIZE:"#overlay.resizing",SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{SNAP:{target:"snapping",actions:"onSnapEnd"},RESIZE:{target:"#overlay.resizing",actions:"onSnapCancel"},DRAG:{target:"#overlay.dragging",actions:"onSnapCancel"},CLOSE:{target:"#overlay.closing",actions:"onSnapCancel"}},onDone:"open"},resizing:{initial:"start",states:{start:{invoke:{src:"onResizeStart",onDone:"resizingSmoothly"}},resizingSmoothly:{invoke:{src:"resizeSmoothly",onDone:"end"}},end:{invoke:{src:"onResizeEnd",onDone:"done"},on:{SNAP:"#overlay.snapping",CLOSE:"#overlay.closing",DRAG:"#overlay.dragging"}},done:{type:"final"}},on:{RESIZE:{target:"resizing",actions:"onResizeEnd"},SNAP:{target:"snapping",actions:"onResizeCancel"},DRAG:{target:"#overlay.dragging",actions:"onResizeCancel"},CLOSE:{target:"#overlay.closing",actions:"onResizeCancel"}},onDone:"open"},closing:{initial:"start",states:{start:{invoke:{src:"onCloseStart",onDone:"deactivating"},on:{OPEN:{target:"#overlay.open",actions:"onCloseCancel"}}},deactivating:{invoke:{src:"deactivate",onDone:"closingSmoothly"}},closingSmoothly:{invoke:{src:"closeSmoothly",onDone:"end"}},end:{invoke:{src:"onCloseEnd",onDone:"done"},on:{OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}}},done:{type:"final"}},on:{CLOSE:void 0,OPEN:{target:"#overlay.opening",actions:"onCloseCancel"}},onDone:"closed"}},on:{CLOSE:"closing"}},{actions:{onOpenCancel:function(e,n){},onSnapCancel:function(e,n){},onResizeCancel:function(e,n){},onCloseCancel:function(e,n){},onOpenEnd:function(e,n){},onSnapEnd:function(e,n){},onResizeEnd:function(e,n){}},services:{onSnapStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeStart:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onSnapEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onOpenEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onCloseEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},onResizeEnd:function(){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},renderVisuallyHidden:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},activate:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},deactivate:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},openSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},openImmediately:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},snapSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},resizeSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}},closeSmoothly:function(e,n){try{return Promise.resolve(b()).then(function(){})}catch(e){return Promise.reject(e)}}},guards:{initiallyClosed:function(e){return"CLOSED"===e.initialState},initiallyOpen:function(e){return"OPEN"===e.initialState}}}),C=["children","sibling","className","footer","header","open","initialState","lastSnapRef","initialFocusRef","onDismiss","maxHeight","defaultSnap","snapPoints","blocking","scrollLocking","style","onSpringStart","onSpringCancel","onSpringEnd","reserveScrollBarGap","expandOnContentDrag","disableExpandList"],k=["velocity"],O=["onRest","config"],x=t.config.default,D=x.tension,N=x.friction,H=d.default.forwardRef(function(e,c){var u=e.children,s=e.sibling,l=e.className,f=e.footer,h=e.header,b=e.open,E=e.initialState,P=e.lastSnapRef,x=e.initialFocusRef,H=e.onDismiss,L=e.maxHeight,A=e.defaultSnap,T=void 0===A?j:A,M=e.snapPoints,I=void 0===M?z:M,B=e.blocking,q=void 0===B||B,F=e.scrollLocking,G=void 0===F||F,V=e.style,Z=e.onSpringStart,_=e.onSpringCancel,K=e.onSpringEnd,J=e.reserveScrollBarGap,Q=void 0===J?q:J,U=e.expandOnContentDrag,W=void 0!==U&&U,X=e.disableExpandList,Y=void 0===X?[]:X,$=p(e,C),ee=function(){var e=n.useState(!1),r=e[0],t=e[1],o=n.useState({}),i=o[0],a=o[1],c=n.useCallback(function(e){return a(function(n){var r;return v({},n,((r={})[e]=!1,r))}),function(){a(function(n){var r;return v({},n,((r={})[e]=!0,r))})}},[]);return n.useEffect(function(){var e=Object.values(i);0!==e.length&&e.every(Boolean)&&t(!0)},[i]),{ready:r,registerReady:c}}(),ne=ee.ready,re=ee.registerReady,te=n.useRef(!1),oe=n.useRef(Z),ie=n.useRef(_),ae=n.useRef(K);n.useEffect(function(){oe.current=Z,ie.current=_,ae.current=K},[_,Z,K]);var ce,ue,se=t.useSpring(function(){return{y:0,ready:0,maxHeight:0,minSnap:0,maxSnap:0}}),le=se[0],fe=se[1],de=n.useRef(null),ve=n.useRef(null),pe=n.useRef(null),me=n.useRef(null),ye=n.useRef(null),ge=n.useRef(null),he=n.useRef(0),Se=n.useRef(),be=n.useRef(!1),Ee=(ce=n.useMemo(function(){return"undefined"!=typeof window?window.matchMedia("(prefers-reduced-motion: reduce)"):null},[]),ue=n.useRef(null==ce?void 0:ce.matches),n.useDebugValue(ue.current?"reduce":"no-preference"),n.useEffect(function(){var e=function(e){ue.current=e.matches};return null==ce||ce.addListener(e),function(){return null==ce?void 0:ce.removeListener(e)}},[ce]),ue),Pe=function(e){var r=e.targetRef,t=e.enabled,o=e.reserveScrollBarGap,i=n.useRef({activate:function(){throw new TypeError("Tried to activate scroll lock too early")},deactivate:function(){}});return n.useDebugValue(t?"Enabled":"Disabled"),n.useEffect(function(){if(!t)return i.current.deactivate(),void(i.current={activate:function(){},deactivate:function(){}});var e=r.current,n=!1;i.current={activate:function(){n||(n=!0,a.disableBodyScroll(e,{allowTouchMove:function(e){return e.closest("[data-body-scroll-lock-ignore]")},reserveScrollBarGap:o}))},deactivate:function(){n&&(n=!1,a.enableBodyScroll(e))}}},[t,r,o]),i}({targetRef:ve,enabled:ne&&G,reserveScrollBarGap:Q}),Re=function(e){var r=e.targetRef,t=e.enabled,o=n.useRef({activate:function(){throw new TypeError("Tried to activate aria hider too early")},deactivate:function(){}});return n.useDebugValue(t?"Enabled":"Disabled"),n.useEffect(function(){if(!t)return o.current.deactivate(),void(o.current={activate:function(){},deactivate:function(){}});var e=r.current,n=!1,i=[],a=[];o.current={activate:function(){if(!n){n=!0;var r=e.parentNode;document.querySelectorAll("body > *").forEach(function(e){if(e!==r){var n=e.getAttribute("aria-hidden");null!==n&&"false"!==n||(i.push(n),a.push(e),e.setAttribute("aria-hidden","true"))}})}},deactivate:function(){n&&(n=!1,a.forEach(function(e,n){var r=i[n];null===r?e.removeAttribute("aria-hidden"):e.setAttribute("aria-hidden",r)}),i=[],a=[])}}},[r,t]),o}({targetRef:de,enabled:ne&&q}),Ce=function(e){var r=e.targetRef,t=e.fallbackRef,o=e.initialFocusRef,a=e.enabled,c=n.useRef({activate:function(){throw new TypeError("Tried to activate focus trap too early")},deactivate:function(){}});return n.useDebugValue(a?"Enabled":"Disabled"),n.useEffect(function(){if(!a)return c.current.deactivate(),void(c.current={activate:function(){},deactivate:function(){}});var e=t.current,n=i.createFocusTrap(r.current,{onActivate:void 0,initialFocus:o?function(){return(null==o?void 0:o.current)||e}:void 0,fallbackFocus:e,escapeDeactivates:!1,clickOutsideDeactivates:!1}),u=!1;c.current={activate:function(){try{return u?Promise.resolve():(u=!0,Promise.resolve(n.activate()).then(function(){return Promise.resolve(new Promise(function(e){return setTimeout(function(){return e(void 0)},0)})).then(function(){})}))}catch(e){return Promise.reject(e)}},deactivate:function(){u&&(u=!1,n.deactivate())}}},[a,t,o,r]),c}({targetRef:de,fallbackRef:ge,initialFocusRef:x||void 0,enabled:ne&&q&&!1!==x}),ke=function(e){var r=e.getSnapPoints,t=e.heightRef,o=e.lastSnapRef,i=e.ready,a=function(e){var r=e.contentRef,t=e.controlledMaxHeight,o=e.footerEnabled,i=e.footerRef,a=e.headerEnabled,c=e.headerRef,u=e.registerReady,s=e.resizeSourceRef,l=n.useMemo(function(){return u("contentHeight")},[u]),f=function(e,r,t){var o=n.useMemo(function(){return r("maxHeight")},[r]),i=n.useState(function(){return g(e)||"undefined"!=typeof window?window.innerHeight:0}),a=i[0],c=i[1],u=a>0,s=n.useRef(0);return n.useDebugValue(e?"controlled":"auto"),n.useEffect(function(){u&&o()},[u,o]),m(function(){if(e)return c(g(e)),void(t.current="maxheightprop");var n=function(){s.current||(s.current=requestAnimationFrame(function(){c(window.innerHeight),t.current="window",s.current=0}))};return window.addEventListener("resize",n),c(window.innerHeight),t.current="window",o(),function(){window.removeEventListener("resize",n),cancelAnimationFrame(s.current)}},[e,o,t]),a}(t,u,s),d=S(c,{label:"headerHeight",enabled:a,resizeSourceRef:s}),v=S(r,{label:"contentHeight",enabled:!0,resizeSourceRef:s}),p=S(i,{label:"footerHeight",enabled:o,resizeSourceRef:s}),y=Math.min(f-d-p,v)+d+p;n.useDebugValue("minHeight: "+y);var h=v>0;return n.useEffect(function(){h&&l()},[h,l]),{maxHeight:f,minHeight:y,headerHeight:d,footerHeight:p}}({contentRef:e.contentRef,controlledMaxHeight:e.controlledMaxHeight,footerEnabled:e.footerEnabled,footerRef:e.footerRef,headerEnabled:e.headerEnabled,headerRef:e.headerRef,registerReady:e.registerReady,resizeSourceRef:e.resizeSourceRef}),c=a.maxHeight,u=a.minHeight,s=a.headerHeight,l=a.footerHeight,f=function(e,n){var r=[].concat(e).map(g).reduce(function(e,r){return e.add(y(r,0,n)),e},new Set),t=Array.from(r),o=Math.min.apply(Math,t);if(Number.isNaN(o))throw new TypeError("minSnap is NaN");var i=Math.max.apply(Math,t);if(Number.isNaN(i))throw new TypeError("maxSnap is NaN");return{snapPoints:t,minSnap:o,maxSnap:i}}(i?r({height:t.current,footerHeight:l,headerHeight:s,minHeight:u,maxHeight:c}):[0],c),d=f.snapPoints,v=f.minSnap,p=f.maxSnap;return n.useDebugValue("minSnap: "+v+", maxSnap:"+p),{minSnap:v,maxSnap:p,findSnap:function(e){var n=g("function"==typeof e?e({footerHeight:l,headerHeight:s,height:t.current,minHeight:u,maxHeight:c,snapPoints:d,lastSnap:o.current}):e);return d.reduce(function(e,r){return Math.abs(r-n)<Math.abs(e-n)?r:e},v)},maxHeight:c}}({contentRef:pe,controlledMaxHeight:L,footerEnabled:!!f,footerRef:ye,getSnapPoints:I,headerEnabled:!1!==h,headerRef:me,heightRef:he,lastSnapRef:P,ready:ne,registerReady:re,resizeSourceRef:Se}),Oe=ke.minSnap,xe=ke.maxSnap,De=ke.maxHeight,Ne=ke.findSnap,He=n.useRef(De),we=n.useRef(Oe),je=n.useRef(xe),ze=n.useRef(Ne),Le=n.useRef(0);m(function(){He.current=De,je.current=xe,we.current=Oe,ze.current=Ne,Le.current=Ne(T)},[Ne,T,De,xe,Oe]);var Ae=n.useCallback(function(e){var n=e.onRest,r=e.config,t=(r=void 0===r?{}:r).velocity,o=void 0===t?1:t,i=p(r,k),a=p(e,O);return new Promise(function(e){return fe(v({},a,{config:v({velocity:o},i,{mass:1,tension:D,friction:Math.max(N,N+(N-N*o))}),onRest:function(){var r=[].slice.call(arguments);e.apply(void 0,r),null==n||n.apply(void 0,r)}}))})},[fe]),Te=r.useMachine(R,{devTools:!1,actions:{onOpenCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"OPEN"})},[]),onSnapCancel:n.useCallback(function(e){return null==ie.current?void 0:ie.current({type:"SNAP",source:e.snapSource})},[]),onCloseCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"CLOSE"})},[]),onResizeCancel:n.useCallback(function(){return null==ie.current?void 0:ie.current({type:"RESIZE",source:Se.current})},[]),onOpenEnd:n.useCallback(function(){return null==ae.current?void 0:ae.current({type:"OPEN"})},[]),onSnapEnd:n.useCallback(function(e,n){return null==ae.current?void 0:ae.current({type:"SNAP",source:e.snapSource})},[]),onResizeEnd:n.useCallback(function(){return null==ae.current?void 0:ae.current({type:"RESIZE",source:Se.current})},[])},context:{initialState:E},services:{onSnapStart:n.useCallback(function(e,n){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"SNAP",source:n.payload.source||"custom"}))}catch(e){return Promise.reject(e)}},[]),onOpenStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeStart:n.useCallback(function(){try{return Promise.resolve(null==oe.current?void 0:oe.current({type:"RESIZE",source:Se.current}))}catch(e){return Promise.reject(e)}},[]),onSnapEnd:n.useCallback(function(e,n){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"SNAP",source:e.snapSource}))}catch(e){return Promise.reject(e)}},[]),onOpenEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"OPEN"}))}catch(e){return Promise.reject(e)}},[]),onCloseEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"CLOSE"}))}catch(e){return Promise.reject(e)}},[]),onResizeEnd:n.useCallback(function(){try{return Promise.resolve(null==ae.current?void 0:ae.current({type:"RESIZE",source:Se.current}))}catch(e){return Promise.reject(e)}},[]),renderVisuallyHidden:n.useCallback(function(e,n){try{return Promise.resolve(Ae({y:Le.current,ready:0,maxHeight:He.current,maxSnap:je.current,minSnap:Le.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ae]),activate:n.useCallback(function(e,n){try{return te.current=!0,Promise.resolve(Promise.all([Pe.current.activate(),Ce.current.activate(),Re.current.activate()])).then(function(){})}catch(e){return Promise.reject(e)}},[Re,Ce,Pe]),deactivate:n.useCallback(function(){try{return Pe.current.deactivate(),Ce.current.deactivate(),Re.current.deactivate(),te.current=!1,Promise.resolve()}catch(e){return Promise.reject(e)}},[Re,Ce,Pe]),openImmediately:n.useCallback(function(){try{return he.current=Le.current,Promise.resolve(Ae({y:Le.current,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:Le.current,immediate:!0})).then(function(){})}catch(e){return Promise.reject(e)}},[Ae]),openSmoothly:n.useCallback(function(){try{return Promise.resolve(Ae({y:0,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:Le.current,immediate:!0})).then(function(){return he.current=Le.current,Promise.resolve(Ae({y:Le.current,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:Le.current,immediate:Ee.current})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ae,Ee]),snapSmoothly:n.useCallback(function(e,n){try{var r=ze.current(e.y);return he.current=r,P.current=r,Promise.resolve(Ae({y:r,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:we.current,immediate:Ee.current,config:{velocity:e.velocity}})).then(function(){})}catch(e){return Promise.reject(e)}},[Ae,P,Ee]),resizeSmoothly:n.useCallback(function(){try{var e=ze.current(he.current);return he.current=e,P.current=e,Promise.resolve(Ae({y:e,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:we.current,immediate:"element"!==Se.current||Ee.current})).then(function(){})}catch(e){return Promise.reject(e)}},[Ae,P,Ee]),closeSmoothly:n.useCallback(function(e,n){try{return Ae({minSnap:he.current,immediate:!0}),he.current=0,Promise.resolve(Ae({y:0,maxHeight:He.current,maxSnap:je.current,immediate:Ee.current})).then(function(){return Promise.resolve(Ae({ready:0,immediate:!0})).then(function(){})})}catch(e){return Promise.reject(e)}},[Ae,Ee])}}),Me=Te[0],Ie=Te[1];n.useEffect(function(){ne&&Ie(b?"OPEN":"CLOSE")},[b,Ie,ne]),m(function(){(De||xe||Oe)&&Ie("RESIZE")},[De,xe,Oe,Ie]),n.useEffect(function(){return function(){Pe.current.deactivate(),Ce.current.deactivate(),Re.current.deactivate()}},[Re,Ce,Pe]),n.useImperativeHandle(c,function(){return{snapTo:function(e,n){var r=void 0===n?{}:n,t=r.velocity,o=void 0===t?1:t,i=r.source,a=void 0===i?"custom":i;Ie("SNAP",{payload:{y:ze.current(e),velocity:o,source:a}})},get height(){return he.current}}},[Ie]),n.useEffect(function(){var e=ve.current,n=function(n){var r=Y.map(function(e){return de.current.querySelector(e)}).filter(Boolean);if(r.length&&r.some(function(e){return e.contains(n.target)}))return!0;be.current&&e.scrollTop<=0&&n.preventDefault()},r=0,t=function(n){e.scrollTop<0&&(r=e.scrollTop)},o=function(n){e.scrollTop<0&&e.scrollTop<r&&n.preventDefault()};return W&&(e.addEventListener("scroll",n),e.addEventListener("touchmove",n),e.addEventListener("touchmove",o),e.addEventListener("touchstart",t,{passive:!0})),function(){e.removeEventListener("scroll",n),e.removeEventListener("touchmove",n),e.removeEventListener("touchmove",o),e.removeEventListener("touchstart",t)}},[W,ve,Y]);var Be=o.useDrag(function(e){var n=e.args,r=(n=void 0===n?[]:n)[0],t=(r=void 0===r?{}:r).closeOnTap,i=void 0!==t&&t,a=r.isContentDragging,c=void 0!==a&&a,u=e.cancel,s=e.direction[1],l=e.down,f=e.first,d=e.last,v=e.memo,p=void 0===v?le.y.get():v,m=e.tap,y=e.velocity,g=e.event,h=-1*e.movement[1],S=ve.current.scrollHeight>ve.current.clientHeight;if(de.current&&Y.length){var b=Y.map(function(e){return de.current.querySelector(e)}).filter(Boolean);if(b.length&&b.some(function(e){return e.contains(g.target)}))return u(),p}if(!te.current)return u(),p;if(H&&i&&m)return u(),setTimeout(function(){return H()},10),p;if(m)return p;var E=p+h,P=h*y,R=Math.max(we.current,Math.min(je.current,E+2*P));if(!l&&H&&s>0&&E+P<we.current/2&&(!S||ve.current.scrollTop<=0))return u(),H(),p;var C=l?H||we.current!==je.current?o.rubberbandIfOutOfBounds(E,H?0:we.current,je.current,.55):E<we.current?o.rubberbandIfOutOfBounds(E,we.current,2*je.current,.55):o.rubberbandIfOutOfBounds(E,we.current/2,je.current,.55):R;return W&&c?(C>=je.current&&(C=je.current),p===je.current&&ve.current.scrollTop>0&&(C=je.current),be.current=C<je.current):be.current=!1,f&&Ie("DRAG"),d?(Ie("SNAP",{payload:{y:C,velocity:y>.05?y:1,source:"dragging"}}),p):(fe({y:C,ready:1,maxHeight:He.current,maxSnap:je.current,minSnap:we.current,immediate:!0,config:{velocity:y}}),p)},{filterTaps:!0});if(Number.isNaN(je.current))throw new TypeError("maxSnapRef is NaN!!");if(Number.isNaN(we.current))throw new TypeError("minSnapRef is NaN!!");var qe=function(e){var n,r=e.spring,o=t.to([r.y,r.maxHeight],function(e,n){return Math.round(y(n-e,0,16))+"px"}),i=t.to([r.y,r.minSnap,r.maxSnap],function(e,n,r){return y(e,n,r)+"px"}),a=t.to([r.y,r.minSnap,r.maxSnap],function(e,n,r){return e<n?n-e+"px":e>r?r-e+"px":"0px"}),c=t.to([r.y,r.maxSnap],function(e,n){return e>=n?Math.ceil(e-n):0}),u=t.to([r.y,r.minSnap],function(e,n){if(!n)return 0;var r=Math.max(n/2-45,0);return y((e-r)*(1/(Math.min(n/2+45,n)-r)+0),0,1)}),s=t.to([r.y,r.minSnap],function(e,n){return n?y(e/n,0,1):0});return(n={})["--rsbs-content-opacity"]=u,n["--rsbs-backdrop-opacity"]=s,n["--rsbs-antigap-scale-y"]=c,n["--rsbs-overlay-translate-y"]=a,n["--rsbs-overlay-rounded"]=o,n["--rsbs-overlay-h"]=i,n}({spring:le});/*#__PURE__*/return d.default.createElement(t.animated.div,v({},$,{"data-rsbs-root":!0,"data-rsbs-state":w.find(Me.matches),"data-rsbs-is-blocking":q,"data-rsbs-is-dismissable":!!H,"data-rsbs-has-header":!!h,"data-rsbs-has-footer":!!f,className:l,ref:de,style:v({},qe,V,{opacity:le.ready})}),s,q&&/*#__PURE__*/d.default.createElement("div",v({key:"backdrop","data-rsbs-backdrop":!0},Be({closeOnTap:!0}))),/*#__PURE__*/d.default.createElement("div",{key:"overlay","aria-modal":"true",role:"dialog","data-rsbs-overlay":!0,tabIndex:-1,ref:ge,onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),H&&H())}},!1!==h&&/*#__PURE__*/d.default.createElement("div",v({key:"header","data-rsbs-header":!0,ref:me},Be()),h),/*#__PURE__*/d.default.createElement("div",v({key:"scroll","data-rsbs-scroll":!0,ref:ve},W?Be({isContentDragging:!0}):{}),/*#__PURE__*/d.default.createElement("div",{"data-rsbs-content":!0,ref:pe},u)),f&&/*#__PURE__*/d.default.createElement("div",v({key:"footer",ref:ye,"data-rsbs-footer":!0},Be()),f)))}),w=["closed","opening","open","closing","dragging","snapping","resizing"];function j(e){var n=e.lastSnap;return null!=n?n:Math.min.apply(Math,e.snapPoints)}function z(e){return e.minHeight}var L=["onSpringStart","onSpringEnd","skipInitialTransition"],A=n.forwardRef(function(e,r){var t=e.onSpringStart,o=e.onSpringEnd,i=e.skipInitialTransition,a=p(e,L),c=n.useState(!1),u=c[0],s=c[1],l=n.useRef(),y=n.useRef(null),g=n.useRef(i&&a.open?"OPEN":"CLOSED");m(function(){if(a.open)return cancelAnimationFrame(l.current),s(!0),function(){g.current="CLOSED"}},[a.open]);var h=n.useCallback(function(e){return Promise.resolve(null==t?void 0:t(e)).then(function(){"OPEN"===e.type&&cancelAnimationFrame(l.current)})},[t]),S=n.useCallback(function(e){return Promise.resolve(null==o?void 0:o(e)).then(function(){"CLOSE"===e.type&&(l.current=requestAnimationFrame(function(){return s(!1)}))})},[o]);return u?/*#__PURE__*/d.default.createElement(f.Root,{"data-rsbs-portal":!0},/*#__PURE__*/d.default.createElement(H,v({},a,{lastSnapRef:y,ref:r,initialState:g.current,onSpringStart:h,onSpringEnd:S}))):null});exports.BottomSheet=A;
//# sourceMappingURL=index.js.map

@@ -11,3 +11,3 @@ {

},
"version": "3.5.3",
"version": "3.5.4",
"main": "dist/index.js",

@@ -14,0 +14,0 @@ "module": "dist/index.es.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc