@plainsheet/react 0.4.10 → 0.4.12

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(M,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):(M=typeof globalThis<"u"?globalThis:M||self,S(M.BottomSheet={},M.React,M.ReactDOM))})(this,function(M,S,xe){"use strict";function Ae(e){return e!=null}(function(){try{if(typeof document<"u"){var e=document.createElement("style");e.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(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();var De=Object.defineProperty,Me=(e,t,n)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J=(e,t,n)=>Me(e,typeof t!="symbol"?t+"":t,n);function L(e){return typeof e=="string"}function Pe(e,t){return e.classList.contains(Q(t))}function _(e,t){e.classList.add(Q(t))}function oe(e,t){e.classList.remove(Q(t))}function X(e,t,n){L(n)&&(L(t)&&oe(e,t),_(e,n))}function Q(e){return L(e)?e.trim().replace(/\./g,""):""}function R(e){return e.map(t=>Q(t)).filter(Boolean).join(" ")}function Ye(e){return e.map(t=>t==null?void 0:t.trim()).filter(Boolean).map(t=>`.${t}`).join(" ")}const de="open",pe="hidden";function re(e,t){const n=t;if(Array.isArray(e)){e.forEach(o=>{Z(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}Z(e,n),e.setAttribute("aria-modal",n?"true":"false")}function Z(e,t){t?(_(e,de),oe(e,pe)):(_(e,pe),oe(e,de))}function he(e){return e instanceof HTMLElement}function A(e){return typeof e=="number"&&!Number.isNaN(e)}function Re(e){he(e)&&e.focus()}function Fe(e){if(!he(e)||e.offsetParent===null||"disabled"in e&&e.disabled)return!1;const t=e.getAttribute("tabindex"),n=A(t)?parseInt(t,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(e.tagName),r=e instanceof HTMLAnchorElement&&e.href!==""||e instanceof HTMLAreaElement&&e.href!=="";return o||r||n>-1}var k=(e=>(e.Backdrop="pbs-backdrop",e.Root="pbs-root",e.Container="pbs-container",e.GapFiller="pbs-gap-filler",e.Handle="pbs-handle",e.HandleBar="pbs-handle-bar",e.ContentWrapper="pbs-content-wrapper",e))(k||{}),ae=(e=>(e.Button="pbs-button-reset",e.Dialog="pbs-dialog-reset",e))(ae||{}),ee=(e=>(e.Hidden="hidden",e))(ee||{});function Y(e,t,n){const o=document.createElement(e);return t.split(" ").forEach(r=>{_(o,r)}),L(n)&&o.setAttribute("data-testid",n),o}Ye([k.Root,k.ContentWrapper]);function me(e,t,n,o){switch(o){case"content-height":return t>=e?ve(e,t,n):0;case"middle":return-(e/2-t);case"top":return-(e-t)+n;default:return 0}}function fe(e,t){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function be(e,t){return t<e?-(e-t):t-e}function q(e,t){return e>t?e-t:t-e}function Ie(e,t){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function ge(e,t,n){const o=e==="above";return n.filter(r=>{const i=r*t.viewportHeight;return o?t.visibleHeight<i:t.visibleHeight>i})}function ve(e,t,n){return-(e-t)+n}function Se(e){return Number(e.replace("px",""))}function te(e,...t){return Number(e.toFixed(...t))}function ye(e){const t=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=t.exec(e))!==null;){const r=o[1],i=o[2].split(",").map(a=>a.trim());n.push({type:r,values:i})}return n}function We(e){const t=e.style.transform,n=ye(t);return{transform:t,transformValues:n}}function Ce(e,t){return e.find(o=>o.type.startsWith(t))||null}const ie="translate";function P(e){const t=e.style.transform,n=ye(t),o=Ce(n,ie);return Ee(o??{type:ie,values:[]})}function ne(e,{x:t,y:n}){const{transform:o,transformValues:r}=We(e),i=Ce(r,ie);if(i){const a=Ee(i);e.style.transform=`translate(${t??a.x??0}px,${n??a.y??0}px)`;return}if(o){e.style.transform=`${o}, translate(${t??0}px,${n??0}px)`;return}e.style.transform=`translate(${t??0}px,${n??0}px)`}function Ee(e){if(e.type!=="translate")throw new Error(`Could not get coordinates from ${e.type}, since is not translate.`);const t=e.values[0],n=e.values[1];return{x:Se(t)??0,y:Se(n)??0}}function se(e){return e!=null}function we(e,{min:t,max:n}){return se(n)&&e>=n?n:se(t)&&e<=t?t:e}const Ne=(e,t,n)=>{t instanceof HTMLElement&&!Pe(t,k.Handle)&&n.scrollTop>=1||(e.isDragging=!0)},je=(e,t,n,o)=>r=>{o.startY=e.getCoordinates(r).y,o.containerStartTranslate=P(t),n.onDragStart()},Ge=(e,t,n,o,r)=>i=>{Ue(i,e,n,o,r,t,n.marginTop)};function Ue(e,t,n,o,r,i,a){if(!o.isDragging||!A(o.startY))return;const l=t.getCoordinates(e).y,u=be(o.startY,l),h=window.innerHeight,c=i.clientHeight,f=c-(o.containerStartTranslate.y+u);if(f>=h)return;const C=fe(o.startY,l);if(C.isUp&&!n.expandable&&f>=c||n.preventClosing&&f<=c)return;r.start(()=>{ne(i,{y:o.containerStartTranslate.y+u})},0);const s=h-a,E=c-o.containerStartTranslate.y;if(C.isUp){const v=s-E,y=s-f,w=we(1-te(y/v,2),{min:0,max:1});n.onDragMove(C,w)}else if(C.isDown){const v=we(te(1-f/E,2),{min:0,max:1});n.onDragMove(C,v)}}const $e=(e,t,n,o,r,i,a)=>l=>{if(!o.isDragging||(o.isDragging=!1,!A(o.startY)))return;n.onDragEnd();const u=o.startY,h=e.getCoordinates(l).y,c=P(t).y,f=fe(u,h),C=window.innerHeight,s=t.clientHeight;if(f.isUp){const E=[...n.snapPoints].sort((w,x)=>w-x),v=s+-c;if(!n.expandable&&v>=s)return;for(const w of E){const x=w*window.innerHeight;if(v<=x){const T=q(v,x);a.translateContainer({startY:c,endY:c-T,animationFrame:r,bottomSheetContainer:t});return}}const y=ve(C,s,n.marginTop);a.translateContainer({startY:c,endY:y,animationFrame:r,bottomSheetContainer:t})}else if(f.isDown){const E=[...n.snapPoints].sort((v,y)=>y-v);for(const v of E){const y=v*window.innerHeight,w=s+-c;if(w>=y){const x=q(w,y);a.translateContainer({startY:c,endY:c+x,animationFrame:r,bottomSheetContainer:t});return}}if(n.preventClosing){const v=s+-c;if(v>=s){const y=q(v,s);a.translateContainer({startY:c,endY:c+y,animationFrame:r,bottomSheetContainer:t})}return}i()}};var F=(e=>(e[e.All=-1]="All",e[e.None=0]="None",e[e.Capture=1]="Capture",e[e.Target=2]="Target",e[e.Bubble=3]="Bubble",e))(F||{});function ke(e){switch(e){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const _e={eventPhase:F.All};class z{constructor(t){J(this,"currentTarget"),this.currentTarget=t}addEventListeners({onStart:t,onStartOptions:n=_e,onMove:o,onEnd:r}){this.addTouchEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}),this.addMouseEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r})}addTouchEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}){t&&this.currentTarget.addEventListener("touchstart",i=>{if(n.eventPhase===F.All){t(i);return}ke(i.eventPhase)===n.eventPhase&&t(i)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),r&&this.currentTarget.addEventListener("touchend",r)}addMouseEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}){t&&this.currentTarget.addEventListener("mousedown",i=>{if(n.eventPhase===F.All){t(i);return}ke(i.eventPhase)===n.eventPhase&&t(i)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),r&&this.currentTarget.addEventListener("mouseup",i=>{r(i)})}removeEventListeners({onStart:t,onMove:n,onEnd:o}){t&&this.currentTarget.removeEventListener("touchstart",t),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),t&&this.currentTarget.removeEventListener("mousedown",t),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(t){if(t.type==="touchstart"||t.type==="mousedown"){if("touches"in t)return{x:t.touches[0].clientX,y:t.touches[0].clientY};if(t instanceof MouseEvent)return{x:t.clientX,y:t.clientY}}if(t.type==="touchend"||t.type==="mouseup"||t.type==="mousemove"||t.type==="touchmove"){if("touches"in t)return{x:t.changedTouches[0].clientX,y:t.changedTouches[0].clientY};if(t instanceof MouseEvent)return{x:t.clientX,y:t.clientY}}return{x:0,y:0}}}function Te(e){const t=e;return`${t} ${t} 0px 0px`}function Xe(e,t){const n=qe(e);ze(n),n.bottomSheetContainer.style.width=e.width;const o=document.createElement("div");o.innerHTML=e.content??"";const r=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${r}px`,n.bottomSheetContentWrapper.appendChild(o);const i=Ve({bottomSheetElements:n,bottomSheetProps:e,options:t});return e.rootStyle&&Object.assign(n.bottomSheetRoot.style,e.rootStyle),e.backdropStyle&&Object.assign(n.bottomSheetBackdrop.style,e.backdropStyle),e.containerGapFillerStyle&&Object.assign(n.bottomSheetContainer.style,e.containerStyle),e.containerStyle&&Object.assign(n.bottomSheetContainerGapFiller.style,e.containerGapFillerStyle),e.handleStyle&&Object.assign(n.bottomSheetHandleBar.style,e.handleStyle),e.contentWrapperStyle&&Object.assign(n.bottomSheetContentWrapper.style,e.contentWrapperStyle),{elements:n,eventHandlers:i}}function qe(e){const t=Y("dialog",R([k.Root,ae.Dialog,e.rootClass]),k.Root);t.ariaLabel=e.ariaLabel;const n=Y("section",R([k.Container,e.containerClass]),k.Container);e.containerBorderRadius&&(n.style.borderRadius=Te(e.containerBorderRadius));const o=Y("div",k.GapFiller,k.GapFiller);e.containerBackgroundColor&&(n.style.backgroundColor=e.containerBackgroundColor,o.style.backgroundColor=e.containerBackgroundColor);const r=Y("button",R([k.Handle,ae.Button,e.shouldShowHandle?null:ee.Hidden,e.handleClass]),k.Handle);r.setAttribute("type","button"),r.ariaLabel="bottom sheet close button";const i=Y("span",R([k.HandleBar,e.shouldShowHandle?null:ee.Hidden]),k.HandleBar),a=Y("article",R([k.ContentWrapper,e.contentWrapperClass]),k.ContentWrapper),l=Y("div",R([k.Backdrop,e.backdropClass,ee.Hidden]),k.Backdrop);return e.backdropColor&&(l.style.backgroundColor=e.backdropColor),e.backDropTransition&&(l.style.transition=e.backDropTransition),{bottomSheetRoot:t,bottomSheetBackdrop:l,bottomSheetContainer:n,bottomSheetHandle:r,bottomSheetHandleBar:i,bottomSheetContentWrapper:a,bottomSheetContainerGapFiller:o}}function ze({bottomSheetRoot:e,bottomSheetContainer:t,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:r,bottomSheetContainerGapFiller:i}){e.appendChild(t),n.appendChild(o),t.appendChild(n),t.appendChild(r),t.appendChild(i)}function Ve({bottomSheetElements:e,bottomSheetProps:t,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:r,bottomSheetHandle:i,bottomSheetContainerGapFiller:a,bottomSheetContentWrapper:l,bottomSheetBackdrop:u}=e,{animationFrame:h}=n,c=new z(i),f=new z(l),C=new z(a);let s=[];const E=new z(window),v=je(E,r,t,n.draggingState),y=Ge(E,r,t,n.draggingState,h),w=$e(E,r,t,n.draggingState,h,n.onClose,n.bottomSheetState);function x(H){H.target instanceof Element&&!o.contains(H.target)&&n.onClose()}function T(H){Ne(n.draggingState,H.target,e.bottomSheetContentWrapper)}function j(H){const B=H??t;B.draggable&&B.backgroundDraggable&&(f.addEventListeners({onStart:T,onStartOptions:{eventPhase:F.Target}}),C.addEventListeners({onStart:T})),B.draggable&&E.addEventListeners({onStart:v,onMove:y,onEnd:w}),B.draggable&&window.document.addEventListener("keyup",b=>{b.key==="Escape"&&n.onClose()}),i.addEventListener("keyup",b=>{if(b.key==="ArrowUp"){n.moveUp();return}if(b.key==="ArrowDown"){n.moveDown();return}if(b.shiftKey&&b.key==="Tab"){const d=G(e.bottomSheetContentWrapper);Re(d)}})}function V(H){const B=H??t;t.shouldCloseOnOutsideClick&&!t.preventClosing?u.addEventListener("click",x):u.style.pointerEvents="none",B.draggable&&(c.addEventListeners({onStart:T}),s.forEach(b=>{b.removeEventListeners({onStart:T})}),s=t.dragTriggers.reduce((b,d)=>{const p=o.querySelectorAll(d);if(!p.length)return b;const g=Array.from(p).map(m=>m instanceof HTMLElement?new z(m):null).filter(m=>!!m);return[...b,...g]},[]),s.forEach(b=>{b.addEventListeners({onStart:T,onStartOptions:{eventPhase:F.Target}})}))}function K(){u.removeEventListener("click",x)}function G(H){let B=[...Array.from(H.childNodes).reverse()];for(;B.length;){const b=B.shift();if(Fe(b))return b;b&&(B=[...B,...Array.from(b.childNodes).reverse()])}return null}function U(){c.removeEventListeners({onStart:T}),f.removeEventListeners({onStart:T}),C.removeEventListeners({onStart:T}),s.forEach(H=>{H.removeEventListeners({onStart:T})}),E.removeEventListeners({onStart:v,onMove:y,onEnd:w})}return{attachEventListeners:j,clearEventListeners:U,attacheOnOpenEventListeners:V,clearOnOpenEventListeners:K}}class Ke{constructor(){J(this,"animationId"),J(this,"isInProgress"),J(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(t,n,o=!1){this.isInProgress=!0;const r=i=>{this.startedAt||(this.startedAt=i);const a=i-this.startedAt,l=n===0?1:te(a/n,2),u=l>=1&&!o;t(l),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 Je(e){const{startY:t,endY:n,bottomSheetContainer:o,animationFrame:r,onEnd:i,animationTimingFunction:a,animationDuration:l}=e,u=be(t,n);r.stop();let h=!1;r.start(c=>{ne(o,{y:t+u*a(c)}),!h&&c>=1&&(i==null||i(),h=!0)},l)}const ce=(e,t)=>n=>{Je({...n,animationTimingFunction:e,animationDuration:t})},I={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Qe(e){return!(!A(e)||e>1||e<0)}function Ze(e,t){const n={set(o,r,i,a){return t(r,i),Reflect.set(o,r,i,a)}};return new Proxy(e,n)}function et(...e){console.error(e)}const W={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function tt(e){for(const t of Object.values(W))if(t===e)return!0;return!1}function He(e){return!!(e instanceof Object&&"p1x"in e&&"p1y"in e&&"p2x"in e&&"p2y"in e&&A(e.p1x)&&A(e.p1y)&&A(e.p2x)&&A(e.p2y))}function N(e,t,n,o){return function(l){return a(r(l))};function r(l){let u=0,h=1,c=l,f;if(l===0||l===1)return l;for(;u<h;){if(f=i(c),Math.abs(f-l)<.001)return c;l>f?u=c:h=c,c=(h+u)/2}return c}function i(l){return 3*e*l*Math.pow(1-l,2)+3*n*Math.pow(l,2)*(1-l)+Math.pow(l,3)}function a(l){return 3*t*l*Math.pow(1-l,2)+3*o*Math.pow(l,2)*(1-l)+Math.pow(l,3)}}const Oe=N(.25,.1,.25,1),nt=N(.42,0,1,1),Le=N(.42,0,.58,1),ot=N(.4,.1,.6,1),rt=N(.45,1.5,.55,1);function at(e){switch(e){case W.EASE:return Oe;case W.EASE_IN:return nt;case W.EASE_OUT:return Le;case W.EASE_IN_OUT:return ot;case W.SPRING:return rt;default:return Oe}}function Be(e){return typeof e=="boolean"}const it={ariaLabel:"Bottom sheet",content:"",defaultPosition:I.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,preventClosing:!1,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBackgroundColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180,rootStyle:{},containerStyle:{},handleStyle:{},contentWrapperStyle:{},backdropStyle:{},containerGapFillerStyle:{}};function st(e){const t={...it},n=Object.entries(e).reduce((o,r)=>{const[i,a]=r;return se(a)&&(o[i]=a),o},{});return{...t,...n}}function le(e){if(He(e)){const{p1x:t,p1y:n,p2x:o,p2y:r}=e;return N(t,n,o,r)}return tt(e)?at(e):Le}function ct(e,t,n,o){function r(i,a){switch(i){case"content":L(a)&&(e.bottomSheetContentWrapper.innerHTML=a);break;case"width":L(a)&&(e.bottomSheetContainer.style.width=a);break;case"shouldShowHandle":Be(a)||Z(e.bottomSheetHandle,!1);break;case"shouldShowBackdrop":Be(a)||Z(e.bottomSheetBackdrop,!1);break;case"containerBorderRadius":L(a)&&(e.bottomSheetContainer.style.borderRadius=Te(a));break;case"containerBackgroundColor":L(a)&&(e.bottomSheetContainer.style.backgroundColor=a,e.bottomSheetContainerGapFiller.style.backgroundColor=a);break;case"backdropColor":L(a)&&(e.bottomSheetBackdrop.style.backgroundColor=a);break;case"backDropTransition":L(a)&&(e.bottomSheetBackdrop.style.transition=a);break;case"rootClass":if(!L(a))return;X(e.bottomSheetRoot,n.rootClass,a);break;case"containerClass":if(!L(a))return;X(e.bottomSheetContainer,n.containerClass,a);break;case"handleClass":if(!L(a))return;X(e.bottomSheetHandle,n.handleClass,a);break;case"contentWrapperClass":if(!L(a))return;X(e.bottomSheetContentWrapper,n.contentWrapperClass,a);break;case"backdropClass":if(!L(a))return;X(e.bottomSheetBackdrop,n.backdropClass,a);break;case"expandable":o.clearEventListeners(),o.attachEventListeners(n);break;case"preventClosing":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggable":o.clearEventListeners(),o.attachEventListeners(n);break;case"dragTriggers":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggingAnimationTimings":if(He(a)){const l=le(a),u=ce(l,n.draggingAnimationDuration);t.translateContainer=u}break;case"draggingAnimationDuration":if(A(a)){const l=le(n.draggingAnimationTimings),u=ce(l,a);t.translateContainer=u}break;case"rootStyle":n.rootStyle&&Object.assign(e.bottomSheetRoot.style,n.rootStyle);break;case"backdropStyle":n.backdropStyle&&Object.assign(e.bottomSheetBackdrop.style,n.backdropStyle);break;case"containerStyle":n.containerStyle&&Object.assign(e.bottomSheetContainer.style,n.containerStyle);break;case"containerGapFillerStyle":n.containerGapFillerStyle&&Object.assign(e.bottomSheetContainerGapFiller.style,n.containerGapFillerStyle);break;case"handleStyle":n.handleStyle&&Object.assign(e.bottomSheetHandleBar.style,n.handleStyle);break;case"contentWrapperStyle":n.contentWrapperStyle&&Object.assign(e.bottomSheetContentWrapper.style,n.contentWrapperStyle);break}}return r}function lt(e){const t=st(e),n=le(e.draggingAnimationTimings),o={isMounted:!1,translateContainer:ce(n,t.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function i(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const a=new Ke,l={animationFrame:a,onClose:w,bottomSheetState:o,draggingState:r,snapTo:b,moveUp:H,moveDown:B},{elements:u,eventHandlers:h}=Xe(t,l),c=Ze(t,ct(u,o,t,h)),{bottomSheetBackdrop:f,bottomSheetRoot:C,bottomSheetContainer:s}=u,E=d=>{const p=d??window.document.body;p.appendChild(C),p.appendChild(f);const g=window.innerHeight;ne(s,{y:g}),h.attachEventListeners(),o.isMounted=!0},v=()=>{h.clearEventListeners(),Object.values(u).forEach(d=>{d.remove()}),i(),o.isMounted=!1},y=()=>{var d;if(x()||et('Bottom Sheet is not mounted yet. call the "mount" method first.'),(d=e.beforeOpen)==null||d.call(e),T())return;re(f,!0),c.shouldShowBackdrop||_(f,"transparent"),re([s],!0),ne(s,{y:s.clientHeight});const p=window.innerHeight,g=me(p,s.clientHeight,c.marginTop,c.defaultPosition),m=P(s).y;o.translateContainer({startY:m,endY:g,animationFrame:a,bottomSheetContainer:s,onEnd:e.afterOpen});const O=document.body.style.overflowY;r.originalDocumentOverflowY=O||"initial";const D=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=D||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",u.bottomSheetHandle.focus(),h.attacheOnOpenEventListeners()};function w(){var d;if(j())return;(d=e.beforeClose)==null||d.call(e);const p=P(s).y,g=s.clientHeight;o.translateContainer({startY:p,endY:g,animationFrame:a,bottomSheetContainer:s,onEnd:()=>{var m;(m=e.afterClose)==null||m.call(e),re([f,s],!1),h.clearOnOpenEventListeners()}}),i()}function x(){return o.isMounted}function T(){const d=P(s).y,p=window.innerHeight,g=s.clientHeight>=p?p:s.clientHeight;return d<=g}function j(){return!T()}function V(){const d=P(s).y,p=s.clientHeight,g=window.innerHeight;if(d<=5&&d>=-5)return I.CONTENT_HEIGHT;const m=p-d;if(m===g/2)return I.MIDDLE;const O=g-c.marginTop,D=10;return m<=O+D&&m>=O-D?I.TOP:I.CLOSED}function K(){return s.clientHeight}function G(d){if(!T())return;const p=P(s).y,g=s.clientHeight-p,m=window.innerHeight-d,O=Ie(g,m),D=q(g,m);o.translateContainer({startY:p,endY:p+(O.isUp?-D:D),animationFrame:a,bottomSheetContainer:s})}function U(d,{viewportHeight:p,visibleHeight:g}){let m=null;for(const O of d){const D=O*p,$=q(g,D);(m===null||$<m)&&(m=$)}return{minOffset:m}}function H(){const d=[...c.snapPoints].reverse(),p=P(s).y,g=s.clientHeight,m=g-p;if(!c.expandable&&m>=g)return;const O=window.innerHeight,D=ge("above",{visibleHeight:m,viewportHeight:O},d),{minOffset:$}=U(D,{visibleHeight:m,viewportHeight:O});if($===null&&m<O-c.marginTop){o.translateContainer({startY:p,endY:me(O,g,c.marginTop,"top"),animationFrame:a,bottomSheetContainer:s});return}A($)&&o.translateContainer({startY:p,endY:p-$,animationFrame:a,bottomSheetContainer:s})}function B(){const d=P(s).y,p=s.clientHeight-d;if(p<1)return;const g=window.innerHeight,m=ge("below",{visibleHeight:p,viewportHeight:g},c.snapPoints),{minOffset:O}=U(m,{visibleHeight:p,viewportHeight:g});A(O)&&o.translateContainer({startY:d,endY:d+O,animationFrame:a,bottomSheetContainer:s})}function b(d){const p=window.innerHeight;if(!Qe(d))return;const g=te(p*d,2);G(g)}return{props:c,elements:u,mount:E,unmount:v,open:y,close:w,getIsMounted:x,getIsOpen:T,getIsClosed:j,getPosition:V,getHeight:K,moveTo:G,snapTo:b}}function ue(){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:()=>I.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ut=ue(),dt=S.forwardRef(function(t,n){const{children:o,isOpen:r,setIsOpen:i,afterClose:a,mountingPointRef:l,...u}=t,h=S.useRef(ut),[c,f]=S.useState(h.current);S.useImperativeHandle(n,()=>c,[c]);const C=S.useCallback(()=>{i(!1),a==null||a()},[a]);S.useEffect(()=>{r?c.open():c.close()},[r]);const s=S.useRef(null);return S.useEffect(function(){var w;if(l&&!l.current)return;const v=Ae((w=t.mountingPointRef)==null?void 0:w.current)?t.mountingPointRef.current:window.document.body;if(!v||c.getIsMounted())return;const y=lt({content:"",...u,afterClose:C});return y.mount(v),s.current=y.elements.bottomSheetContentWrapper??null,h.current=y,f(y),()=>{c.unmount()}},[t.mountingPointRef,u,C]),S.useEffect(function(){Object.assign(h.current.props,{...u}),f(h.current)},[u]),S.useEffect(function(){return()=>{h.current.unmount()}},[]),s.current?xe.createPortal(t.children,s.current):null}),pt=ue();function ht(e={}){const t=S.useRef(pt),[n,o]=S.useState(!1),r=!n,[i,a]=S.useState(t.current);S.useEffect(()=>{a(t.current)},[t.current]);const{beforeOpen:l,afterOpen:u,beforeClose:h,afterClose:c,onDragStart:f,onDragMove:C,onDragEnd:s,...E}=e,v=()=>{l==null||l()},y=()=>{u==null||u(),o(!0)},w=()=>{h==null||h()},x=()=>{c==null||c(),o(!1)},T=()=>{f==null||f()},j=(b,d)=>{C==null||C(b,d)},V=()=>{s==null||s()},K=S.useMemo(()=>({ref:t,isOpen:n,setIsOpen:o,beforeOpen:v,afterOpen:y,beforeClose:w,afterClose:x,onDragStart:T,onDragMove:j,onDragEnd:V,...E}),[t.current,n,o,e]),G=S.useCallback(()=>{o(!0)},[o]),U=S.useCallback(()=>{o(!1)},[o]),H=S.useCallback((...b)=>{i.moveTo(...b)},[i]),B=S.useCallback((...b)=>{i.snapTo(...b)},[i]);return{props:K,instance:i,isOpen:n,isClosed:r,setIsOpen:o,open:G,close:U,moveTo:H,snapTo:B}}M.BottomSheet=dt,M.createPlaceholderBottomSheet=ue,M.useBottomSheet=ht,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
1
+ (function(M,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):(M=typeof globalThis<"u"?globalThis:M||self,S(M.BottomSheet={},M.React,M.ReactDOM))})(this,function(M,S,Be){"use strict";function Ae(e){return e!=null}(function(){try{if(typeof document<"u"){var e=document.createElement("style");e.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;flex-shrink:0;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(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();var De=Object.defineProperty,Me=(e,t,n)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,J=(e,t,n)=>Me(e,typeof t!="symbol"?t+"":t,n);function L(e){return typeof e=="string"}function Ye(e,t){return e.classList.contains(Q(t))}function _(e,t){e.classList.add(Q(t))}function oe(e,t){e.classList.remove(Q(t))}function X(e,t,n){L(n)&&(L(t)&&oe(e,t),_(e,n))}function Q(e){return L(e)?e.trim().replace(/\./g,""):""}function F(e){return e.map(t=>Q(t)).filter(Boolean).join(" ")}const de="open",pe="hidden";function re(e,t){const n=t;if(Array.isArray(e)){e.forEach(o=>{Z(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}Z(e,n),e.setAttribute("aria-modal",n?"true":"false")}function Z(e,t){t?(_(e,de),oe(e,pe)):(_(e,pe),oe(e,de))}function he(e){return e instanceof HTMLElement}function A(e){return typeof e=="number"&&!Number.isNaN(e)}function Pe(e){he(e)&&e.focus()}function Fe(e){if(!he(e)||e.offsetParent===null||"disabled"in e&&e.disabled)return!1;const t=e.getAttribute("tabindex"),n=A(t)?parseInt(t,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(e.tagName),r=e instanceof HTMLAnchorElement&&e.href!==""||e instanceof HTMLAreaElement&&e.href!=="";return o||r||n>-1}var T=(e=>(e.Backdrop="pbs-backdrop",e.Root="pbs-root",e.Container="pbs-container",e.GapFiller="pbs-gap-filler",e.Handle="pbs-handle",e.HandleBar="pbs-handle-bar",e.ContentWrapper="pbs-content-wrapper",e))(T||{}),ae=(e=>(e.Button="pbs-button-reset",e.Dialog="pbs-dialog-reset",e))(ae||{}),ee=(e=>(e.Hidden="hidden",e))(ee||{});function P(e,t,n){const o=document.createElement(e);return t.split(" ").forEach(r=>{_(o,r)}),L(n)&&o.setAttribute("data-testid",n),o}function me(e,t,n,o){switch(o){case"content-height":return t>=e?Se(e,t,n):0;case"middle":return-(e/2-t);case"top":return-(e-t)+n;default:return 0}}function fe(e,t){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function be(e,t){return t<e?-(e-t):t-e}function q(e,t){return e>t?e-t:t-e}function Ie(e,t){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function ge(e,t,n){const o=e==="above";return n.filter(r=>{const i=r*t.viewportHeight;return o?t.visibleHeight<i:t.visibleHeight>i})}function Se(e,t,n){return-(e-t)+n}function ve(e){return Number(e.replace("px",""))}function te(e,...t){return Number(e.toFixed(...t))}function ye(e){const t=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=t.exec(e))!==null;){const r=o[1],i=o[2].split(",").map(a=>a.trim());n.push({type:r,values:i})}return n}function Re(e){const t=e.style.transform,n=ye(t);return{transform:t,transformValues:n}}function Ce(e,t){return e.find(o=>o.type.startsWith(t))||null}const ie="translate";function Y(e){const t=e.style.transform,n=ye(t),o=Ce(n,ie);return Ee(o??{type:ie,values:[]})}function ne(e,{x:t,y:n}){const{transform:o,transformValues:r}=Re(e),i=Ce(r,ie);if(i){const a=Ee(i);e.style.transform=`translate(${t??a.x??0}px,${n??a.y??0}px)`;return}if(o){e.style.transform=`${o}, translate(${t??0}px,${n??0}px)`;return}e.style.transform=`translate(${t??0}px,${n??0}px)`}function Ee(e){if(e.type!=="translate")throw new Error(`Could not get coordinates from ${e.type}, since is not translate.`);const t=e.values[0],n=e.values[1];return{x:ve(t)??0,y:ve(n)??0}}function se(e){return e!=null}function we(e,{min:t,max:n}){return se(n)&&e>=n?n:se(t)&&e<=t?t:e}const We=(e,t,n)=>{t instanceof HTMLElement&&!Ye(t,T.Handle)&&n.scrollTop>=1||(e.isDragging=!0)},je=(e,t,n,o)=>r=>{o.startY=e.getCoordinates(r).y,o.containerStartTranslate=Y(t),n.onDragStart()},Ne=(e,t,n,o,r)=>i=>{Ge(i,e,n,o,r,t,n.marginTop)};function Ge(e,t,n,o,r,i,a){if(!o.isDragging||!A(o.startY))return;const l=t.getCoordinates(e).y,u=be(o.startY,l),h=window.innerHeight,s=i.clientHeight,f=s-(o.containerStartTranslate.y+u);if(f>=h)return;const C=fe(o.startY,l);if(C.isUp&&!n.expandable&&f>=s||n.preventClosing&&f<=s)return;r.start(()=>{ne(i,{y:o.containerStartTranslate.y+u})},0);const c=h-a,E=s-o.containerStartTranslate.y;if(C.isUp){const v=c-E,y=c-f,w=we(1-te(y/v,2),{min:0,max:1});n.onDragMove(C,w)}else if(C.isDown){const v=we(te(1-f/E,2),{min:0,max:1});n.onDragMove(C,v)}}const Ue=(e,t,n,o,r,i,a)=>l=>{if(!o.isDragging||(o.isDragging=!1,!A(o.startY)))return;n.onDragEnd();const u=o.startY,h=e.getCoordinates(l).y,s=Y(t).y,f=fe(u,h),C=window.innerHeight,c=t.clientHeight;if(f.isUp){if(!n.expandable)return;const E=[...n.snapPoints].sort((w,B)=>w-B),v=c+-s;for(const w of E){const B=w*window.innerHeight;if(v<=B){const k=q(v,B);a.translateContainer({startY:s,endY:s-k,animationFrame:r,bottomSheetContainer:t});return}}const y=Se(C,c,n.marginTop);a.translateContainer({startY:s,endY:y,animationFrame:r,bottomSheetContainer:t})}else if(f.isDown){const E=[...n.snapPoints].sort((v,y)=>y-v);for(const v of E){const y=v*window.innerHeight,w=c+-s;if(w>=y){const B=q(w,y);a.translateContainer({startY:s,endY:s+B,animationFrame:r,bottomSheetContainer:t});return}}if(n.preventClosing){const v=c+-s;if(v>=c){const y=q(v,c);a.translateContainer({startY:s,endY:s+y,animationFrame:r,bottomSheetContainer:t})}return}i()}};var I=(e=>(e[e.All=-1]="All",e[e.None=0]="None",e[e.Capture=1]="Capture",e[e.Target=2]="Target",e[e.Bubble=3]="Bubble",e))(I||{});function ke(e){switch(e){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const $e={eventPhase:I.All};class z{constructor(t){J(this,"currentTarget"),this.currentTarget=t}addEventListeners({onStart:t,onStartOptions:n=$e,onMove:o,onEnd:r}){this.addTouchEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}),this.addMouseEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r})}addTouchEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}){t&&this.currentTarget.addEventListener("touchstart",i=>{if(n.eventPhase===I.All){t(i);return}ke(i.eventPhase)===n.eventPhase&&t(i)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),r&&this.currentTarget.addEventListener("touchend",r)}addMouseEventListeners({onStart:t,onStartOptions:n,onMove:o,onEnd:r}){t&&this.currentTarget.addEventListener("mousedown",i=>{if(n.eventPhase===I.All){t(i);return}ke(i.eventPhase)===n.eventPhase&&t(i)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),r&&this.currentTarget.addEventListener("mouseup",i=>{r(i)})}removeEventListeners({onStart:t,onMove:n,onEnd:o}){t&&this.currentTarget.removeEventListener("touchstart",t),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),t&&this.currentTarget.removeEventListener("mousedown",t),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(t){if(t.type==="touchstart"||t.type==="mousedown"){if("touches"in t)return{x:t.touches[0].clientX,y:t.touches[0].clientY};if(t instanceof MouseEvent)return{x:t.clientX,y:t.clientY}}if(t.type==="touchend"||t.type==="mouseup"||t.type==="mousemove"||t.type==="touchmove"){if("touches"in t)return{x:t.changedTouches[0].clientX,y:t.changedTouches[0].clientY};if(t instanceof MouseEvent)return{x:t.clientX,y:t.clientY}}return{x:0,y:0}}}function Te(e){const t=e;return`${t} ${t} 0px 0px`}function _e(e,t){const n=Xe(e);qe(n),n.bottomSheetContainer.style.width=e.width;const o=document.createElement("div");o.innerHTML=e.content??"";const r=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${r}px`,n.bottomSheetContentWrapper.appendChild(o);const i=ze({bottomSheetElements:n,bottomSheetProps:e,options:t});return e.rootStyle&&Object.assign(n.bottomSheetRoot.style,e.rootStyle),e.backdropStyle&&Object.assign(n.bottomSheetBackdrop.style,e.backdropStyle),e.containerGapFillerStyle&&Object.assign(n.bottomSheetContainer.style,e.containerStyle),e.containerStyle&&Object.assign(n.bottomSheetContainerGapFiller.style,e.containerGapFillerStyle),e.handleStyle&&Object.assign(n.bottomSheetHandleBar.style,e.handleStyle),e.contentWrapperStyle&&Object.assign(n.bottomSheetContentWrapper.style,e.contentWrapperStyle),{elements:n,eventHandlers:i}}function Xe(e){const t=P("dialog",F([T.Root,ae.Dialog,e.rootClass]),T.Root);t.ariaLabel=e.ariaLabel;const n=P("section",F([T.Container,e.containerClass]),T.Container);e.containerBorderRadius&&(n.style.borderRadius=Te(e.containerBorderRadius));const o=P("div",T.GapFiller,T.GapFiller);e.containerBackgroundColor&&(n.style.backgroundColor=e.containerBackgroundColor,o.style.backgroundColor=e.containerBackgroundColor);const r=P("button",F([T.Handle,ae.Button,e.shouldShowHandle?null:ee.Hidden,e.handleClass]),T.Handle);r.setAttribute("type","button"),r.ariaLabel="bottom sheet close button";const i=P("span",F([T.HandleBar,e.shouldShowHandle?null:ee.Hidden]),T.HandleBar),a=P("article",F([T.ContentWrapper,e.contentWrapperClass]),T.ContentWrapper),l=P("div",F([T.Backdrop,e.backdropClass,ee.Hidden]),T.Backdrop);return e.backdropColor&&(l.style.backgroundColor=e.backdropColor),e.backDropTransition&&(l.style.transition=e.backDropTransition),{bottomSheetRoot:t,bottomSheetBackdrop:l,bottomSheetContainer:n,bottomSheetHandle:r,bottomSheetHandleBar:i,bottomSheetContentWrapper:a,bottomSheetContainerGapFiller:o}}function qe({bottomSheetRoot:e,bottomSheetContainer:t,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:r,bottomSheetContainerGapFiller:i}){e.appendChild(t),n.appendChild(o),t.appendChild(n),t.appendChild(r),t.appendChild(i)}function ze({bottomSheetElements:e,bottomSheetProps:t,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:r,bottomSheetHandle:i,bottomSheetContainerGapFiller:a,bottomSheetContentWrapper:l,bottomSheetBackdrop:u}=e,{animationFrame:h}=n,s=new z(i),f=new z(l),C=new z(a);let c=[];const E=new z(window),v=je(E,r,t,n.draggingState),y=Ne(E,r,t,n.draggingState,h),w=Ue(E,r,t,n.draggingState,h,n.onClose,n.bottomSheetState);function B(H){H.target instanceof Element&&!o.contains(H.target)&&n.onClose()}function k(H){We(n.draggingState,H.target,e.bottomSheetContentWrapper)}function N(H){const x=H??t;x.draggable&&x.backgroundDraggable&&(f.addEventListeners({onStart:k,onStartOptions:{eventPhase:I.Target}}),C.addEventListeners({onStart:k})),x.draggable&&E.addEventListeners({onStart:v,onMove:y,onEnd:w}),x.draggable&&window.document.addEventListener("keyup",b=>{b.key==="Escape"&&n.onClose()}),i.addEventListener("keyup",b=>{if(b.key==="ArrowUp"){n.moveUp();return}if(b.key==="ArrowDown"){n.moveDown();return}if(b.shiftKey&&b.key==="Tab"){const d=G(e.bottomSheetContentWrapper);Pe(d)}})}function V(H){const x=H??t;t.shouldCloseOnOutsideClick&&!t.preventClosing?u.addEventListener("click",B):u.style.pointerEvents="none",x.draggable&&(s.addEventListeners({onStart:k}),c.forEach(b=>{b.removeEventListeners({onStart:k})}),c=t.dragTriggers.reduce((b,d)=>{const p=o.querySelectorAll(d);if(!p.length)return b;const g=Array.from(p).map(m=>m instanceof HTMLElement?new z(m):null).filter(m=>!!m);return[...b,...g]},[]),c.forEach(b=>{b.addEventListeners({onStart:k,onStartOptions:{eventPhase:I.Target}})}))}function K(){u.removeEventListener("click",B)}function G(H){let x=[...Array.from(H.childNodes).reverse()];for(;x.length;){const b=x.shift();if(Fe(b))return b;b&&(x=[...x,...Array.from(b.childNodes).reverse()])}return null}function U(){s.removeEventListeners({onStart:k}),f.removeEventListeners({onStart:k}),C.removeEventListeners({onStart:k}),c.forEach(H=>{H.removeEventListeners({onStart:k})}),E.removeEventListeners({onStart:v,onMove:y,onEnd:w})}return{attachEventListeners:N,clearEventListeners:U,attacheOnOpenEventListeners:V,clearOnOpenEventListeners:K}}class Ve{constructor(){J(this,"animationId"),J(this,"isInProgress"),J(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(t,n,o=!1){this.isInProgress=!0;const r=i=>{this.startedAt||(this.startedAt=i);const a=i-this.startedAt,l=n===0?1:te(a/n,2),u=l>=1&&!o;t(l),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 Ke(e){const{startY:t,endY:n,bottomSheetContainer:o,animationFrame:r,onEnd:i,animationTimingFunction:a,animationDuration:l}=e,u=be(t,n);r.stop();let h=!1;r.start(s=>{ne(o,{y:t+u*a(s)}),!h&&s>=1&&(i==null||i(),h=!0)},l)}const ce=(e,t)=>n=>{Ke({...n,animationTimingFunction:e,animationDuration:t})},R={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Je(e){return!(!A(e)||e>1||e<0)}function Qe(e,t){const n={set(o,r,i,a){return t(r,i),Reflect.set(o,r,i,a)}};return new Proxy(e,n)}function Ze(...e){console.error(e)}const W={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function et(e){for(const t of Object.values(W))if(t===e)return!0;return!1}function He(e){return!!(e instanceof Object&&"p1x"in e&&"p1y"in e&&"p2x"in e&&"p2y"in e&&A(e.p1x)&&A(e.p1y)&&A(e.p2x)&&A(e.p2y))}function j(e,t,n,o){return function(l){return a(r(l))};function r(l){let u=0,h=1,s=l,f;if(l===0||l===1)return l;for(;u<h;){if(f=i(s),Math.abs(f-l)<.001)return s;l>f?u=s:h=s,s=(h+u)/2}return s}function i(l){return 3*e*l*Math.pow(1-l,2)+3*n*Math.pow(l,2)*(1-l)+Math.pow(l,3)}function a(l){return 3*t*l*Math.pow(1-l,2)+3*o*Math.pow(l,2)*(1-l)+Math.pow(l,3)}}const Oe=j(.25,.1,.25,1),tt=j(.42,0,1,1),Le=j(.42,0,.58,1),nt=j(.4,.1,.6,1),ot=j(.45,1.5,.55,1);function rt(e){switch(e){case W.EASE:return Oe;case W.EASE_IN:return tt;case W.EASE_OUT:return Le;case W.EASE_IN_OUT:return nt;case W.SPRING:return ot;default:return Oe}}function xe(e){return typeof e=="boolean"}const at={ariaLabel:"Bottom sheet",content:"",defaultPosition:R.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,preventClosing:!1,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBackgroundColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180,rootStyle:{},containerStyle:{},handleStyle:{},contentWrapperStyle:{},backdropStyle:{},containerGapFillerStyle:{}};function it(e){const t={...at},n=Object.entries(e).reduce((o,r)=>{const[i,a]=r;return se(a)&&(o[i]=a),o},{});return{...t,...n}}function le(e){if(He(e)){const{p1x:t,p1y:n,p2x:o,p2y:r}=e;return j(t,n,o,r)}return et(e)?rt(e):Le}function st(e,t,n,o){function r(i,a){switch(i){case"content":L(a)&&(e.bottomSheetContentWrapper.innerHTML=a);break;case"width":L(a)&&(e.bottomSheetContainer.style.width=a);break;case"shouldShowHandle":xe(a)||Z(e.bottomSheetHandle,!1);break;case"shouldShowBackdrop":xe(a)||Z(e.bottomSheetBackdrop,!1);break;case"containerBorderRadius":L(a)&&(e.bottomSheetContainer.style.borderRadius=Te(a));break;case"containerBackgroundColor":L(a)&&(e.bottomSheetContainer.style.backgroundColor=a,e.bottomSheetContainerGapFiller.style.backgroundColor=a);break;case"backdropColor":L(a)&&(e.bottomSheetBackdrop.style.backgroundColor=a);break;case"backDropTransition":L(a)&&(e.bottomSheetBackdrop.style.transition=a);break;case"rootClass":if(!L(a))return;X(e.bottomSheetRoot,n.rootClass,a);break;case"containerClass":if(!L(a))return;X(e.bottomSheetContainer,n.containerClass,a);break;case"handleClass":if(!L(a))return;X(e.bottomSheetHandle,n.handleClass,a);break;case"contentWrapperClass":if(!L(a))return;X(e.bottomSheetContentWrapper,n.contentWrapperClass,a);break;case"backdropClass":if(!L(a))return;X(e.bottomSheetBackdrop,n.backdropClass,a);break;case"expandable":o.clearEventListeners(),o.attachEventListeners(n);break;case"preventClosing":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggable":o.clearEventListeners(),o.attachEventListeners(n);break;case"dragTriggers":o.clearEventListeners(),o.attachEventListeners(n);break;case"draggingAnimationTimings":if(He(a)){const l=le(a),u=ce(l,n.draggingAnimationDuration);t.translateContainer=u}break;case"draggingAnimationDuration":if(A(a)){const l=le(n.draggingAnimationTimings),u=ce(l,a);t.translateContainer=u}break;case"rootStyle":n.rootStyle&&Object.assign(e.bottomSheetRoot.style,n.rootStyle);break;case"backdropStyle":n.backdropStyle&&Object.assign(e.bottomSheetBackdrop.style,n.backdropStyle);break;case"containerStyle":n.containerStyle&&Object.assign(e.bottomSheetContainer.style,n.containerStyle);break;case"containerGapFillerStyle":n.containerGapFillerStyle&&Object.assign(e.bottomSheetContainerGapFiller.style,n.containerGapFillerStyle);break;case"handleStyle":n.handleStyle&&Object.assign(e.bottomSheetHandleBar.style,n.handleStyle);break;case"contentWrapperStyle":n.contentWrapperStyle&&Object.assign(e.bottomSheetContentWrapper.style,n.contentWrapperStyle);break}}return r}function ct(e){const t=it(e),n=le(e.draggingAnimationTimings),o={isMounted:!1,translateContainer:ce(n,t.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function i(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const a=new Ve,l={animationFrame:a,onClose:w,bottomSheetState:o,draggingState:r,snapTo:b,moveUp:H,moveDown:x},{elements:u,eventHandlers:h}=_e(t,l),s=Qe(t,st(u,o,t,h)),{bottomSheetBackdrop:f,bottomSheetRoot:C,bottomSheetContainer:c}=u,E=d=>{const p=d??window.document.body;p.appendChild(C),p.appendChild(f);const g=window.innerHeight;ne(c,{y:g}),h.attachEventListeners(),o.isMounted=!0},v=()=>{h.clearEventListeners(),Object.values(u).forEach(d=>{d.remove()}),i(),o.isMounted=!1},y=()=>{var d;if(B()||Ze('Bottom Sheet is not mounted yet. call the "mount" method first.'),(d=e.beforeOpen)==null||d.call(e),k())return;re(f,!0),s.shouldShowBackdrop||_(f,"transparent"),re([c],!0),ne(c,{y:c.clientHeight});const p=window.innerHeight,g=me(p,c.clientHeight,s.marginTop,s.defaultPosition),m=Y(c).y;o.translateContainer({startY:m,endY:g,animationFrame:a,bottomSheetContainer:c,onEnd:e.afterOpen});const O=document.body.style.overflowY;r.originalDocumentOverflowY=O||"initial";const D=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=D||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",u.bottomSheetHandle.focus(),h.attacheOnOpenEventListeners()};function w(){var d;if(N())return;(d=e.beforeClose)==null||d.call(e);const p=Y(c).y,g=c.clientHeight;o.translateContainer({startY:p,endY:g,animationFrame:a,bottomSheetContainer:c,onEnd:()=>{var m;(m=e.afterClose)==null||m.call(e),re([f,c],!1),h.clearOnOpenEventListeners()}}),i()}function B(){return o.isMounted}function k(){const d=Y(c).y,p=window.innerHeight,g=c.clientHeight>=p?p:c.clientHeight;return d<=g}function N(){return!k()}function V(){const d=Y(c).y,p=c.clientHeight,g=window.innerHeight;if(d<=5&&d>=-5)return R.CONTENT_HEIGHT;const m=p-d;if(m===g/2)return R.MIDDLE;const O=g-s.marginTop,D=10;return m<=O+D&&m>=O-D?R.TOP:R.CLOSED}function K(){return c.clientHeight}function G(d){if(!k())return;const p=Y(c).y,g=c.clientHeight-p,m=window.innerHeight-d,O=Ie(g,m),D=q(g,m);o.translateContainer({startY:p,endY:p+(O.isUp?-D:D),animationFrame:a,bottomSheetContainer:c})}function U(d,{viewportHeight:p,visibleHeight:g}){let m=null;for(const O of d){const D=O*p,$=q(g,D);(m===null||$<m)&&(m=$)}return{minOffset:m}}function H(){const d=[...s.snapPoints].reverse(),p=Y(c).y,g=c.clientHeight,m=g-p;if(!s.expandable&&m>=g)return;const O=window.innerHeight,D=ge("above",{visibleHeight:m,viewportHeight:O},d),{minOffset:$}=U(D,{visibleHeight:m,viewportHeight:O});if($===null&&m<O-s.marginTop){o.translateContainer({startY:p,endY:me(O,g,s.marginTop,"top"),animationFrame:a,bottomSheetContainer:c});return}A($)&&o.translateContainer({startY:p,endY:p-$,animationFrame:a,bottomSheetContainer:c})}function x(){const d=Y(c).y,p=c.clientHeight-d;if(p<1)return;const g=window.innerHeight,m=ge("below",{visibleHeight:p,viewportHeight:g},s.snapPoints),{minOffset:O}=U(m,{visibleHeight:p,viewportHeight:g});A(O)&&o.translateContainer({startY:d,endY:d+O,animationFrame:a,bottomSheetContainer:c})}function b(d){const p=window.innerHeight;if(!Je(d))return;const g=te(p*d,2);G(g)}return{props:s,elements:u,mount:E,unmount:v,open:y,close:w,getIsMounted:B,getIsOpen:k,getIsClosed:N,getPosition:V,getHeight:K,moveTo:G,snapTo:b}}function ue(){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:()=>R.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const lt=ue(),ut=S.forwardRef(function(t,n){const{children:o,isOpen:r,setIsOpen:i,afterClose:a,mountingPointRef:l,...u}=t,h=S.useRef(lt),[s,f]=S.useState(h.current);S.useImperativeHandle(n,()=>s,[s]);const C=S.useCallback(()=>{i(!1),a==null||a()},[a]);S.useEffect(()=>{r?s.open():s.close()},[r]);const c=S.useRef(null);return S.useEffect(function(){var w;if(l&&!l.current)return;const v=Ae((w=t.mountingPointRef)==null?void 0:w.current)?t.mountingPointRef.current:window.document.body;if(!v||s.getIsMounted())return;const y=ct({content:"",...u,afterClose:C});return y.mount(v),c.current=y.elements.bottomSheetContentWrapper??null,h.current=y,f(y),()=>{s.unmount()}},[t.mountingPointRef,u,C]),S.useEffect(function(){Object.assign(h.current.props,{...u}),f(h.current)},[u]),S.useEffect(function(){return()=>{h.current.unmount()}},[]),c.current?Be.createPortal(t.children,c.current):null}),dt=ue();function pt(e={}){const t=S.useRef(dt),[n,o]=S.useState(!1),r=!n,[i,a]=S.useState(t.current);S.useEffect(()=>{a(t.current)},[t.current]);const{beforeOpen:l,afterOpen:u,beforeClose:h,afterClose:s,onDragStart:f,onDragMove:C,onDragEnd:c,...E}=e,v=()=>{l==null||l()},y=()=>{u==null||u(),o(!0)},w=()=>{h==null||h()},B=()=>{s==null||s(),o(!1)},k=()=>{f==null||f()},N=(b,d)=>{C==null||C(b,d)},V=()=>{c==null||c()},K=S.useMemo(()=>({ref:t,isOpen:n,setIsOpen:o,beforeOpen:v,afterOpen:y,beforeClose:w,afterClose:B,onDragStart:k,onDragMove:N,onDragEnd:V,...E}),[t.current,n,o,e]),G=S.useCallback(()=>{o(!0)},[o]),U=S.useCallback(()=>{o(!1)},[o]),H=S.useCallback((...b)=>{i.moveTo(...b)},[i]),x=S.useCallback((...b)=>{i.snapTo(...b)},[i]);return{props:K,instance:i,isOpen:n,isClosed:r,setIsOpen:o,open:G,close:U,moveTo:H,snapTo:x}}M.BottomSheet=ut,M.createPlaceholderBottomSheet=ue,M.useBottomSheet=pt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plainsheet/react",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
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.10",
34
+ "@plainsheet/core": "0.7.12",
35
35
  "@plainsheet/utility": "0.0.3"
36
36
  },
37
37
  "devDependencies": {
@@ -49,7 +49,7 @@
49
49
  "typescript-eslint": "^8.0.0",
50
50
  "vite": "^5.4.0",
51
51
  "vite-plugin-dts": "^3.8.1",
52
- "vitest": "^1.6.0"
52
+ "vitest": "^1.6.1"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "react": ">=17.0.0 <20.0.0",