@plainsheet/react 0.4.1 → 0.4.5

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
@@ -59,7 +59,7 @@ Without any configs.
59
59
  ## Philosophy
60
60
 
61
61
  As the name suggests, we strive to make the plain bottom sheet minimalistic yet feature-rich and highly configurable.
62
- We try our best to write concise, well-tested, and maintainable code to achieve this goal.
62
+ To achieve this goal, we try our best to write concise, well-tested, and maintainable code.
63
63
 
64
64
  ## Support the project 🤍
65
65
 
@@ -1,6 +1,6 @@
1
1
  import { OmitKeyof } from '@plainsheet/utility';
2
2
  import { BottomSheetCore, BottomSheetCoreProps } from '@plainsheet/core';
3
- import { ReactNode } from 'react';
3
+ import { MutableRefObject, ReactNode } from 'react';
4
4
 
5
5
  export { createPlaceholderBottomSheet } from '@plainsheet/core';
6
6
  export type { BottomSheetCore } from '@plainsheet/core';
@@ -8,12 +8,13 @@ export type BottomSheetProps = {
8
8
  children: ReactNode;
9
9
  isOpen: boolean;
10
10
  setIsOpen: (isOpen: boolean) => void;
11
- mountingPoint?: Element | null;
11
+ mountingPointRef?: MutableRefObject<MountingPoint>;
12
12
  } & CoreProps;
13
13
  type CoreProps = OmitKeyof<BottomSheetCoreProps, "content">;
14
+ type MountingPoint = undefined | HTMLElement;
14
15
  export declare const BottomSheet: import('react').ForwardRefExoticComponent<{
15
16
  children: ReactNode;
16
17
  isOpen: boolean;
17
18
  setIsOpen: (isOpen: boolean) => void;
18
- mountingPoint?: Element | null;
19
+ mountingPointRef?: MutableRefObject<MountingPoint>;
19
20
  } & CoreProps & import('react').RefAttributes<BottomSheetCore>>;
@@ -1,5 +1,7 @@
1
- import { BottomSheetCore } from '@plainsheet/core';
1
+ import { BottomSheetCore, BottomSheetCoreProps } from '@plainsheet/core';
2
2
 
3
+ interface UseBottomSheetProps extends Omit<BottomSheetCoreProps, "content"> {
4
+ }
3
5
  interface UseBottomSheetReturn {
4
6
  /**
5
7
  * Props to be passed to the `BottomSheet`.
@@ -9,8 +11,13 @@ interface UseBottomSheetReturn {
9
11
  * `BottomSheetCore` instance to control the bottom sheet.
10
12
  */
11
13
  instance: BottomSheetCore;
14
+ /**
15
+ * a React state tells whether the bottom sheet is open.
16
+ */
17
+ isOpen: boolean;
18
+ setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
12
19
  }
13
- interface HookProvidedProps {
20
+ interface HookProvidedProps extends UseBottomSheetProps {
14
21
  /**
15
22
  * `ref` of the BottomSheet component. Pass it to the component to use `instance`.
16
23
  */
@@ -18,5 +25,5 @@ interface HookProvidedProps {
18
25
  isOpen: boolean;
19
26
  setIsOpen: React.Dispatch<React.SetStateAction<boolean>>;
20
27
  }
21
- export declare function useBottomSheet(): UseBottomSheetReturn;
28
+ export declare function useBottomSheet(props?: UseBottomSheetProps): UseBottomSheetReturn;
22
29
  export {};
@@ -1 +1 @@
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%;pointer-events:none;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{display:none}.pbs-backdrop.open{background-color:#454545b3}.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 Ot=Object.defineProperty,Dt=(t,e,n)=>e in t?Ot(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e,n)=>Dt(t,typeof e!="symbol"?e+"":e,n);function H(t){return typeof t=="string"}function Bt(t,e){return t.classList.contains(Q(e))}function q(t,e){t.classList.add(Q(e))}function nt(t,e){t.classList.remove(Q(e))}function j(t,e,n){H(n)&&(H(e)&&nt(t,e),q(t,n))}function Q(t){return H(t)?t.trim().replace(/\./g,""):""}function R(t){return t.map(e=>Q(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 et(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{z(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}z(t,n),t.setAttribute("aria-modal",n?"true":"false")}function z(t,e){e?(q(t,ut),nt(t,dt)):(q(t,dt),nt(t,ut))}function St(t){return t instanceof HTMLElement}function x(t){return typeof t=="number"&&!Number.isNaN(t)}function Mt(t){St(t)&&t.focus()}function Yt(t){if(!St(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=x(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),i=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||i||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||{}),ot=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(ot||{}),X=(t=>(t.Hidden="hidden",t))(X||{});function M(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{q(o,i)}),H(n)&&o.setAttribute("data-testid",n),o}Pt([w.Root,w.ContentWrapper]);function ht(t,e,n,o){switch(o){case"content-height":return e>=t?yt(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 wt(t,e){return e<t?-(t-e):e-t}function V(t,e){return t>e?t-e:e-t}function It(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(i=>{const r=i*e.viewportHeight;return o?e.visibleHeight<r:e.visibleHeight>r})}function yt(t,e,n){return-(t-e)+n}function mt(t){return Number(t.replace("px",""))}function K(t,...e){return Number(t.toFixed(...e))}function Et(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const i=o[1],r=o[2].split(",").map(c=>c.trim());n.push({type:i,values:r})}return n}function Rt(t){const e=t.style.transform,n=Et(e);return{transform:e,transformValues:n}}function Tt(t,e){return t.find(o=>o.type.startsWith(e))||null}const rt="translate";function B(t){const e=t.style.transform,n=Et(e),o=Tt(n,rt);return Ht(o??{type:rt,values:[]})}function J(t,{x:e,y:n}){const{transform:o,transformValues:i}=Rt(t),r=Tt(i,rt);if(r){const c=Ht(r);t.style.transform=`translate(${e??c.x??0}px,${n??c.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 ft(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&&!Bt(e,w.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Ft=(t,e,n,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=B(e),n.onDragStart()},Wt=(t,e,n,o,i)=>r=>{Ut(r,t,n,o,i,e,n.marginTop)};function Ut(t,e,n,o,i,r,c){if(!o.isDragging||!x(o.startY))return;const s=e.getCoordinates(t).y,h=wt(o.startY,s),f=window.innerHeight,l=r.clientHeight,b=l-(o.containerStartTranslate.y+h);if(b>=f)return;const E=Ct(o.startY,s);if(E.isUp&&!n.expandable&&b>=l)return;i.start(()=>{J(r,{y:o.containerStartTranslate.y+h})},0);const a=f-c,L=l-o.containerStartTranslate.y;if(E.isUp){const v=a-L,S=a-b,T=ft(1-K(S/v,2),{min:0,max:1});n.onDragMove(E,T)}else if(E.isDown){const v=ft(K(1-b/L,2),{min:0,max:1});n.onDragMove(E,v)}}const jt=(t,e,n,o,i,r,c)=>s=>{if(!o.isDragging||(o.isDragging=!1,!x(o.startY)))return;n.onDragEnd();const h=o.startY,f=t.getCoordinates(s).y,l=B(e).y,b=Ct(h,f),E=window.innerHeight,a=e.clientHeight;if(b.isUp){const L=[...n.snapPoints].sort((T,C)=>T-C),v=a+-l;if(!n.expandable&&v>=a)return;for(const T of L){const C=T*window.innerHeight;if(v<=C){const P=V(v,C);c.translateContainer({startY:l,endY:l-P,animationFrame:i,bottomSheetContainer:e});return}}const S=yt(E,a,n.marginTop);c.translateContainer({startY:l,endY:S,animationFrame:i,bottomSheetContainer:e})}else if(b.isDown){const L=[...n.snapPoints].sort((v,S)=>S-v);for(const v of L){const S=v*window.innerHeight,T=a+-l;if(T>=S){const C=V(T,S);c.translateContainer({startY:l,endY:l+C,animationFrame:i,bottomSheetContainer:e});return}}r()}};var W=(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))(W||{});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:W.All};class G{constructor(e){$(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=Gt,onMove:o,onEnd:i}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("touchstart",r=>{if(n.eventPhase===W.All){e(r);return}gt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),i&&this.currentTarget.addEventListener("touchend",i)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("mousedown",r=>{if(n.eventPhase===W.All){e(r);return}gt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),i&&this.currentTarget.addEventListener("mouseup",r=>{i(r)})}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 _t(t,e){const n=$t(t);Xt(n),n.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const i=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${i}px`,n.bottomSheetContentWrapper.appendChild(o);const r=qt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function $t(t){const e=M("dialog",R([w.Root,ot.Dialog,t.rootClass]),w.Root);e.ariaLabel=t.ariaLabel;const n=M("section",R([w.Container,t.containerClass]),w.Container);t.containerBorderRadius&&(n.style.borderRadius=t.containerBorderRadius);const o=M("div",w.GapFiller,w.GapFiller),i=M("button",R([w.Handle,ot.Button,t.shouldShowHandle?null:X.Hidden,t.handleClass]),w.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=M("span",R([w.HandleBar,t.shouldShowHandle?null:X.Hidden]),w.HandleBar),c=M("article",R([w.ContentWrapper,t.contentWrapperClass]),w.ContentWrapper),s=M("div",R([w.Backdrop,t.backdropClass,X.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:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function Xt({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:r}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(i),e.appendChild(r)}function qt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:s}=t,{animationFrame:h}=n,f=new G(r),l=new G(s),b=new G(c),E=e.dragTriggers.reduce((g,A)=>{const D=o.querySelectorAll(A);if(!D.length)return g;const tt=Array.from(D).map(Y=>Y instanceof HTMLElement?new G(Y):null).filter(Y=>!!Y);return[...g,...tt]},[]),a=new G(window),L=Ft(a,i,e,n.draggingState),v=Wt(a,i,e,n.draggingState,h),S=jt(a,i,e,n.draggingState,h,n.onClose,n.bottomSheetState);function T(g){g.target instanceof Element&&!o.contains(g.target)&&n.onClose()}function C(g){Nt(n.draggingState,g.target,t.bottomSheetContentWrapper)}function P(){e.draggable&&(f.addEventListeners({onStart:C}),E.forEach(g=>{g.addEventListeners({onStart:C,onStartOptions:{eventPhase:W.Target}})})),e.draggable&&e.backgroundDraggable&&(l.addEventListeners({onStart:C,onStartOptions:{eventPhase:W.Target}}),b.addEventListeners({onStart:C})),e.draggable&&a.addEventListeners({onStart:L,onMove:v,onEnd:S}),e.draggable&&window.document.addEventListener("keyup",g=>{g.key==="Escape"&&n.onClose()}),e.shouldCloseOnOutsideClick&&window.document.addEventListener("click",T),r.addEventListener("keyup",g=>{if(g.key==="ArrowUp"){n.moveUp();return}if(g.key==="ArrowDown"){n.moveDown();return}if(g.shiftKey&&g.key==="Tab"){const A=_(t.bottomSheetContentWrapper);Mt(A)}})}function _(g){let A=[...Array.from(g.childNodes).reverse()];for(;A.length;){const D=A.shift();if(Yt(D))return D;D&&(A=[...A,...Array.from(D.childNodes).reverse()])}return null}function Z(){f.removeEventListeners({onStart:C}),l.removeEventListeners({onStart:C}),b.removeEventListeners({onStart:C}),E.forEach(g=>{g.removeEventListeners({onStart:C})}),a.removeEventListeners({onStart:L,onMove:v,onEnd:S}),window.removeEventListener("click",T)}return{attachEventListeners:P,clearEventListeners:Z}}class zt{constructor(){$(this,"animationId"),$(this,"isInProgress"),$(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const i=r=>{this.startedAt||(this.startedAt=r);const c=r-this.startedAt,s=n===0?1:K(c/n,2),h=s>=1&&!o;e(s),h?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,x(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Vt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:s}=t,h=wt(e,n);i.stop();let f=!1;i.start(l=>{J(o,{y:e+h*c(l)}),!f&&l>=1&&(r==null||r(),f=!0)},s)}const at=(t,e)=>n=>{Vt({...n,animationTimingFunction:t,animationDuration:e})},F={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Kt(t){return!(!x(t)||t>1||t<0)}function Jt(t,e){const n={set(o,i,r,c){return e(i,r),Reflect.set(o,i,r,c)}};return new Proxy(t,n)}function Qt(...t){console.error(t)}const N={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function Zt(t){for(const e of Object.values(N))if(e===t)return!0;return!1}function kt(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&x(t.p1x)&&x(t.p1y)&&x(t.p2x)&&x(t.p2y))}function U(t,e,n,o){return function(s){return c(i(s))};function i(s){let h=0,f=1,l=s,b;if(s===0||s===1)return s;for(;h<f;){if(b=r(l),Math.abs(b-s)<.001)return l;s>b?h=l:f=l,l=(f+h)/2}return l}function r(s){return 3*t*s*Math.pow(1-s,2)+3*n*Math.pow(s,2)*(1-s)+Math.pow(s,3)}function c(s){return 3*e*s*Math.pow(1-s,2)+3*o*Math.pow(s,2)*(1-s)+Math.pow(s,3)}}const bt=U(.25,.1,.25,1),te=U(.42,0,1,1),Lt=U(.42,0,.58,1),ee=U(.4,.1,.6,1),ne=U(.45,1.5,.55,1);function oe(t){switch(t){case N.EASE:return bt;case N.EASE_IN:return te;case N.EASE_OUT:return Lt;case N.EASE_IN_OUT:return ee;case N.SPRING:return ne;default:return bt}}function vt(t){return typeof t=="boolean"}const re={ariaLabel:"Bottom sheet",content:"",defaultPosition:F.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 ie(t){const e={...re},n=Object.entries(t).reduce((o,i)=>{const[r,c]=i;return it(c)&&(o[r]=c),o},{});return{...e,...n}}function st(t){if(kt(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return U(e,n,o,i)}return Zt(t)?oe(t):Lt}function ae(t,e,n){function o(i,r){switch(i){case"content":H(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":H(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":vt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":vt(r)||z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":H(r)&&(t.bottomSheetContainer.style.borderRadius=r);break;case"backdropColor":H(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":H(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!H(r))return;j(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!H(r))return;j(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!H(r))return;j(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!H(r))return;j(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!H(r))return;j(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(kt(r)){const c=st(r),s=at(c,n.draggingAnimationDuration);e.translateContainer=s}break;case"draggingAnimationDuration":if(x(r)){const c=st(n.draggingAnimationTimings),s=at(c,r);e.translateContainer=s}break}}return o}function se(t){const e=ie(t),n=st(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:at(n,e.draggingAnimationDuration)},i={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function r(){i.originalDocumentOverflowY&&i.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=i.originalDocumentOverflowY),i.originalDocumentOverscrollBehavior&&(document.body.style.position=i.originalDocumentOverscrollBehavior)}const c=new zt,s={animationFrame:c,onClose:T,bottomSheetState:o,draggingState:i,snapTo:lt,moveUp:tt,moveDown:Y},{elements:h,eventHandlers:f}=_t(e,s),l=Jt(e,ae(h,o,e)),{bottomSheetBackdrop:b,bottomSheetRoot:E,bottomSheetContainer:a}=h,L=u=>{const d=u??window.document.body;d.appendChild(E),d.appendChild(b);const p=window.innerHeight;J(a,{y:p}),f.attachEventListeners(),o.isMounted=!0},v=()=>{f.clearEventListeners(),Object.values(h).forEach(u=>{u.remove()}),r(),o.isMounted=!1},S=()=>{var u;if(C()||Qt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(u=t.beforeOpen)==null||u.call(t),P())return;l.shouldShowBackdrop&&et(b,!0),et([a],!0),J(a,{y:a.clientHeight});const d=window.innerHeight,p=ht(d,a.clientHeight,l.marginTop,l.defaultPosition),m=B(a).y;o.translateContainer({startY:m,endY:p,animationFrame:c,bottomSheetContainer:a,onEnd:t.afterOpen}),h.bottomSheetHandle.focus();const y=document.body.style.overflowY;i.originalDocumentOverflowY=y||"initial";const O=document.body.style.overscrollBehavior;i.originalDocumentOverscrollBehavior=O||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain"};function T(){var u;if(_())return;(u=t.beforeClose)==null||u.call(t);const d=B(a).y,p=a.clientHeight;o.translateContainer({startY:d,endY:p,animationFrame:c,bottomSheetContainer:a,onEnd:()=>{var m;(m=t.afterClose)==null||m.call(t),et([b,a],!1)}}),r()}function C(){return o.isMounted}function P(){const u=B(a).y,d=window.innerHeight,p=a.clientHeight>=d?d:a.clientHeight;return u<p}function _(){return!P()}function Z(){const u=B(a).y,d=a.clientHeight,p=window.innerHeight;if(u<=5&&u>=-5)return F.CONTENT_HEIGHT;const m=d-u;if(m===p/2)return F.MIDDLE;const y=p-l.marginTop,O=10;return m<=y+O&&m>=y-O?F.TOP:F.CLOSED}function g(){return a.clientHeight}function A(u){if(!P())return;const d=B(a).y,p=a.clientHeight-d,m=window.innerHeight-u,y=It(p,m),O=V(p,m);o.translateContainer({startY:d,endY:d+(y.isUp?-O:O),animationFrame:c,bottomSheetContainer:a})}function D(u,{viewportHeight:d,visibleHeight:p}){let m=null;for(const y of u){const O=y*d,I=V(p,O);(m===null||I<m)&&(m=I)}return{minOffset:m}}function tt(){const u=[...l.snapPoints].reverse(),d=B(a).y,p=a.clientHeight,m=p-d;if(!l.expandable&&m>=p)return;const y=window.innerHeight,O=pt("above",{visibleHeight:m,viewportHeight:y},u),{minOffset:I}=D(O,{visibleHeight:m,viewportHeight:y});if(I===null&&m<y-l.marginTop){o.translateContainer({startY:d,endY:ht(y,p,l.marginTop,"top"),animationFrame:c,bottomSheetContainer:a});return}x(I)&&o.translateContainer({startY:d,endY:d-I,animationFrame:c,bottomSheetContainer:a})}function Y(){const u=B(a).y,d=a.clientHeight-u;if(d<1)return;const p=window.innerHeight,m=pt("below",{visibleHeight:d,viewportHeight:p},l.snapPoints),{minOffset:y}=D(m,{visibleHeight:d,viewportHeight:p});x(y)&&o.translateContainer({startY:u,endY:u+y,animationFrame:c,bottomSheetContainer:a})}function lt(u){const d=window.innerHeight;if(!Kt(u))return;const p=K(d*u,2);A(p)}return{props:l,elements:h,mount:L,unmount:v,open:S,close:T,getIsMounted:C,getIsOpen:P,getIsClosed:_,getPosition:Z,getHeight:g,moveTo:A,snapTo:lt}}function ct(){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:()=>F.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ce=ct(),le=k.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:c,mountingPoint:s,...h}=e,f=k.useRef(ce),[l,b]=k.useState(f.current);k.useImperativeHandle(n,()=>l,[l]);const E=k.useCallback(()=>{r(!1),c==null||c()},[c]);k.useEffect(()=>{i?l.open():l.close()},[i]);const a=k.useRef(null);return k.useEffect(function(){const v=At(e.mountingPoint)?e.mountingPoint:window.document.body;if(!v||l.getIsMounted())return;const S=se({content:"",...h,afterClose:E});return S.mount(v),a.current=S.elements.bottomSheetContentWrapper??null,f.current=S,b(S),()=>{l.unmount()}},[e.mountingPoint,h,E]),k.useEffect(function(){Object.assign(f.current.props,{...h}),b(f.current)},[h]),a.current?xt.createPortal(e.children,a.current):null}),ue=ct();function de(){const t=k.useRef(ue),[e,n]=k.useState(!1),[o,i]=k.useState(t.current);return k.useEffect(()=>{i(t.current)},[t.current]),{props:k.useMemo(()=>({ref:t,isOpen:e,setIsOpen:n}),[e]),instance:o}}exports.BottomSheet=le;exports.createPlaceholderBottomSheet=ct;exports.useBottomSheet=de;
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;