@plainsheet/react 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,9 +18,7 @@
18
18
 
19
19
  The **minimalistic**, **configurable** bottom sheet for any web project.
20
20
 
21
- ### [Check out our website](https://www.plainsheet.org//), for a quick start guide, APIs, examples, and more!
22
-
23
- ## Why?
21
+ ### [Check out our website](https://www.plainsheet.org//), for a quick start guide, API, examples, and more!
24
22
 
25
23
  ### 🧩 Framework-agnostic
26
24
 
@@ -16,7 +16,13 @@ interface UseBottomSheetReturn {
16
16
  */
17
17
  isOpen: boolean;
18
18
  setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
19
+ open: () => void;
20
+ close: () => void;
21
+ moveTo: MoveTo;
22
+ snapTo: SnapTo;
19
23
  }
24
+ type MoveTo = (...params: Parameters<BottomSheetCore["moveTo"]>) => void;
25
+ type SnapTo = (...params: Parameters<BottomSheetCore["snapTo"]>) => void;
20
26
  interface HookProvidedProps extends UseBottomSheetProps {
21
27
  /**
22
28
  * `ref` of the BottomSheet component. Pass it to the component to use `instance`.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("react"),xt=require("react-dom");function Dt(t){return t!=null}(function(){try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode('.pbs-root{position:fixed;left:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;height:fit-content;max-height:100vh;z-index:2}.pbs-dialog-reset{background-color:transparent;color:inherit;border:none;outline:none;padding:0;margin:0}.pbs-backdrop{position:fixed;top:0;left:0;width:100%;height:100%;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{visibility:hidden}.pbs-backdrop.open{background-color:#454545b3}.pbs-backdrop.transparent{background-color:transparent}.pbs-container{--pbs-container-background-color: rgb(240, 240, 240);background-color:var(--pbs-container-background-color);position:relative;display:none;flex-direction:column;align-items:center;justify-content:flex-start;width:92%;height:fit-content;max-height:100vh;border-radius:10px 10px 0 0}.pbs-container.open{display:flex}.pbs-container .pbs-gap-filler{position:absolute;bottom:calc(-100vh + .5px);left:0;background-color:var(--pbs-container-background-color);content:"";width:100%;height:100vh}.pbs-handle{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;cursor:pointer}.pbs-handle.hidden{display:none}.pbs-button-reset{background-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;border:none}button:focus.pbs-button-reset{outline:none}.pbs-handle-bar{background-color:#a8a8a8;position:relative;width:12%;height:7px;border-radius:12px}.pbs-handle-bar.hidden{display:none}.pbs-content-wrapper{position:relative;width:100%;height:fit-content;max-height:100%;overflow-y:scroll}.pbs-content-wrapper::-webkit-scrollbar{display:none}.example{-ms-overflow-style:none;scrollbar-width:none}')),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var At=Object.defineProperty,Bt=(t,e,n)=>e in t?At(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,V=(t,e,n)=>Bt(t,typeof e!="symbol"?e+"":e,n);function D(t){return typeof t=="string"}function Pt(t,e){return t.classList.contains(et(e))}function X(t,e){t.classList.add(et(e))}function ot(t,e){t.classList.remove(et(e))}function G(t,e,n){D(n)&&(D(e)&&ot(t,e),X(t,n))}function et(t){return D(t)?t.trim().replace(/\./g,""):""}function N(t){return t.map(e=>et(e)).filter(Boolean).join(" ")}function Mt(t){return t.map(e=>e==null?void 0:e.trim()).filter(Boolean).map(e=>`.${e}`).join(" ")}const ut="open",dt="hidden";function nt(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{J(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}J(t,n),t.setAttribute("aria-modal",n?"true":"false")}function J(t,e){e?(X(t,ut),ot(t,dt)):(X(t,dt),ot(t,ut))}function St(t){return t instanceof HTMLElement}function A(t){return typeof t=="number"&&!Number.isNaN(t)}function Yt(t){St(t)&&t.focus()}function It(t){if(!St(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=A(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),r=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||r||n>-1}var w=(t=>(t.Backdrop="pbs-backdrop",t.Root="pbs-root",t.Container="pbs-container",t.GapFiller="pbs-gap-filler",t.Handle="pbs-handle",t.HandleBar="pbs-handle-bar",t.ContentWrapper="pbs-content-wrapper",t))(w||{}),rt=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(rt||{}),K=(t=>(t.Hidden="hidden",t))(K||{});function M(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(r=>{X(o,r)}),D(n)&&o.setAttribute("data-testid",n),o}Mt([w.Root,w.ContentWrapper]);function ht(t,e,n,o){switch(o){case"content-height":return e>=t?Et(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function Ct(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function yt(t,e){return e<t?-(t-e):e-t}function Q(t,e){return t>e?t-e:e-t}function Rt(t,e){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function pt(t,e,n){const o=t==="above";return n.filter(r=>{const a=r*e.viewportHeight;return o?e.visibleHeight<a:e.visibleHeight>a})}function Et(t,e,n){return-(t-e)+n}function mt(t){return Number(t.replace("px",""))}function Z(t,...e){return Number(t.toFixed(...e))}function wt(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const r=o[1],a=o[2].split(",").map(i=>i.trim());n.push({type:r,values:a})}return n}function Nt(t){const e=t.style.transform,n=wt(e);return{transform:e,transformValues:n}}function Tt(t,e){return t.find(o=>o.type.startsWith(e))||null}const it="translate";function P(t){const e=t.style.transform,n=wt(e),o=Tt(n,it);return Ht(o??{type:it,values:[]})}function tt(t,{x:e,y:n}){const{transform:o,transformValues:r}=Nt(t),a=Tt(r,it);if(a){const i=Ht(a);t.style.transform=`translate(${e??i.x??0}px,${n??i.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${e??0}px,${n??0}px)`;return}t.style.transform=`translate(${e??0}px,${n??0}px)`}function Ht(t){if(t.type!=="translate")throw new Error(`Could not get coordinates from ${t.type}, since is not translate.`);const e=t.values[0],n=t.values[1];return{x:mt(e)??0,y:mt(n)??0}}function at(t){return t!=null}function ft(t,{min:e,max:n}){return at(n)&&t>=n?n:at(e)&&t<=e?e:t}const Ft=(t,e,n)=>{e instanceof HTMLElement&&!Pt(e,w.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Wt=(t,e,n,o)=>r=>{o.startY=t.getCoordinates(r).y,o.containerStartTranslate=P(e),n.onDragStart()},Ut=(t,e,n,o,r)=>a=>{jt(a,t,n,o,r,e,n.marginTop)};function jt(t,e,n,o,r,a,i){if(!o.isDragging||!A(o.startY))return;const s=e.getCoordinates(t).y,u=yt(o.startY,s),p=window.innerHeight,c=a.clientHeight,m=c-(o.containerStartTranslate.y+u);if(m>=p)return;const S=Ct(o.startY,s);if(S.isUp&&!n.expandable&&m>=c)return;r.start(()=>{tt(a,{y:o.containerStartTranslate.y+u})},0);const l=p-i,C=c-o.containerStartTranslate.y;if(S.isUp){const b=l-C,v=l-m,y=ft(1-Z(v/b,2),{min:0,max:1});n.onDragMove(S,y)}else if(S.isDown){const b=ft(Z(1-m/C,2),{min:0,max:1});n.onDragMove(S,b)}}const $t=(t,e,n,o,r,a,i)=>s=>{if(!o.isDragging||(o.isDragging=!1,!A(o.startY)))return;n.onDragEnd();const u=o.startY,p=t.getCoordinates(s).y,c=P(e).y,m=Ct(u,p),S=window.innerHeight,l=e.clientHeight;if(m.isUp){const C=[...n.snapPoints].sort((y,O)=>y-O),b=l+-c;if(!n.expandable&&b>=l)return;for(const y of C){const O=y*window.innerHeight;if(b<=O){const T=Q(b,O);i.translateContainer({startY:c,endY:c-T,animationFrame:r,bottomSheetContainer:e});return}}const v=Et(S,l,n.marginTop);i.translateContainer({startY:c,endY:v,animationFrame:r,bottomSheetContainer:e})}else if(m.isDown){const C=[...n.snapPoints].sort((b,v)=>v-b);for(const b of C){const v=b*window.innerHeight,y=l+-c;if(y>=v){const O=Q(y,v);i.translateContainer({startY:c,endY:c+O,animationFrame:r,bottomSheetContainer:e});return}}a()}};var U=(t=>(t[t.All=-1]="All",t[t.None=0]="None",t[t.Capture=1]="Capture",t[t.Target=2]="Target",t[t.Bubble=3]="Bubble",t))(U||{});function gt(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const Gt={eventPhase:U.All};class _{constructor(e){V(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=Gt,onMove:o,onEnd:r}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("touchstart",a=>{if(n.eventPhase===U.All){e(a);return}gt(a.eventPhase)===n.eventPhase&&e(a)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),r&&this.currentTarget.addEventListener("touchend",r)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("mousedown",a=>{if(n.eventPhase===U.All){e(a);return}gt(a.eventPhase)===n.eventPhase&&e(a)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),r&&this.currentTarget.addEventListener("mouseup",a=>{r(a)})}removeEventListeners({onStart:e,onMove:n,onEnd:o}){e&&this.currentTarget.removeEventListener("touchstart",e),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),e&&this.currentTarget.removeEventListener("mousedown",e),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(e){if(e.type==="touchstart"||e.type==="mousedown"){if("touches"in e)return{x:e.touches[0].clientX,y:e.touches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}if(e.type==="touchend"||e.type==="mouseup"||e.type==="mousemove"||e.type==="touchmove"){if("touches"in e)return{x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}return{x:0,y:0}}}function kt(t){const e=t;return`${e} ${e} 0px 0px`}function _t(t,e){const n=Xt(t);qt(n),n.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const r=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${r}px`,n.bottomSheetContentWrapper.appendChild(o);const a=zt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:a}}function Xt(t){const e=M("dialog",N([w.Root,rt.Dialog,t.rootClass]),w.Root);e.ariaLabel=t.ariaLabel;const n=M("section",N([w.Container,t.containerClass]),w.Container);t.containerBorderRadius&&(n.style.borderRadius=kt(t.containerBorderRadius));const o=M("div",w.GapFiller,w.GapFiller),r=M("button",N([w.Handle,rt.Button,t.shouldShowHandle?null:K.Hidden,t.handleClass]),w.Handle);r.setAttribute("type","button"),r.ariaLabel="bottom sheet close button";const a=M("span",N([w.HandleBar,t.shouldShowHandle?null:K.Hidden]),w.HandleBar),i=M("article",N([w.ContentWrapper,t.contentWrapperClass]),w.ContentWrapper),s=M("div",N([w.Backdrop,t.backdropClass,K.Hidden]),w.Backdrop);return t.backdropColor&&(s.style.backgroundColor=t.backdropColor),t.backDropTransition&&(s.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:s,bottomSheetContainer:n,bottomSheetHandle:r,bottomSheetHandleBar:a,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:o}}function qt({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:r,bottomSheetContainerGapFiller:a}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(r),e.appendChild(a)}function zt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:r,bottomSheetHandle:a,bottomSheetContainerGapFiller:i,bottomSheetContentWrapper:s,bottomSheetBackdrop:u}=t,{animationFrame:p}=n,c=new _(a),m=new _(s),S=new _(i),l=e.dragTriggers.reduce((k,x)=>{const E=o.querySelectorAll(x);if(!E.length)return k;const h=Array.from(E).map(d=>d instanceof HTMLElement?new _(d):null).filter(d=>!!d);return[...k,...h]},[]),C=new _(window),b=Wt(C,r,e,n.draggingState),v=Ut(C,r,e,n.draggingState,p),y=$t(C,r,e,n.draggingState,p,n.onClose,n.bottomSheetState);function O(k){k.target instanceof Element&&!o.contains(k.target)&&n.onClose()}function T(k){Ft(n.draggingState,k.target,t.bottomSheetContentWrapper)}function Y(k){const x=k??e;x.draggable&&(c.addEventListeners({onStart:T}),l.forEach(E=>{E.addEventListeners({onStart:T,onStartOptions:{eventPhase:U.Target}})})),x.draggable&&x.backgroundDraggable&&(m.addEventListeners({onStart:T,onStartOptions:{eventPhase:U.Target}}),S.addEventListeners({onStart:T})),x.draggable&&C.addEventListeners({onStart:b,onMove:v,onEnd:y}),x.draggable&&window.document.addEventListener("keyup",E=>{E.key==="Escape"&&n.onClose()}),a.addEventListener("keyup",E=>{if(E.key==="ArrowUp"){n.moveUp();return}if(E.key==="ArrowDown"){n.moveDown();return}if(E.shiftKey&&E.key==="Tab"){const h=I(t.bottomSheetContentWrapper);Yt(h)}})}function q(){e.shouldCloseOnOutsideClick?u.addEventListener("click",O):u.style.pointerEvents="none"}function $(){u.removeEventListener("click",O)}function I(k){let x=[...Array.from(k.childNodes).reverse()];for(;x.length;){const E=x.shift();if(It(E))return E;E&&(x=[...x,...Array.from(E.childNodes).reverse()])}return null}function z(){c.removeEventListeners({onStart:T}),m.removeEventListeners({onStart:T}),S.removeEventListeners({onStart:T}),l.forEach(k=>{k.removeEventListeners({onStart:T})}),C.removeEventListeners({onStart:b,onMove:v,onEnd:y})}return{attachEventListeners:Y,clearEventListeners:z,attacheOnOpenEventListeners:q,clearOnOpenEventListeners:$}}class Vt{constructor(){V(this,"animationId"),V(this,"isInProgress"),V(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const r=a=>{this.startedAt||(this.startedAt=a);const i=a-this.startedAt,s=n===0?1:Z(i/n,2),u=s>=1&&!o;e(s),u?this.stop():this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}stop(){this.isInProgress=!1,this.startedAt=null,A(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Kt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:r,onEnd:a,animationTimingFunction:i,animationDuration:s}=t,u=yt(e,n);r.stop();let p=!1;r.start(c=>{tt(o,{y:e+u*i(c)}),!p&&c>=1&&(a==null||a(),p=!0)},s)}const st=(t,e)=>n=>{Kt({...n,animationTimingFunction:t,animationDuration:e})},W={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Jt(t){return!(!A(t)||t>1||t<0)}function Qt(t,e){const n={set(o,r,a,i){return e(r,a),Reflect.set(o,r,a,i)}};return new Proxy(t,n)}function Zt(...t){console.error(t)}const F={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function te(t){for(const e of Object.values(F))if(e===t)return!0;return!1}function Lt(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&A(t.p1x)&&A(t.p1y)&&A(t.p2x)&&A(t.p2y))}function j(t,e,n,o){return function(s){return i(r(s))};function r(s){let u=0,p=1,c=s,m;if(s===0||s===1)return s;for(;u<p;){if(m=a(c),Math.abs(m-s)<.001)return c;s>m?u=c:p=c,c=(p+u)/2}return c}function a(s){return 3*t*s*Math.pow(1-s,2)+3*n*Math.pow(s,2)*(1-s)+Math.pow(s,3)}function i(s){return 3*e*s*Math.pow(1-s,2)+3*o*Math.pow(s,2)*(1-s)+Math.pow(s,3)}}const bt=j(.25,.1,.25,1),ee=j(.42,0,1,1),Ot=j(.42,0,.58,1),ne=j(.4,.1,.6,1),oe=j(.45,1.5,.55,1);function re(t){switch(t){case F.EASE:return bt;case F.EASE_IN:return ee;case F.EASE_OUT:return Ot;case F.EASE_IN_OUT:return ne;case F.SPRING:return oe;default:return bt}}function vt(t){return typeof t=="boolean"}const ie={ariaLabel:"Bottom sheet",content:"",defaultPosition:W.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180};function ae(t){const e={...ie},n=Object.entries(t).reduce((o,r)=>{const[a,i]=r;return at(i)&&(o[a]=i),o},{});return{...e,...n}}function ct(t){if(Lt(t)){const{p1x:e,p1y:n,p2x:o,p2y:r}=t;return j(e,n,o,r)}return te(t)?re(t):Ot}function se(t,e,n,o){function r(a,i){switch(a){case"content":D(i)&&(t.bottomSheetContentWrapper.innerHTML=i);break;case"width":D(i)&&(t.bottomSheetContainer.style.width=i);break;case"shouldShowHandle":vt(i)||J(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":vt(i)||J(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":D(i)&&(t.bottomSheetContainer.style.borderRadius=kt(i));break;case"backdropColor":D(i)&&(t.bottomSheetBackdrop.style.backgroundColor=i);break;case"backDropTransition":D(i)&&(t.bottomSheetBackdrop.style.transition=i);break;case"rootClass":if(!D(i))return;G(t.bottomSheetRoot,n.rootClass,i);break;case"containerClass":if(!D(i))return;G(t.bottomSheetContainer,n.containerClass,i);break;case"handleClass":if(!D(i))return;G(t.bottomSheetHandle,n.handleClass,i);break;case"contentWrapperClass":if(!D(i))return;G(t.bottomSheetContentWrapper,n.contentWrapperClass,i);break;case"backdropClass":if(!D(i))return;G(t.bottomSheetBackdrop,n.backdropClass,i);break;case"expandable":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggable":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggingAnimationTimings":if(Lt(i)){const s=ct(i),u=st(s,n.draggingAnimationDuration);e.translateContainer=u}break;case"draggingAnimationDuration":if(A(i)){const s=ct(n.draggingAnimationTimings),u=st(s,i);e.translateContainer=u}break}}return r}function ce(t){const e=ae(t),n=ct(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:st(n,e.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function a(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const i=new Vt,s={animationFrame:i,onClose:y,bottomSheetState:o,draggingState:r,snapTo:E,moveUp:k,moveDown:x},{elements:u,eventHandlers:p}=_t(e,s),c=Qt(e,se(u,o,e,p)),{bottomSheetBackdrop:m,bottomSheetRoot:S,bottomSheetContainer:l}=u,C=h=>{const d=h??window.document.body;d.appendChild(S),d.appendChild(m);const f=window.innerHeight;tt(l,{y:f}),p.attachEventListeners(),o.isMounted=!0},b=()=>{p.clearEventListeners(),Object.values(u).forEach(h=>{h.remove()}),a(),o.isMounted=!1},v=()=>{var h;if(O()||Zt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(h=t.beforeOpen)==null||h.call(t),T())return;nt(m,!0),c.shouldShowBackdrop||X(m,"transparent"),nt([l],!0),tt(l,{y:l.clientHeight});const d=window.innerHeight,f=ht(d,l.clientHeight,c.marginTop,c.defaultPosition),g=P(l).y;o.translateContainer({startY:g,endY:f,animationFrame:i,bottomSheetContainer:l,onEnd:t.afterOpen});const H=document.body.style.overflowY;r.originalDocumentOverflowY=H||"initial";const B=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=B||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",u.bottomSheetHandle.focus(),p.attacheOnOpenEventListeners()};function y(){var h;if(Y())return;(h=t.beforeClose)==null||h.call(t);const d=P(l).y,f=l.clientHeight;o.translateContainer({startY:d,endY:f,animationFrame:i,bottomSheetContainer:l,onEnd:()=>{var g;(g=t.afterClose)==null||g.call(t),nt([m,l],!1),p.clearOnOpenEventListeners()}}),a()}function O(){return o.isMounted}function T(){const h=P(l).y,d=window.innerHeight,f=l.clientHeight>=d?d:l.clientHeight;return h<=f}function Y(){return!T()}function q(){const h=P(l).y,d=l.clientHeight,f=window.innerHeight;if(h<=5&&h>=-5)return W.CONTENT_HEIGHT;const g=d-h;if(g===f/2)return W.MIDDLE;const H=f-c.marginTop,B=10;return g<=H+B&&g>=H-B?W.TOP:W.CLOSED}function $(){return l.clientHeight}function I(h){if(!T())return;const d=P(l).y,f=l.clientHeight-d,g=window.innerHeight-h,H=Rt(f,g),B=Q(f,g);o.translateContainer({startY:d,endY:d+(H.isUp?-B:B),animationFrame:i,bottomSheetContainer:l})}function z(h,{viewportHeight:d,visibleHeight:f}){let g=null;for(const H of h){const B=H*d,R=Q(f,B);(g===null||R<g)&&(g=R)}return{minOffset:g}}function k(){const h=[...c.snapPoints].reverse(),d=P(l).y,f=l.clientHeight,g=f-d;if(!c.expandable&&g>=f)return;const H=window.innerHeight,B=pt("above",{visibleHeight:g,viewportHeight:H},h),{minOffset:R}=z(B,{visibleHeight:g,viewportHeight:H});if(R===null&&g<H-c.marginTop){o.translateContainer({startY:d,endY:ht(H,f,c.marginTop,"top"),animationFrame:i,bottomSheetContainer:l});return}A(R)&&o.translateContainer({startY:d,endY:d-R,animationFrame:i,bottomSheetContainer:l})}function x(){const h=P(l).y,d=l.clientHeight-h;if(d<1)return;const f=window.innerHeight,g=pt("below",{visibleHeight:d,viewportHeight:f},c.snapPoints),{minOffset:H}=z(g,{visibleHeight:d,viewportHeight:f});A(H)&&o.translateContainer({startY:h,endY:h+H,animationFrame:i,bottomSheetContainer:l})}function E(h){const d=window.innerHeight;if(!Jt(h))return;const f=Z(d*h,2);I(f)}return{props:c,elements:u,mount:C,unmount:b,open:v,close:y,getIsMounted:O,getIsOpen:T,getIsClosed:Y,getPosition:q,getHeight:$,moveTo:I,snapTo:E}}function lt(){return{elements:{bottomSheetRoot:void 0,bottomSheetBackdrop:void 0,bottomSheetContainer:void 0,bottomSheetHandle:void 0,bottomSheetHandleBar:void 0,bottomSheetContentWrapper:void 0,bottomSheetContainerGapFiller:void 0},mount:()=>{},unmount:()=>{},open:()=>{},close:()=>{},getIsMounted:()=>!1,getHeight:()=>0,getIsOpen:()=>!1,getIsClosed:()=>!0,getPosition:()=>W.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const le=lt(),ue=L.forwardRef(function(e,n){const{children:o,isOpen:r,setIsOpen:a,afterClose:i,mountingPointRef:s,...u}=e,p=L.useRef(le),[c,m]=L.useState(p.current);L.useImperativeHandle(n,()=>c,[c]);const S=L.useCallback(()=>{a(!1),i==null||i()},[i]);L.useEffect(()=>{r?c.open():c.close()},[r]);const l=L.useRef(null);return L.useEffect(function(){var y;if(s&&!s.current)return;const b=Dt((y=e.mountingPointRef)==null?void 0:y.current)?e.mountingPointRef.current:window.document.body;if(!b||c.getIsMounted())return;const v=ce({content:"",...u,afterClose:S});return v.mount(b),l.current=v.elements.bottomSheetContentWrapper??null,p.current=v,m(v),()=>{c.unmount()}},[e.mountingPointRef,u,S]),L.useEffect(function(){Object.assign(p.current.props,{...u}),m(p.current)},[u]),L.useEffect(function(){return()=>{p.current.unmount()}},[]),l.current?xt.createPortal(e.children,l.current):null}),de=lt();function he(t={}){const e=L.useRef(de),[n,o]=L.useState(!1),[r,a]=L.useState(e.current);L.useEffect(()=>{a(e.current)},[e.current]);const{beforeOpen:i,afterOpen:s,beforeClose:u,afterClose:p,onDragStart:c,onDragMove:m,onDragEnd:S,...l}=t,C=()=>{i==null||i()},b=()=>{s==null||s(),o(!0)},v=()=>{u==null||u()},y=()=>{p==null||p(),o(!1)},O=()=>{c==null||c()},T=($,I)=>{m==null||m($,I)},Y=()=>{S==null||S()};return{props:L.useMemo(()=>({ref:e,isOpen:n,setIsOpen:o,beforeOpen:C,afterOpen:b,beforeClose:v,afterClose:y,onDragStart:O,onDragMove:T,onDragEnd:Y,...l}),[e.current,n,o,t]),instance:r,isOpen:n,setIsOpen:o}}exports.BottomSheet=ue;exports.createPlaceholderBottomSheet=lt;exports.useBottomSheet=he;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react"),xt=require("react-dom");function At(t){return t!=null}(function(){try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode('.pbs-root{position:fixed;left:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;height:fit-content;max-height:100vh;z-index:2}.pbs-dialog-reset{background-color:transparent;color:inherit;border:none;outline:none;padding:0;margin:0}.pbs-backdrop{position:fixed;top:0;left:0;width:100%;height:100%;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{visibility:hidden}.pbs-backdrop.open{background-color:#454545b3}.pbs-backdrop.transparent{background-color:transparent}.pbs-container{--pbs-container-background-color: rgb(240, 240, 240);background-color:var(--pbs-container-background-color);position:relative;display:none;flex-direction:column;align-items:center;justify-content:flex-start;width:92%;height:fit-content;max-height:100vh;border-radius:10px 10px 0 0}.pbs-container.open{display:flex}.pbs-container .pbs-gap-filler{position:absolute;bottom:calc(-100vh + .5px);left:0;background-color:var(--pbs-container-background-color);content:"";width:100%;height:100vh}.pbs-handle{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;cursor:pointer}.pbs-handle.hidden{display:none}.pbs-button-reset{background-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;border:none}button:focus.pbs-button-reset{outline:none}.pbs-handle-bar{background-color:#a8a8a8;position:relative;width:12%;height:7px;border-radius:12px}.pbs-handle-bar.hidden{display:none}.pbs-content-wrapper{position:relative;width:100%;height:fit-content;max-height:100%;overflow-y:scroll}.pbs-content-wrapper::-webkit-scrollbar{display:none}.example{-ms-overflow-style:none;scrollbar-width:none}')),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var Dt=Object.defineProperty,Bt=(t,e,n)=>e in t?Dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,V=(t,e,n)=>Bt(t,typeof e!="symbol"?e+"":e,n);function A(t){return typeof t=="string"}function Mt(t,e){return t.classList.contains(et(e))}function z(t,e){t.classList.add(et(e))}function ot(t,e){t.classList.remove(et(e))}function X(t,e,n){A(n)&&(A(e)&&ot(t,e),z(t,n))}function et(t){return A(t)?t.trim().replace(/\./g,""):""}function N(t){return t.map(e=>et(e)).filter(Boolean).join(" ")}function Pt(t){return t.map(e=>e==null?void 0:e.trim()).filter(Boolean).map(e=>`.${e}`).join(" ")}const ut="open",dt="hidden";function nt(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{J(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}J(t,n),t.setAttribute("aria-modal",n?"true":"false")}function J(t,e){e?(z(t,ut),ot(t,dt)):(z(t,dt),ot(t,ut))}function St(t){return t instanceof HTMLElement}function D(t){return typeof t=="number"&&!Number.isNaN(t)}function Yt(t){St(t)&&t.focus()}function It(t){if(!St(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=D(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),r=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||r||n>-1}var H=(t=>(t.Backdrop="pbs-backdrop",t.Root="pbs-root",t.Container="pbs-container",t.GapFiller="pbs-gap-filler",t.Handle="pbs-handle",t.HandleBar="pbs-handle-bar",t.ContentWrapper="pbs-content-wrapper",t))(H||{}),rt=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(rt||{}),K=(t=>(t.Hidden="hidden",t))(K||{});function P(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(r=>{z(o,r)}),A(n)&&o.setAttribute("data-testid",n),o}Pt([H.Root,H.ContentWrapper]);function pt(t,e,n,o){switch(o){case"content-height":return e>=t?Et(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function yt(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function Ct(t,e){return e<t?-(t-e):e-t}function Q(t,e){return t>e?t-e:e-t}function Rt(t,e){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function ht(t,e,n){const o=t==="above";return n.filter(r=>{const i=r*e.viewportHeight;return o?e.visibleHeight<i:e.visibleHeight>i})}function Et(t,e,n){return-(t-e)+n}function mt(t){return Number(t.replace("px",""))}function Z(t,...e){return Number(t.toFixed(...e))}function wt(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const r=o[1],i=o[2].split(",").map(a=>a.trim());n.push({type:r,values:i})}return n}function Wt(t){const e=t.style.transform,n=wt(e);return{transform:e,transformValues:n}}function kt(t,e){return t.find(o=>o.type.startsWith(e))||null}const at="translate";function M(t){const e=t.style.transform,n=wt(e),o=kt(n,at);return Ht(o??{type:at,values:[]})}function tt(t,{x:e,y:n}){const{transform:o,transformValues:r}=Wt(t),i=kt(r,at);if(i){const a=Ht(i);t.style.transform=`translate(${e??a.x??0}px,${n??a.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${e??0}px,${n??0}px)`;return}t.style.transform=`translate(${e??0}px,${n??0}px)`}function Ht(t){if(t.type!=="translate")throw new Error(`Could not get coordinates from ${t.type}, since is not translate.`);const e=t.values[0],n=t.values[1];return{x:mt(e)??0,y:mt(n)??0}}function it(t){return t!=null}function bt(t,{min:e,max:n}){return it(n)&&t>=n?n:it(e)&&t<=e?e:t}const Nt=(t,e,n)=>{e instanceof HTMLElement&&!Mt(e,H.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Ft=(t,e,n,o)=>r=>{o.startY=t.getCoordinates(r).y,o.containerStartTranslate=M(e),n.onDragStart()},jt=(t,e,n,o,r)=>i=>{Ut(i,t,n,o,r,e,n.marginTop)};function Ut(t,e,n,o,r,i,a){if(!o.isDragging||!D(o.startY))return;const s=e.getCoordinates(t).y,u=Ct(o.startY,s),h=window.innerHeight,c=i.clientHeight,m=c-(o.containerStartTranslate.y+u);if(m>=h)return;const C=yt(o.startY,s);if(C.isUp&&!n.expandable&&m>=c)return;r.start(()=>{tt(i,{y:o.containerStartTranslate.y+u})},0);const l=h-a,E=c-o.containerStartTranslate.y;if(C.isUp){const g=l-E,S=l-m,w=bt(1-Z(S/g,2),{min:0,max:1});n.onDragMove(C,w)}else if(C.isDown){const g=bt(Z(1-m/E,2),{min:0,max:1});n.onDragMove(C,g)}}const $t=(t,e,n,o,r,i,a)=>s=>{if(!o.isDragging||(o.isDragging=!1,!D(o.startY)))return;n.onDragEnd();const u=o.startY,h=t.getCoordinates(s).y,c=M(e).y,m=yt(u,h),C=window.innerHeight,l=e.clientHeight;if(m.isUp){const E=[...n.snapPoints].sort((w,x)=>w-x),g=l+-c;if(!n.expandable&&g>=l)return;for(const w of E){const x=w*window.innerHeight;if(g<=x){const T=Q(g,x);a.translateContainer({startY:c,endY:c-T,animationFrame:r,bottomSheetContainer:e});return}}const S=Et(C,l,n.marginTop);a.translateContainer({startY:c,endY:S,animationFrame:r,bottomSheetContainer:e})}else if(m.isDown){const E=[...n.snapPoints].sort((g,S)=>S-g);for(const g of E){const S=g*window.innerHeight,w=l+-c;if(w>=S){const x=Q(w,S);a.translateContainer({startY:c,endY:c+x,animationFrame:r,bottomSheetContainer:e});return}}i()}};var U=(t=>(t[t.All=-1]="All",t[t.None=0]="None",t[t.Capture=1]="Capture",t[t.Target=2]="Target",t[t.Bubble=3]="Bubble",t))(U||{});function ft(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const Gt={eventPhase:U.All};class q{constructor(e){V(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=Gt,onMove:o,onEnd:r}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("touchstart",i=>{if(n.eventPhase===U.All){e(i);return}ft(i.eventPhase)===n.eventPhase&&e(i)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),r&&this.currentTarget.addEventListener("touchend",r)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("mousedown",i=>{if(n.eventPhase===U.All){e(i);return}ft(i.eventPhase)===n.eventPhase&&e(i)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),r&&this.currentTarget.addEventListener("mouseup",i=>{r(i)})}removeEventListeners({onStart:e,onMove:n,onEnd:o}){e&&this.currentTarget.removeEventListener("touchstart",e),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),e&&this.currentTarget.removeEventListener("mousedown",e),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(e){if(e.type==="touchstart"||e.type==="mousedown"){if("touches"in e)return{x:e.touches[0].clientX,y:e.touches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}if(e.type==="touchend"||e.type==="mouseup"||e.type==="mousemove"||e.type==="touchmove"){if("touches"in e)return{x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}return{x:0,y:0}}}function Tt(t){const e=t;return`${e} ${e} 0px 0px`}function _t(t,e){const n=Xt(t);qt(n),n.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const r=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${r}px`,n.bottomSheetContentWrapper.appendChild(o);const i=zt({bottomSheetElements:n,bottomSheetProps:t,options:e});return t.rootStyle&&Object.assign(n.bottomSheetRoot.style,t.rootStyle),t.backdropStyle&&Object.assign(n.bottomSheetBackdrop.style,t.backdropStyle),t.containerStyle&&Object.assign(n.bottomSheetContainer.style,t.containerStyle),t.handleStyle&&Object.assign(n.bottomSheetHandleBar.style,t.handleStyle),t.contentWrapperStyle&&Object.assign(n.bottomSheetContentWrapper.style,t.contentWrapperStyle),{elements:n,eventHandlers:i}}function Xt(t){const e=P("dialog",N([H.Root,rt.Dialog,t.rootClass]),H.Root);e.ariaLabel=t.ariaLabel;const n=P("section",N([H.Container,t.containerClass]),H.Container);t.containerBorderRadius&&(n.style.borderRadius=Tt(t.containerBorderRadius));const o=P("div",H.GapFiller,H.GapFiller),r=P("button",N([H.Handle,rt.Button,t.shouldShowHandle?null:K.Hidden,t.handleClass]),H.Handle);r.setAttribute("type","button"),r.ariaLabel="bottom sheet close button";const i=P("span",N([H.HandleBar,t.shouldShowHandle?null:K.Hidden]),H.HandleBar),a=P("article",N([H.ContentWrapper,t.contentWrapperClass]),H.ContentWrapper),s=P("div",N([H.Backdrop,t.backdropClass,K.Hidden]),H.Backdrop);return t.backdropColor&&(s.style.backgroundColor=t.backdropColor),t.backDropTransition&&(s.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:s,bottomSheetContainer:n,bottomSheetHandle:r,bottomSheetHandleBar:i,bottomSheetContentWrapper:a,bottomSheetContainerGapFiller:o}}function qt({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:r,bottomSheetContainerGapFiller:i}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(r),e.appendChild(i)}function zt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:r,bottomSheetHandle:i,bottomSheetContainerGapFiller:a,bottomSheetContentWrapper:s,bottomSheetBackdrop:u}=t,{animationFrame:h}=n,c=new q(i),m=new q(s),C=new q(a),l=e.dragTriggers.reduce((O,y)=>{const v=o.querySelectorAll(y);if(!v.length)return O;const p=Array.from(v).map(d=>d instanceof HTMLElement?new q(d):null).filter(d=>!!d);return[...O,...p]},[]),E=new q(window),g=Ft(E,r,e,n.draggingState),S=jt(E,r,e,n.draggingState,h),w=$t(E,r,e,n.draggingState,h,n.onClose,n.bottomSheetState);function x(O){O.target instanceof Element&&!o.contains(O.target)&&n.onClose()}function T(O){Nt(n.draggingState,O.target,t.bottomSheetContentWrapper)}function Y(O){const y=O??e;y.draggable&&(c.addEventListeners({onStart:T}),l.forEach(v=>{v.addEventListeners({onStart:T,onStartOptions:{eventPhase:U.Target}})})),y.draggable&&y.backgroundDraggable&&(m.addEventListeners({onStart:T,onStartOptions:{eventPhase:U.Target}}),C.addEventListeners({onStart:T})),y.draggable&&E.addEventListeners({onStart:g,onMove:S,onEnd:w}),y.draggable&&window.document.addEventListener("keyup",v=>{v.key==="Escape"&&n.onClose()}),i.addEventListener("keyup",v=>{if(v.key==="ArrowUp"){n.moveUp();return}if(v.key==="ArrowDown"){n.moveDown();return}if(v.shiftKey&&v.key==="Tab"){const p=I(t.bottomSheetContentWrapper);Yt(p)}})}function G(){e.shouldCloseOnOutsideClick?u.addEventListener("click",x):u.style.pointerEvents="none"}function _(){u.removeEventListener("click",x)}function I(O){let y=[...Array.from(O.childNodes).reverse()];for(;y.length;){const v=y.shift();if(It(v))return v;v&&(y=[...y,...Array.from(v.childNodes).reverse()])}return null}function R(){c.removeEventListeners({onStart:T}),m.removeEventListeners({onStart:T}),C.removeEventListeners({onStart:T}),l.forEach(O=>{O.removeEventListeners({onStart:T})}),E.removeEventListeners({onStart:g,onMove:S,onEnd:w})}return{attachEventListeners:Y,clearEventListeners:R,attacheOnOpenEventListeners:G,clearOnOpenEventListeners:_}}class Vt{constructor(){V(this,"animationId"),V(this,"isInProgress"),V(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const r=i=>{this.startedAt||(this.startedAt=i);const a=i-this.startedAt,s=n===0?1:Z(a/n,2),u=s>=1&&!o;e(s),u?this.stop():this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}stop(){this.isInProgress=!1,this.startedAt=null,D(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Kt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:r,onEnd:i,animationTimingFunction:a,animationDuration:s}=t,u=Ct(e,n);r.stop();let h=!1;r.start(c=>{tt(o,{y:e+u*a(c)}),!h&&c>=1&&(i==null||i(),h=!0)},s)}const st=(t,e)=>n=>{Kt({...n,animationTimingFunction:t,animationDuration:e})},j={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Jt(t){return!(!D(t)||t>1||t<0)}function Qt(t,e){const n={set(o,r,i,a){return e(r,i),Reflect.set(o,r,i,a)}};return new Proxy(t,n)}function Zt(...t){console.error(t)}const F={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function te(t){for(const e of Object.values(F))if(e===t)return!0;return!1}function Ot(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&D(t.p1x)&&D(t.p1y)&&D(t.p2x)&&D(t.p2y))}function $(t,e,n,o){return function(s){return a(r(s))};function r(s){let u=0,h=1,c=s,m;if(s===0||s===1)return s;for(;u<h;){if(m=i(c),Math.abs(m-s)<.001)return c;s>m?u=c:h=c,c=(h+u)/2}return c}function i(s){return 3*t*s*Math.pow(1-s,2)+3*n*Math.pow(s,2)*(1-s)+Math.pow(s,3)}function a(s){return 3*e*s*Math.pow(1-s,2)+3*o*Math.pow(s,2)*(1-s)+Math.pow(s,3)}}const gt=$(.25,.1,.25,1),ee=$(.42,0,1,1),Lt=$(.42,0,.58,1),ne=$(.4,.1,.6,1),oe=$(.45,1.5,.55,1);function re(t){switch(t){case F.EASE:return gt;case F.EASE_IN:return ee;case F.EASE_OUT:return Lt;case F.EASE_IN_OUT:return ne;case F.SPRING:return oe;default:return gt}}function vt(t){return typeof t=="boolean"}const ae={ariaLabel:"Bottom sheet",content:"",defaultPosition:j.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180,rootStyle:{},containerStyle:{},handleStyle:{},contentWrapperStyle:{},backdropStyle:{}};function ie(t){const e={...ae},n=Object.entries(t).reduce((o,r)=>{const[i,a]=r;return it(a)&&(o[i]=a),o},{});return{...e,...n}}function ct(t){if(Ot(t)){const{p1x:e,p1y:n,p2x:o,p2y:r}=t;return $(e,n,o,r)}return te(t)?re(t):Lt}function se(t,e,n,o){function r(i,a){switch(i){case"content":A(a)&&(t.bottomSheetContentWrapper.innerHTML=a);break;case"width":A(a)&&(t.bottomSheetContainer.style.width=a);break;case"shouldShowHandle":vt(a)||J(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":vt(a)||J(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":A(a)&&(t.bottomSheetContainer.style.borderRadius=Tt(a));break;case"backdropColor":A(a)&&(t.bottomSheetBackdrop.style.backgroundColor=a);break;case"backDropTransition":A(a)&&(t.bottomSheetBackdrop.style.transition=a);break;case"rootClass":if(!A(a))return;X(t.bottomSheetRoot,n.rootClass,a);break;case"containerClass":if(!A(a))return;X(t.bottomSheetContainer,n.containerClass,a);break;case"handleClass":if(!A(a))return;X(t.bottomSheetHandle,n.handleClass,a);break;case"contentWrapperClass":if(!A(a))return;X(t.bottomSheetContentWrapper,n.contentWrapperClass,a);break;case"backdropClass":if(!A(a))return;X(t.bottomSheetBackdrop,n.backdropClass,a);break;case"expandable":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggable":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggingAnimationTimings":if(Ot(a)){const s=ct(a),u=st(s,n.draggingAnimationDuration);e.translateContainer=u}break;case"draggingAnimationDuration":if(D(a)){const s=ct(n.draggingAnimationTimings),u=st(s,a);e.translateContainer=u}break;case"rootStyle":n.rootStyle&&Object.assign(t.bottomSheetRoot.style,n.rootStyle);break;case"backdropStyle":n.backdropStyle&&Object.assign(t.bottomSheetBackdrop.style,n.backdropStyle);break;case"containerStyle":n.containerStyle&&Object.assign(t.bottomSheetContainer.style,n.containerStyle);break;case"handleStyle":n.handleStyle&&Object.assign(t.bottomSheetHandleBar.style,n.handleStyle);break;case"contentWrapperStyle":n.contentWrapperStyle&&Object.assign(t.bottomSheetContentWrapper.style,n.contentWrapperStyle);break}}return r}function ce(t){const e=ie(t),n=ct(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:st(n,e.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function i(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const a=new Vt,s={animationFrame:a,onClose:w,bottomSheetState:o,draggingState:r,snapTo:v,moveUp:O,moveDown:y},{elements:u,eventHandlers:h}=_t(e,s),c=Qt(e,se(u,o,e,h)),{bottomSheetBackdrop:m,bottomSheetRoot:C,bottomSheetContainer:l}=u,E=p=>{const d=p??window.document.body;d.appendChild(C),d.appendChild(m);const b=window.innerHeight;tt(l,{y:b}),h.attachEventListeners(),o.isMounted=!0},g=()=>{h.clearEventListeners(),Object.values(u).forEach(p=>{p.remove()}),i(),o.isMounted=!1},S=()=>{var p;if(x()||Zt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(p=t.beforeOpen)==null||p.call(t),T())return;nt(m,!0),c.shouldShowBackdrop||z(m,"transparent"),nt([l],!0),tt(l,{y:l.clientHeight});const d=window.innerHeight,b=pt(d,l.clientHeight,c.marginTop,c.defaultPosition),f=M(l).y;o.translateContainer({startY:f,endY:b,animationFrame:a,bottomSheetContainer:l,onEnd:t.afterOpen});const L=document.body.style.overflowY;r.originalDocumentOverflowY=L||"initial";const B=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=B||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",u.bottomSheetHandle.focus(),h.attacheOnOpenEventListeners()};function w(){var p;if(Y())return;(p=t.beforeClose)==null||p.call(t);const d=M(l).y,b=l.clientHeight;o.translateContainer({startY:d,endY:b,animationFrame:a,bottomSheetContainer:l,onEnd:()=>{var f;(f=t.afterClose)==null||f.call(t),nt([m,l],!1),h.clearOnOpenEventListeners()}}),i()}function x(){return o.isMounted}function T(){const p=M(l).y,d=window.innerHeight,b=l.clientHeight>=d?d:l.clientHeight;return p<=b}function Y(){return!T()}function G(){const p=M(l).y,d=l.clientHeight,b=window.innerHeight;if(p<=5&&p>=-5)return j.CONTENT_HEIGHT;const f=d-p;if(f===b/2)return j.MIDDLE;const L=b-c.marginTop,B=10;return f<=L+B&&f>=L-B?j.TOP:j.CLOSED}function _(){return l.clientHeight}function I(p){if(!T())return;const d=M(l).y,b=l.clientHeight-d,f=window.innerHeight-p,L=Rt(b,f),B=Q(b,f);o.translateContainer({startY:d,endY:d+(L.isUp?-B:B),animationFrame:a,bottomSheetContainer:l})}function R(p,{viewportHeight:d,visibleHeight:b}){let f=null;for(const L of p){const B=L*d,W=Q(b,B);(f===null||W<f)&&(f=W)}return{minOffset:f}}function O(){const p=[...c.snapPoints].reverse(),d=M(l).y,b=l.clientHeight,f=b-d;if(!c.expandable&&f>=b)return;const L=window.innerHeight,B=ht("above",{visibleHeight:f,viewportHeight:L},p),{minOffset:W}=R(B,{visibleHeight:f,viewportHeight:L});if(W===null&&f<L-c.marginTop){o.translateContainer({startY:d,endY:pt(L,b,c.marginTop,"top"),animationFrame:a,bottomSheetContainer:l});return}D(W)&&o.translateContainer({startY:d,endY:d-W,animationFrame:a,bottomSheetContainer:l})}function y(){const p=M(l).y,d=l.clientHeight-p;if(d<1)return;const b=window.innerHeight,f=ht("below",{visibleHeight:d,viewportHeight:b},c.snapPoints),{minOffset:L}=R(f,{visibleHeight:d,viewportHeight:b});D(L)&&o.translateContainer({startY:p,endY:p+L,animationFrame:a,bottomSheetContainer:l})}function v(p){const d=window.innerHeight;if(!Jt(p))return;const b=Z(d*p,2);I(b)}return{props:c,elements:u,mount:E,unmount:g,open:S,close:w,getIsMounted:x,getIsOpen:T,getIsClosed:Y,getPosition:G,getHeight:_,moveTo:I,snapTo:v}}function lt(){return{elements:{bottomSheetRoot:void 0,bottomSheetBackdrop:void 0,bottomSheetContainer:void 0,bottomSheetHandle:void 0,bottomSheetHandleBar:void 0,bottomSheetContentWrapper:void 0,bottomSheetContainerGapFiller:void 0},mount:()=>{},unmount:()=>{},open:()=>{},close:()=>{},getIsMounted:()=>!1,getHeight:()=>0,getIsOpen:()=>!1,getIsClosed:()=>!0,getPosition:()=>j.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const le=lt(),ue=k.forwardRef(function(e,n){const{children:o,isOpen:r,setIsOpen:i,afterClose:a,mountingPointRef:s,...u}=e,h=k.useRef(le),[c,m]=k.useState(h.current);k.useImperativeHandle(n,()=>c,[c]);const C=k.useCallback(()=>{i(!1),a==null||a()},[a]);k.useEffect(()=>{r?c.open():c.close()},[r]);const l=k.useRef(null);return k.useEffect(function(){var w;if(s&&!s.current)return;const g=At((w=e.mountingPointRef)==null?void 0:w.current)?e.mountingPointRef.current:window.document.body;if(!g||c.getIsMounted())return;const S=ce({content:"",...u,afterClose:C});return S.mount(g),l.current=S.elements.bottomSheetContentWrapper??null,h.current=S,m(S),()=>{c.unmount()}},[e.mountingPointRef,u,C]),k.useEffect(function(){Object.assign(h.current.props,{...u}),m(h.current)},[u]),k.useEffect(function(){return()=>{h.current.unmount()}},[]),l.current?xt.createPortal(e.children,l.current):null}),de=lt();function pe(t={}){const e=k.useRef(de),[n,o]=k.useState(!1),[r,i]=k.useState(e.current);k.useEffect(()=>{i(e.current)},[e.current]);const{beforeOpen:a,afterOpen:s,beforeClose:u,afterClose:h,onDragStart:c,onDragMove:m,onDragEnd:C,...l}=t,E=()=>{a==null||a()},g=()=>{s==null||s(),o(!0)},S=()=>{u==null||u()},w=()=>{h==null||h(),o(!1)},x=()=>{c==null||c()},T=(y,v)=>{m==null||m(y,v)},Y=()=>{C==null||C()},G=k.useMemo(()=>({ref:e,isOpen:n,setIsOpen:o,beforeOpen:E,afterOpen:g,beforeClose:S,afterClose:w,onDragStart:x,onDragMove:T,onDragEnd:Y,...l}),[e.current,n,o,t]),_=k.useCallback(()=>{o(!0)},[o]),I=k.useCallback(()=>{o(!0)},[o]),R=k.useCallback((...y)=>{r.moveTo(...y)},[r]),O=k.useCallback((...y)=>{r.snapTo(...y)},[r]);return{props:G,instance:r,isOpen:n,setIsOpen:o,open:_,close:I,moveTo:R,snapTo:O}}exports.BottomSheet=ue;exports.createPlaceholderBottomSheet=lt;exports.useBottomSheet=pe;