@plainsheet/react 0.4.0 → 0.4.4

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.
@@ -1 +1 @@
1
- (function(D,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],S):(D=typeof globalThis<"u"?globalThis:D||self,S(D.BottomSheet={},D.React,D.ReactDOM))})(this,function(D,S,xt){"use strict";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 Dt=Object.defineProperty,Bt=(t,e,n)=>e in t?Dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e,n)=>(Bt(t,typeof e!="symbol"?e+"":e,n),n);function H(t){return typeof t=="string"}function Pt(t,e){return t.classList.contains(q(e))}function X(t,e){t.classList.add(q(e))}function tt(t,e){t.classList.remove(q(e))}function G(t,e,n){H(n)&&(H(e)&&tt(t,e),X(t,n))}function q(t){return H(t)?t.trim().replace(/\./g,""):""}function I(t){return t.map(e=>q(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 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?(X(t,ut),tt(t,dt)):(X(t,dt),tt(t,ut))}function ht(t){return t instanceof HTMLElement}function O(t){return typeof t=="number"&&!Number.isNaN(t)}function Yt(t){ht(t)&&t.focus()}function It(t){if(!ht(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=O(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 C=(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))(C||{}),nt=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(nt||{}),V=(t=>(t.Hidden="hidden",t))(V||{});function Y(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{X(o,i)}),H(n)&&o.setAttribute("data-testid",n),o}Mt([C.Root,C.ContentWrapper]);function pt(t,e,n,o){switch(o){case"content-height":return e>=t?bt(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function mt(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function ft(t,e){return e<t?-(t-e):e-t}function K(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 gt(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 bt(t,e,n){return-(t-e)+n}function vt(t){return Number(t.replace("px",""))}function J(t,...e){return Number(t.toFixed(...e))}function St(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 Nt(t){const e=t.style.transform,n=St(e);return{transform:e,transformValues:n}}function Ct(t,e){return t.find(o=>o.type.startsWith(e))||null}const ot="translate";function P(t){const e=t.style.transform,n=St(e),o=Ct(n,ot);return wt(o??{type:ot,values:[]})}function Q(t,{x:e,y:n}){const{transform:o,transformValues:i}=Nt(t),r=Ct(i,ot);if(r){const c=wt(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 wt(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:vt(e)??0,y:vt(n)??0}}function rt(t){return t!=null}function yt(t,{min:e,max:n}){return rt(n)&&t>=n?n:rt(e)&&t<=e?e:t}const Ft=(t,e,n)=>{e instanceof HTMLElement&&!Pt(e,C.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Wt=(t,e,n,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=P(e),n.onDragStart()},jt=(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||!O(o.startY))return;const s=e.getCoordinates(t).y,h=ft(o.startY,s),f=window.innerHeight,l=r.clientHeight,b=l-(o.containerStartTranslate.y+h);if(b>=f)return;const T=mt(o.startY,s);if(T.isUp&&!n.expandable&&b>=l)return;i.start(()=>{Q(r,{y:o.containerStartTranslate.y+h})},0);const a=f-c,L=l-o.containerStartTranslate.y;if(T.isUp){const v=a-L,w=a-b,k=yt(1-J(w/v,2),{min:0,max:1});n.onDragMove(T,k)}else if(T.isDown){const v=yt(J(1-b/L,2),{min:0,max:1});n.onDragMove(T,v)}}const Gt=(t,e,n,o,i,r,c)=>s=>{if(!o.isDragging||(o.isDragging=!1,!O(o.startY)))return;n.onDragEnd();const h=o.startY,f=t.getCoordinates(s).y,l=P(e).y,b=mt(h,f),T=window.innerHeight,a=e.clientHeight;if(b.isUp){const L=[...n.snapPoints].sort((k,y)=>k-y),v=a+-l;if(!n.expandable&&v>=a)return;for(const k of L){const y=k*window.innerHeight;if(v<=y){const M=K(v,y);c.translateContainer({startY:l,endY:l-M,animationFrame:i,bottomSheetContainer:e});return}}const w=bt(T,a,n.marginTop);c.translateContainer({startY:l,endY:w,animationFrame:i,bottomSheetContainer:e})}else if(b.isDown){const L=[...n.snapPoints].sort((v,w)=>w-v);for(const v of L){const w=v*window.innerHeight,k=a+-l;if(k>=w){const y=K(k,w);c.translateContainer({startY:l,endY:l+y,animationFrame:i,bottomSheetContainer:e});return}}r()}};var R=(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))(R||{});function Et(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const _t={eventPhase:R.All};class _{constructor(e){$(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=_t,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===R.All){e(r);return}Et(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===R.All){e(r);return}Et(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=Xt(t);qt(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=zt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function Xt(t){const e=Y("dialog",I([C.Root,nt.Dialog,t.rootClass]),C.Root);e.ariaLabel=t.ariaLabel;const n=Y("section",I([C.Container,t.containerClass]),C.Container);t.containerBorderRadius&&(n.style.borderRadius=t.containerBorderRadius);const o=Y("div",C.GapFiller,C.GapFiller),i=Y("button",I([C.Handle,nt.Button,t.shouldShowHandle?null:V.Hidden,t.handleClass]),C.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=Y("span",I([C.HandleBar,t.shouldShowHandle?null:V.Hidden]),C.HandleBar),c=Y("article",I([C.ContentWrapper,t.contentWrapperClass]),C.ContentWrapper),s=Y("div",I([C.Backdrop,t.backdropClass,V.Hidden]),C.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 qt({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 zt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:s}=t,{animationFrame:h}=n,f=new _(r),l=new _(s),b=new _(c),T=e.dragTriggers.reduce((g,x)=>{const B=o.querySelectorAll(x);if(!B.length)return g;const lt=Array.from(B).map(j=>j instanceof HTMLElement?new _(j):null).filter(j=>!!j);return[...g,...lt]},[]),a=new _(window),L=Wt(a,i,e,n.draggingState),v=jt(a,i,e,n.draggingState,h),w=Gt(a,i,e,n.draggingState,h,n.onClose,n.bottomSheetState);function k(g){g.target instanceof Element&&!o.contains(g.target)&&n.onClose()}function y(g){Ft(n.draggingState,g.target,t.bottomSheetContentWrapper)}function M(){e.draggable&&(f.addEventListeners({onStart:y}),T.forEach(g=>{g.addEventListeners({onStart:y,onStartOptions:{eventPhase:R.Target}})})),e.draggable&&e.backgroundDraggable&&(l.addEventListeners({onStart:y,onStartOptions:{eventPhase:R.Target}}),b.addEventListeners({onStart:y})),e.draggable&&a.addEventListeners({onStart:L,onMove:v,onEnd:w}),e.draggable&&window.document.addEventListener("keyup",g=>{g.key==="Escape"&&n.onClose()}),e.shouldCloseOnOutsideClick&&window.document.addEventListener("click",k),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 x=Z(t.bottomSheetContentWrapper);Yt(x)}})}function Z(g){let x=[...Array.from(g.childNodes).reverse()];for(;x.length;){const B=x.shift();if(It(B))return B;B&&(x=[...x,...Array.from(B.childNodes).reverse()])}return null}function ct(){f.removeEventListeners({onStart:y}),l.removeEventListeners({onStart:y}),b.removeEventListeners({onStart:y}),T.forEach(g=>{g.removeEventListeners({onStart:y})}),a.removeEventListeners({onStart:L,onMove:v,onEnd:w}),window.removeEventListener("click",k)}return{attachEventListeners:M,clearEventListeners:ct}}class Vt{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:J(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,O(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Kt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:s}=t,h=ft(e,n);i.stop();let f=!1;i.start(l=>{Q(o,{y:e+h*c(l)}),!f&&l>=1&&(r==null||r(),f=!0)},s)}const it=(t,e)=>n=>{Kt({...n,animationTimingFunction:t,animationDuration:e})},N={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Jt(t){return!(!O(t)||t>1||t<0)}function Qt(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 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 Tt(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&O(t.p1x)&&O(t.p1y)&&O(t.p2x)&&O(t.p2y))}function W(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 ee=W(.25,.1,.25,1),ne=W(.42,0,1,1),Ht=W(.42,0,.58,1),kt=W(.4,.1,.6,1),oe=W(.45,1.5,.55,1);function re(t){switch(t){case F.EASE:return ee;case F.EASE_IN:return ne;case F.EASE_OUT:return Ht;case F.EASE_IN_OUT:return kt;case F.SPRING:return oe;default:return kt}}function Lt(t){return typeof t=="boolean"}const ie={ariaLabel:"Bottom sheet",content:"",defaultPosition:N.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,i)=>{const[r,c]=i;return rt(c)&&(o[r]=c),o},{});return{...e,...n}}function at(t){if(Tt(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return W(e,n,o,i)}return te(t)?re(t):Ht}function se(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":Lt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":Lt(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;G(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!H(r))return;G(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!H(r))return;G(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!H(r))return;G(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!H(r))return;G(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(Tt(r)){const c=at(r),s=it(c,n.draggingAnimationDuration);e.translateContainer=s}break;case"draggingAnimationDuration":if(O(r)){const c=at(n.draggingAnimationTimings),s=it(c,r);e.translateContainer=s}break}}return o}function ce(t){const e=ae(t),n=at(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:it(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 Vt,s={animationFrame:c,onClose:k,bottomSheetState:o,draggingState:i,snapTo:Ot,moveUp:lt,moveDown:j},{elements:h,eventHandlers:f}=$t(e,s),l=Qt(e,se(h,o,e)),{bottomSheetBackdrop:b,bottomSheetRoot:T,bottomSheetContainer:a}=h,L=u=>{const d=u??window.document.body;d.appendChild(T),d.appendChild(b);const p=window.innerHeight;Q(a,{y:p}),f.attachEventListeners(),o.isMounted=!0},v=()=>{f.clearEventListeners(),Object.values(h).forEach(u=>{u.remove()}),r(),o.isMounted=!1},w=()=>{var u;if(y()||Zt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(u=t.beforeOpen)==null||u.call(t),M())return;l.shouldShowBackdrop&&et(b,!0),et([a],!0),Q(a,{y:a.clientHeight});const d=window.innerHeight,p=pt(d,a.clientHeight,l.marginTop,l.defaultPosition),m=P(a).y;o.translateContainer({startY:m,endY:p,animationFrame:c,bottomSheetContainer:a,onEnd:t.afterOpen}),h.bottomSheetHandle.focus();const E=document.body.style.overflowY;i.originalDocumentOverflowY=E||"initial";const A=document.body.style.overscrollBehavior;i.originalDocumentOverscrollBehavior=A||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain"};function k(){var u;if(Z())return;(u=t.beforeClose)==null||u.call(t);const d=P(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 y(){return o.isMounted}function M(){const u=P(a).y,d=window.innerHeight,p=a.clientHeight>=d?d:a.clientHeight;return u<p}function Z(){return!M()}function ct(){const u=P(a).y,d=a.clientHeight,p=window.innerHeight;if(u<=5&&u>=-5)return N.CONTENT_HEIGHT;const m=d-u;if(m===p/2)return N.MIDDLE;const E=p-l.marginTop,A=10;return m<=E+A&&m>=E-A?N.TOP:N.CLOSED}function g(){return a.clientHeight}function x(u){if(!M())return;const d=P(a).y,p=a.clientHeight-d,m=window.innerHeight-u,E=Rt(p,m),A=K(p,m);o.translateContainer({startY:d,endY:d+(E.isUp?-A:A),animationFrame:c,bottomSheetContainer:a})}function B(u,{viewportHeight:d,visibleHeight:p}){let m=null;for(const E of u){const A=E*d,U=K(p,A);(m===null||U<m)&&(m=U)}return{minOffset:m}}function lt(){const u=[...l.snapPoints].reverse(),d=P(a).y,p=a.clientHeight,m=p-d;if(!l.expandable&&m>=p)return;const E=window.innerHeight,A=gt("above",{visibleHeight:m,viewportHeight:E},u),{minOffset:U}=B(A,{visibleHeight:m,viewportHeight:E});if(U===null&&m<E-l.marginTop){o.translateContainer({startY:d,endY:pt(E,p,l.marginTop,"top"),animationFrame:c,bottomSheetContainer:a});return}O(U)&&o.translateContainer({startY:d,endY:d-U,animationFrame:c,bottomSheetContainer:a})}function j(){const u=P(a).y,d=a.clientHeight-u;if(d<1)return;const p=window.innerHeight,m=gt("below",{visibleHeight:d,viewportHeight:p},l.snapPoints),{minOffset:E}=B(m,{visibleHeight:d,viewportHeight:p});O(E)&&o.translateContainer({startY:u,endY:u+E,animationFrame:c,bottomSheetContainer:a})}function Ot(u){const d=window.innerHeight;if(!Jt(u))return;const p=J(d*u,2);x(p)}return{props:l,elements:h,mount:L,unmount:v,open:w,close:k,getIsMounted:y,getIsOpen:M,getIsClosed:Z,getPosition:ct,getHeight:g,moveTo:x,snapTo:Ot}}function st(){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:()=>N.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const le=st(),ue=S.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:c,mountingPoint:s,...h}=e,f=S.useRef(le),[l,b]=S.useState(f.current);S.useImperativeHandle(n,()=>l,[l]);const T=S.useCallback(()=>{r(!1),c==null||c()},[c]);S.useEffect(()=>{i?l.open():l.close()},[i]);const a=S.useRef(null);return S.useEffect(function(){const v=At(e.mountingPoint)?e.mountingPoint:window.document.body;if(!v||l.getIsMounted())return;const w=ce({content:"",...h,afterClose:T});return w.mount(v),a.current=w.elements.bottomSheetContentWrapper??null,f.current=w,b(w),()=>{l.unmount()}},[e.mountingPoint,h,T]),S.useEffect(function(){Object.assign(f.current.props,{...h}),b(f.current)},[h]),a.current?xt.createPortal(e.children,a.current):null}),de=st();function he(){const t=S.useRef(de),[e,n]=S.useState(!1),[o,i]=S.useState(t.current);return S.useEffect(()=>{i(t.current)},[t.current]),{props:S.useMemo(()=>({ref:t,isOpen:e,setIsOpen:n}),[e]),instance:o}}D.BottomSheet=ue,D.createPlaceholderBottomSheet=st,D.useBottomSheet=he,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,C){typeof exports=="object"&&typeof module<"u"?C(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],C):(D=typeof globalThis<"u"?globalThis:D||self,C(D.BottomSheet={},D.React,D.ReactDOM))})(this,function(D,C,At){"use strict";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 Bt=Object.defineProperty,Mt=(t,e,n)=>e in t?Bt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,z=(t,e,n)=>Mt(t,typeof e!="symbol"?e+"":e,n);function O(t){return typeof t=="string"}function Pt(t,e){return t.classList.contains(V(e))}function G(t,e){t.classList.add(V(e))}function ot(t,e){t.classList.remove(V(e))}function _(t,e,n){O(n)&&(O(e)&&ot(t,e),G(t,n))}function V(t){return O(t)?t.trim().replace(/\./g,""):""}function I(t){return t.map(e=>V(e)).filter(Boolean).join(" ")}function Yt(t){return t.map(e=>e==null?void 0:e.trim()).filter(Boolean).map(e=>`.${e}`).join(" ")}const dt="open",ht="hidden";function rt(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{K(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}K(t,n),t.setAttribute("aria-modal",n?"true":"false")}function K(t,e){e?(G(t,dt),ot(t,ht)):(G(t,ht),ot(t,dt))}function pt(t){return t instanceof HTMLElement}function x(t){return typeof t=="number"&&!Number.isNaN(t)}function It(t){pt(t)&&t.focus()}function Rt(t){if(!pt(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 T=(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))(T||{}),it=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(it||{}),J=(t=>(t.Hidden="hidden",t))(J||{});function Y(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{G(o,i)}),O(n)&&o.setAttribute("data-testid",n),o}Yt([T.Root,T.ContentWrapper]);function mt(t,e,n,o){switch(o){case"content-height":return e>=t?vt(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function ft(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function gt(t,e){return e<t?-(t-e):e-t}function Q(t,e){return t>e?t-e:e-t}function Nt(t,e){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function bt(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 vt(t,e,n){return-(t-e)+n}function St(t){return Number(t.replace("px",""))}function Z(t,...e){return Number(t.toFixed(...e))}function Ct(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(s=>s.trim());n.push({type:i,values:r})}return n}function Ft(t){const e=t.style.transform,n=Ct(e);return{transform:e,transformValues:n}}function yt(t,e){return t.find(o=>o.type.startsWith(e))||null}const at="translate";function P(t){const e=t.style.transform,n=Ct(e),o=yt(n,at);return Et(o??{type:at,values:[]})}function tt(t,{x:e,y:n}){const{transform:o,transformValues:i}=Ft(t),r=yt(i,at);if(r){const s=Et(r);t.style.transform=`translate(${e??s.x??0}px,${n??s.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 Et(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:St(e)??0,y:St(n)??0}}function st(t){return t!=null}function wt(t,{min:e,max:n}){return st(n)&&t>=n?n:st(e)&&t<=e?e:t}const Wt=(t,e,n)=>{e instanceof HTMLElement&&!Pt(e,T.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},jt=(t,e,n,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=P(e),n.onDragStart()},Ut=(t,e,n,o,i)=>r=>{$t(r,t,n,o,i,e,n.marginTop)};function $t(t,e,n,o,i,r,s){if(!o.isDragging||!x(o.startY))return;const a=e.getCoordinates(t).y,d=gt(o.startY,a),p=window.innerHeight,c=r.clientHeight,m=c-(o.containerStartTranslate.y+d);if(m>=p)return;const y=ft(o.startY,a);if(y.isUp&&!n.expandable&&m>=c)return;i.start(()=>{tt(r,{y:o.containerStartTranslate.y+d})},0);const l=p-s,E=c-o.containerStartTranslate.y;if(y.isUp){const v=l-E,S=l-m,w=wt(1-Z(S/v,2),{min:0,max:1});n.onDragMove(y,w)}else if(y.isDown){const v=wt(Z(1-m/E,2),{min:0,max:1});n.onDragMove(y,v)}}const Gt=(t,e,n,o,i,r,s)=>a=>{if(!o.isDragging||(o.isDragging=!1,!x(o.startY)))return;n.onDragEnd();const d=o.startY,p=t.getCoordinates(a).y,c=P(e).y,m=ft(d,p),y=window.innerHeight,l=e.clientHeight;if(m.isUp){const E=[...n.snapPoints].sort((w,L)=>w-L),v=l+-c;if(!n.expandable&&v>=l)return;for(const w of E){const L=w*window.innerHeight;if(v<=L){const H=Q(v,L);s.translateContainer({startY:c,endY:c-H,animationFrame:i,bottomSheetContainer:e});return}}const S=vt(y,l,n.marginTop);s.translateContainer({startY:c,endY:S,animationFrame:i,bottomSheetContainer:e})}else if(m.isDown){const E=[...n.snapPoints].sort((v,S)=>S-v);for(const v of E){const S=v*window.innerHeight,w=l+-c;if(w>=S){const L=Q(w,S);s.translateContainer({startY:c,endY:c+L,animationFrame:i,bottomSheetContainer:e});return}}r()}};var R=(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))(R||{});function Tt(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const _t={eventPhase:R.All};class X{constructor(e){z(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=_t,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===R.All){e(r);return}Tt(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===R.All){e(r);return}Tt(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 Ht(t){const e=t;return`${e} ${e} 0px 0px`}function Xt(t,e){const n=qt(t);zt(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=Vt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function qt(t){const e=Y("dialog",I([T.Root,it.Dialog,t.rootClass]),T.Root);e.ariaLabel=t.ariaLabel;const n=Y("section",I([T.Container,t.containerClass]),T.Container);t.containerBorderRadius&&(n.style.borderRadius=Ht(t.containerBorderRadius));const o=Y("div",T.GapFiller,T.GapFiller),i=Y("button",I([T.Handle,it.Button,t.shouldShowHandle?null:J.Hidden,t.handleClass]),T.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=Y("span",I([T.HandleBar,t.shouldShowHandle?null:J.Hidden]),T.HandleBar),s=Y("article",I([T.ContentWrapper,t.contentWrapperClass]),T.ContentWrapper),a=Y("div",I([T.Backdrop,t.backdropClass,J.Hidden]),T.Backdrop);return t.backdropColor&&(a.style.backgroundColor=t.backdropColor),t.backDropTransition&&(a.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:a,bottomSheetContainer:n,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:s,bottomSheetContainerGapFiller:o}}function zt({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 Vt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:s,bottomSheetContentWrapper:a,bottomSheetBackdrop:d}=t,{animationFrame:p}=n,c=new X(r),m=new X(a),y=new X(s),l=e.dragTriggers.reduce((b,B)=>{const M=o.querySelectorAll(B);if(!M.length)return b;const h=Array.from(M).map(u=>u instanceof HTMLElement?new X(u):null).filter(u=>!!u);return[...b,...h]},[]),E=new X(window),v=jt(E,i,e,n.draggingState),S=Ut(E,i,e,n.draggingState,p),w=Gt(E,i,e,n.draggingState,p,n.onClose,n.bottomSheetState);function L(b){b.target instanceof Element&&!o.contains(b.target)&&n.onClose()}function H(b){Wt(n.draggingState,b.target,t.bottomSheetContentWrapper)}function j(){e.draggable&&(c.addEventListeners({onStart:H}),l.forEach(b=>{b.addEventListeners({onStart:H,onStartOptions:{eventPhase:R.Target}})})),e.draggable&&e.backgroundDraggable&&(m.addEventListeners({onStart:H,onStartOptions:{eventPhase:R.Target}}),y.addEventListeners({onStart:H})),e.draggable&&E.addEventListeners({onStart:v,onMove:S,onEnd:w}),e.draggable&&window.document.addEventListener("keyup",b=>{b.key==="Escape"&&n.onClose()}),r.addEventListener("keyup",b=>{if(b.key==="ArrowUp"){n.moveUp();return}if(b.key==="ArrowDown"){n.moveDown();return}if(b.shiftKey&&b.key==="Tab"){const B=U(t.bottomSheetContentWrapper);It(B)}})}function et(){e.shouldCloseOnOutsideClick?d.addEventListener("click",L):d.style.pointerEvents="none"}function q(){d.removeEventListener("click",L)}function U(b){let B=[...Array.from(b.childNodes).reverse()];for(;B.length;){const M=B.shift();if(Rt(M))return M;M&&(B=[...B,...Array.from(M.childNodes).reverse()])}return null}function nt(){c.removeEventListeners({onStart:H}),m.removeEventListeners({onStart:H}),y.removeEventListeners({onStart:H}),l.forEach(b=>{b.removeEventListeners({onStart:H})}),E.removeEventListeners({onStart:v,onMove:S,onEnd:w})}return{attachEventListeners:j,clearEventListeners:nt,attacheOnOpenEventListeners:et,clearOnOpenEventListeners:q}}class Kt{constructor(){z(this,"animationId"),z(this,"isInProgress"),z(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 s=r-this.startedAt,a=n===0?1:Z(s/n,2),d=a>=1&&!o;e(a),d?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,x(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Jt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:s,animationDuration:a}=t,d=gt(e,n);i.stop();let p=!1;i.start(c=>{tt(o,{y:e+d*s(c)}),!p&&c>=1&&(r==null||r(),p=!0)},a)}const ct=(t,e)=>n=>{Jt({...n,animationTimingFunction:t,animationDuration:e})},N={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Qt(t){return!(!x(t)||t>1||t<0)}function Zt(t,e){const n={set(o,i,r,s){return e(i,r),Reflect.set(o,i,r,s)}};return new Proxy(t,n)}function te(...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 ee(t){for(const e of Object.values(F))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 W(t,e,n,o){return function(a){return s(i(a))};function i(a){let d=0,p=1,c=a,m;if(a===0||a===1)return a;for(;d<p;){if(m=r(c),Math.abs(m-a)<.001)return c;a>m?d=c:p=c,c=(p+d)/2}return c}function r(a){return 3*t*a*Math.pow(1-a,2)+3*n*Math.pow(a,2)*(1-a)+Math.pow(a,3)}function s(a){return 3*e*a*Math.pow(1-a,2)+3*o*Math.pow(a,2)*(1-a)+Math.pow(a,3)}}const Ot=W(.25,.1,.25,1),ne=W(.42,0,1,1),Lt=W(.42,0,.58,1),oe=W(.4,.1,.6,1),re=W(.45,1.5,.55,1);function ie(t){switch(t){case F.EASE:return Ot;case F.EASE_IN:return ne;case F.EASE_OUT:return Lt;case F.EASE_IN_OUT:return oe;case F.SPRING:return re;default:return Ot}}function xt(t){return typeof t=="boolean"}const ae={ariaLabel:"Bottom sheet",content:"",defaultPosition:N.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 se(t){const e={...ae},n=Object.entries(t).reduce((o,i)=>{const[r,s]=i;return st(s)&&(o[r]=s),o},{});return{...e,...n}}function lt(t){if(kt(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return W(e,n,o,i)}return ee(t)?ie(t):Lt}function ce(t,e,n){function o(i,r){switch(i){case"content":O(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":O(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":xt(r)||K(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":xt(r)||K(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":O(r)&&(t.bottomSheetContainer.style.borderRadius=Ht(r));break;case"backdropColor":O(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":O(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!O(r))return;_(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!O(r))return;_(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!O(r))return;_(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!O(r))return;_(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!O(r))return;_(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(kt(r)){const s=lt(r),a=ct(s,n.draggingAnimationDuration);e.translateContainer=a}break;case"draggingAnimationDuration":if(x(r)){const s=lt(n.draggingAnimationTimings),a=ct(s,r);e.translateContainer=a}break}}return o}function le(t){const e=se(t),n=lt(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:ct(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 s=new Kt,a={animationFrame:s,onClose:w,bottomSheetState:o,draggingState:i,snapTo:M,moveUp:b,moveDown:B},{elements:d,eventHandlers:p}=Xt(e,a),c=Zt(e,ce(d,o,e)),{bottomSheetBackdrop:m,bottomSheetRoot:y,bottomSheetContainer:l}=d,E=h=>{const u=h??window.document.body;u.appendChild(y),u.appendChild(m);const f=window.innerHeight;tt(l,{y:f}),p.attachEventListeners(),o.isMounted=!0},v=()=>{p.clearEventListeners(),Object.values(d).forEach(h=>{h.remove()}),r(),o.isMounted=!1},S=()=>{var h;if(L()||te('Bottom Sheet is not mounted yet. call the "mount" method first.'),(h=t.beforeOpen)==null||h.call(t),H())return;rt(m,!0),c.shouldShowBackdrop||G(m,"transparent"),rt([l],!0),tt(l,{y:l.clientHeight});const u=window.innerHeight,f=mt(u,l.clientHeight,c.marginTop,c.defaultPosition),g=P(l).y;o.translateContainer({startY:g,endY:f,animationFrame:s,bottomSheetContainer:l,onEnd:t.afterOpen});const k=document.body.style.overflowY;i.originalDocumentOverflowY=k||"initial";const A=document.body.style.overscrollBehavior;i.originalDocumentOverscrollBehavior=A||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",d.bottomSheetHandle.focus(),p.attacheOnOpenEventListeners()};function w(){var h;if(j())return;(h=t.beforeClose)==null||h.call(t);const u=P(l).y,f=l.clientHeight;o.translateContainer({startY:u,endY:f,animationFrame:s,bottomSheetContainer:l,onEnd:()=>{var g;(g=t.afterClose)==null||g.call(t),rt([m,l],!1),p.clearOnOpenEventListeners()}}),r()}function L(){return o.isMounted}function H(){const h=P(l).y,u=window.innerHeight,f=l.clientHeight>=u?u:l.clientHeight;return h<=f}function j(){return!H()}function et(){const h=P(l).y,u=l.clientHeight,f=window.innerHeight;if(h<=5&&h>=-5)return N.CONTENT_HEIGHT;const g=u-h;if(g===f/2)return N.MIDDLE;const k=f-c.marginTop,A=10;return g<=k+A&&g>=k-A?N.TOP:N.CLOSED}function q(){return l.clientHeight}function U(h){if(!H())return;const u=P(l).y,f=l.clientHeight-u,g=window.innerHeight-h,k=Nt(f,g),A=Q(f,g);o.translateContainer({startY:u,endY:u+(k.isUp?-A:A),animationFrame:s,bottomSheetContainer:l})}function nt(h,{viewportHeight:u,visibleHeight:f}){let g=null;for(const k of h){const A=k*u,$=Q(f,A);(g===null||$<g)&&(g=$)}return{minOffset:g}}function b(){const h=[...c.snapPoints].reverse(),u=P(l).y,f=l.clientHeight,g=f-u;if(!c.expandable&&g>=f)return;const k=window.innerHeight,A=bt("above",{visibleHeight:g,viewportHeight:k},h),{minOffset:$}=nt(A,{visibleHeight:g,viewportHeight:k});if($===null&&g<k-c.marginTop){o.translateContainer({startY:u,endY:mt(k,f,c.marginTop,"top"),animationFrame:s,bottomSheetContainer:l});return}x($)&&o.translateContainer({startY:u,endY:u-$,animationFrame:s,bottomSheetContainer:l})}function B(){const h=P(l).y,u=l.clientHeight-h;if(u<1)return;const f=window.innerHeight,g=bt("below",{visibleHeight:u,viewportHeight:f},c.snapPoints),{minOffset:k}=nt(g,{visibleHeight:u,viewportHeight:f});x(k)&&o.translateContainer({startY:h,endY:h+k,animationFrame:s,bottomSheetContainer:l})}function M(h){const u=window.innerHeight;if(!Qt(h))return;const f=Z(u*h,2);U(f)}return{props:c,elements:d,mount:E,unmount:v,open:S,close:w,getIsMounted:L,getIsOpen:H,getIsClosed:j,getPosition:et,getHeight:q,moveTo:U,snapTo:M}}function ut(){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:()=>N.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ue=ut(),de=C.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:s,mountingPointRef:a,...d}=e,p=C.useRef(ue),[c,m]=C.useState(p.current);C.useImperativeHandle(n,()=>c,[c]);const y=C.useCallback(()=>{r(!1),s==null||s()},[s]);C.useEffect(()=>{i?c.open():c.close()},[i]);const l=C.useRef(null);return C.useEffect(function(){var w;if(a&&!a.current)return;const v=Dt((w=e.mountingPointRef)==null?void 0:w.current)?e.mountingPointRef.current:window.document.body;if(!v||c.getIsMounted())return;const S=le({content:"",...d,afterClose:y});return S.mount(v),l.current=S.elements.bottomSheetContentWrapper??null,p.current=S,m(S),()=>{c.unmount()}},[e.mountingPointRef,d,y]),C.useEffect(function(){Object.assign(p.current.props,{...d}),m(p.current)},[d]),C.useEffect(function(){return()=>{p.current.unmount()}},[]),l.current?At.createPortal(e.children,l.current):null}),he=ut();function pe(t={}){const e=C.useRef(he),[n,o]=C.useState(!1),[i,r]=C.useState(e.current);C.useEffect(()=>{r(e.current)},[e.current]);const{beforeOpen:s,afterOpen:a,beforeClose:d,afterClose:p,onDragStart:c,onDragMove:m,onDragEnd:y,...l}=t,E=()=>{s==null||s()},v=()=>{a==null||a(),o(!0)},S=()=>{d==null||d()},w=()=>{p==null||p(),o(!1)},L=()=>{c==null||c()},H=(q,U)=>{m==null||m(q,U)},j=()=>{y==null||y()};return{props:C.useMemo(()=>({ref:e,isOpen:n,setIsOpen:o,beforeOpen:E,afterOpen:v,beforeClose:S,afterClose:w,onDragStart:L,onDragMove:H,onDragEnd:j,...l}),[e.current,n,o,t]),instance:i,isOpen:n,setIsOpen:o}}D.BottomSheet=de,D.createPlaceholderBottomSheet=ut,D.useBottomSheet=pe,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plainsheet/react",
3
- "version": "0.4.0",
3
+ "version": "0.4.4",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@plainsheet/core": "0.7.0",
34
+ "@plainsheet/core": "0.7.4",
35
35
  "@plainsheet/utility": "0.0.3"
36
36
  },
37
37
  "devDependencies": {
@@ -48,15 +48,15 @@
48
48
  "typescript": "^5.5.3",
49
49
  "typescript-eslint": "^8.0.0",
50
50
  "vite": "^5.4.0",
51
- "vitest": "^1.6.0",
52
- "vite-plugin-dts": "^3.8.1"
51
+ "vite-plugin-dts": "^3.8.1",
52
+ "vitest": "^1.6.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": "^18",
56
56
  "react-dom": "^18"
57
57
  },
58
58
  "scripts": {
59
- "dev": "vite build --watch --mode development",
59
+ "dev": "vite build --watch --mode development --emptyOutDir=false",
60
60
  "build": "tsc --noEmit && vite build",
61
61
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
62
62
  "lint": "eslint . --max-warnings 0",