@plainsheet/react 0.4.8 → 0.4.9
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,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],g):(M=typeof globalThis<"u"?globalThis:M||self,g(M.BottomSheet={},M.React,M.ReactDOM))})(this,function(M,g,At){"use strict";function Bt(t){return t!=null}(function(){try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode('.pbs-root{position:fixed;left:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;height:fit-content;max-height:100vh;z-index:2}.pbs-dialog-reset{background-color:transparent;color:inherit;border:none;outline:none;padding:0;margin:0}.pbs-backdrop{position:fixed;top:0;left:0;width:100%;height:100%;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{visibility:hidden}.pbs-backdrop.open{background-color:#454545b3}.pbs-backdrop.transparent{background-color:transparent}.pbs-container{--pbs-container-background-color: rgb(240, 240, 240);background-color:var(--pbs-container-background-color);position:relative;display:none;flex-direction:column;align-items:center;justify-content:flex-start;width:92%;height:fit-content;max-height:100vh;border-radius:10px 10px 0 0}.pbs-container.open{display:flex}.pbs-container .pbs-gap-filler{position:absolute;bottom:calc(-100vh + .5px);left:0;background-color:var(--pbs-container-background-color);content:"";width:100%;height:100vh}.pbs-handle{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;cursor:pointer}.pbs-handle.hidden{display:none}.pbs-button-reset{background-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;border:none}button:focus.pbs-button-reset{outline:none}.pbs-handle-bar{background-color:#a8a8a8;position:relative;width:12%;height:7px;border-radius:12px}.pbs-handle-bar.hidden{display:none}.pbs-content-wrapper{position:relative;width:100%;height:fit-content;max-height:100%;overflow-y:scroll}.pbs-content-wrapper::-webkit-scrollbar{display:none}.example{-ms-overflow-style:none;scrollbar-width:none}')),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var Dt=Object.defineProperty,Mt=(t,e,n)=>e in t?Dt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J=(t,e,n)=>Mt(t,typeof e!="symbol"?e+"":e,n);function x(t){return typeof t=="string"}function Pt(t,e){return t.classList.contains(Q(e))}function _(t,e){t.classList.add(Q(e))}function ot(t,e){t.classList.remove(Q(e))}function X(t,e,n){x(n)&&(x(e)&&ot(t,e),_(t,n))}function Q(t){return x(t)?t.trim().replace(/\./g,""):""}function R(t){return t.map(e=>Q(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",pt="hidden";function rt(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?(_(t,dt),ot(t,pt)):(_(t,pt),ot(t,dt))}function ht(t){return t instanceof HTMLElement}function B(t){return typeof t=="number"&&!Number.isNaN(t)}function Rt(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=B(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),r=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||r||n>-1}var k=(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))(k||{}),it=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(it||{}),tt=(t=>(t.Hidden="hidden",t))(tt||{});function Y(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(r=>{_(o,r)}),x(n)&&o.setAttribute("data-testid",n),o}Yt([k.Root,k.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 bt(t,e){return e<t?-(t-e):e-t}function q(t,e){return t>e?t-e:e-t}function Wt(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(r=>{const a=r*e.viewportHeight;return o?e.visibleHeight<a:e.visibleHeight>a})}function vt(t,e,n){return-(t-e)+n}function St(t){return Number(t.replace("px",""))}function et(t,...e){return Number(t.toFixed(...e))}function yt(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const r=o[1],a=o[2].split(",").map(i=>i.trim());n.push({type:r,values:a})}return n}function Nt(t){const e=t.style.transform,n=yt(e);return{transform:e,transformValues:n}}function Ct(t,e){return t.find(o=>o.type.startsWith(e))||null}const at="translate";function P(t){const e=t.style.transform,n=yt(e),o=Ct(n,at);return Et(o??{type:at,values:[]})}function nt(t,{x:e,y:n}){const{transform:o,transformValues:r}=Nt(t),a=Ct(r,at);if(a){const i=Et(a);t.style.transform=`translate(${e??i.x??0}px,${n??i.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${e??0}px,${n??0}px)`;return}t.style.transform=`translate(${e??0}px,${n??0}px)`}function 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 Ft=(t,e,n)=>{e instanceof HTMLElement&&!Pt(e,k.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},jt=(t,e,n,o)=>r=>{o.startY=t.getCoordinates(r).y,o.containerStartTranslate=P(e),n.onDragStart()},Ut=(t,e,n,o,r)=>a=>{$t(a,t,n,o,r,e,n.marginTop)};function $t(t,e,n,o,r,a,i){if(!o.isDragging||!B(o.startY))return;const c=e.getCoordinates(t).y,u=bt(o.startY,c),h=window.innerHeight,s=a.clientHeight,m=s-(o.containerStartTranslate.y+u);if(m>=h)return;const E=ft(o.startY,c);if(E.isUp&&!n.expandable&&m>=s||n.preventClosing&&m<=s)return;r.start(()=>{nt(a,{y:o.containerStartTranslate.y+u})},0);const l=h-i,w=s-o.containerStartTranslate.y;if(E.isUp){const f=l-w,S=l-m,T=wt(1-et(S/f,2),{min:0,max:1});n.onDragMove(E,T)}else if(E.isDown){const f=wt(et(1-m/w,2),{min:0,max:1});n.onDragMove(E,f)}}const Gt=(t,e,n,o,r,a,i)=>c=>{if(!o.isDragging||(o.isDragging=!1,!B(o.startY)))return;n.onDragEnd();const u=o.startY,h=t.getCoordinates(c).y,s=P(e).y,m=ft(u,h),E=window.innerHeight,l=e.clientHeight;if(m.isUp){const w=[...n.snapPoints].sort((T,A)=>T-A),f=l+-s;if(!n.expandable&&f>=l)return;for(const T of w){const A=T*window.innerHeight;if(f<=A){const H=q(f,A);i.translateContainer({startY:s,endY:s-H,animationFrame:r,bottomSheetContainer:e});return}}const S=vt(E,l,n.marginTop);i.translateContainer({startY:s,endY:S,animationFrame:r,bottomSheetContainer:e})}else if(m.isDown){const w=[...n.snapPoints].sort((f,S)=>S-f);for(const f of w){const S=f*window.innerHeight,T=l+-s;if(T>=S){const A=q(T,S);i.translateContainer({startY:s,endY:s+A,animationFrame:r,bottomSheetContainer:e});return}}if(n.preventClosing){const f=l+-s;if(f>=l){const S=q(f,l);i.translateContainer({startY:s,endY:s+S,animationFrame:r,bottomSheetContainer:e})}return}a()}};var I=(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))(I||{});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:I.All};class z{constructor(e){J(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=_t,onMove:o,onEnd:r}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("touchstart",a=>{if(n.eventPhase===I.All){e(a);return}Tt(a.eventPhase)===n.eventPhase&&e(a)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),r&&this.currentTarget.addEventListener("touchend",r)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:r}){e&&this.currentTarget.addEventListener("mousedown",a=>{if(n.eventPhase===I.All){e(a);return}Tt(a.eventPhase)===n.eventPhase&&e(a)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),r&&this.currentTarget.addEventListener("mouseup",a=>{r(a)})}removeEventListeners({onStart:e,onMove:n,onEnd:o}){e&&this.currentTarget.removeEventListener("touchstart",e),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),e&&this.currentTarget.removeEventListener("mousedown",e),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(e){if(e.type==="touchstart"||e.type==="mousedown"){if("touches"in e)return{x:e.touches[0].clientX,y:e.touches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}if(e.type==="touchend"||e.type==="mouseup"||e.type==="mousemove"||e.type==="touchmove"){if("touches"in e)return{x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}return{x:0,y:0}}}function kt(t){const e=t;return`${e} ${e} 0px 0px`}function 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 r=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${r}px`,n.bottomSheetContentWrapper.appendChild(o);const a=Vt({bottomSheetElements:n,bottomSheetProps:t,options:e});return t.rootStyle&&Object.assign(n.bottomSheetRoot.style,t.rootStyle),t.backdropStyle&&Object.assign(n.bottomSheetBackdrop.style,t.backdropStyle),t.containerStyle&&Object.assign(n.bottomSheetContainer.style,t.containerStyle),t.handleStyle&&Object.assign(n.bottomSheetHandleBar.style,t.handleStyle),t.contentWrapperStyle&&Object.assign(n.bottomSheetContentWrapper.style,t.contentWrapperStyle),{elements:n,eventHandlers:a}}function qt(t){const e=Y("dialog",R([k.Root,it.Dialog,t.rootClass]),k.Root);e.ariaLabel=t.ariaLabel;const n=Y("section",R([k.Container,t.containerClass]),k.Container);t.containerBorderRadius&&(n.style.borderRadius=kt(t.containerBorderRadius));const o=Y("div",k.GapFiller,k.GapFiller),r=Y("button",R([k.Handle,it.Button,t.shouldShowHandle?null:tt.Hidden,t.handleClass]),k.Handle);r.setAttribute("type","button"),r.ariaLabel="bottom sheet close button";const a=Y("span",R([k.HandleBar,t.shouldShowHandle?null:tt.Hidden]),k.HandleBar),i=Y("article",R([k.ContentWrapper,t.contentWrapperClass]),k.ContentWrapper),c=Y("div",R([k.Backdrop,t.backdropClass,tt.Hidden]),k.Backdrop);return t.backdropColor&&(c.style.backgroundColor=t.backdropColor),t.backDropTransition&&(c.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:c,bottomSheetContainer:n,bottomSheetHandle:r,bottomSheetHandleBar:a,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:o}}function zt({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:r,bottomSheetContainerGapFiller:a}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(r),e.appendChild(a)}function Vt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:r,bottomSheetHandle:a,bottomSheetContainerGapFiller:i,bottomSheetContentWrapper:c,bottomSheetBackdrop:u}=t,{animationFrame:h}=n,s=new z(a),m=new z(c),E=new z(i),l=e.dragTriggers.reduce((O,C)=>{const y=o.querySelectorAll(C);if(!y.length)return O;const p=Array.from(y).map(d=>d instanceof HTMLElement?new z(d):null).filter(d=>!!d);return[...O,...p]},[]),w=new z(window),f=jt(w,r,e,n.draggingState),S=Ut(w,r,e,n.draggingState,h),T=Gt(w,r,e,n.draggingState,h,n.onClose,n.bottomSheetState);function A(O){O.target instanceof Element&&!o.contains(O.target)&&n.onClose()}function H(O){Ft(n.draggingState,O.target,t.bottomSheetContentWrapper)}function j(O){const C=O??e;C.draggable&&(s.addEventListeners({onStart:H}),l.forEach(y=>{y.addEventListeners({onStart:H,onStartOptions:{eventPhase:I.Target}})})),C.draggable&&C.backgroundDraggable&&(m.addEventListeners({onStart:H,onStartOptions:{eventPhase:I.Target}}),E.addEventListeners({onStart:H})),C.draggable&&w.addEventListeners({onStart:f,onMove:S,onEnd:T}),C.draggable&&window.document.addEventListener("keyup",y=>{y.key==="Escape"&&n.onClose()}),a.addEventListener("keyup",y=>{if(y.key==="ArrowUp"){n.moveUp();return}if(y.key==="ArrowDown"){n.moveDown();return}if(y.shiftKey&&y.key==="Tab"){const p=U(t.bottomSheetContentWrapper);Rt(p)}})}function V(){e.shouldCloseOnOutsideClick?u.addEventListener("click",A):u.style.pointerEvents="none"}function K(){u.removeEventListener("click",A)}function U(O){let C=[...Array.from(O.childNodes).reverse()];for(;C.length;){const y=C.shift();if(It(y))return y;y&&(C=[...C,...Array.from(y.childNodes).reverse()])}return null}function $(){s.removeEventListeners({onStart:H}),m.removeEventListeners({onStart:H}),E.removeEventListeners({onStart:H}),l.forEach(O=>{O.removeEventListeners({onStart:H})}),w.removeEventListeners({onStart:f,onMove:S,onEnd:T})}return{attachEventListeners:j,clearEventListeners:$,attacheOnOpenEventListeners:V,clearOnOpenEventListeners:K}}class Kt{constructor(){J(this,"animationId"),J(this,"isInProgress"),J(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const r=a=>{this.startedAt||(this.startedAt=a);const i=a-this.startedAt,c=n===0?1:et(i/n,2),u=c>=1&&!o;e(c),u?this.stop():this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}stop(){this.isInProgress=!1,this.startedAt=null,B(this.animationId)&&cancelAnimationFrame(this.animationId)}}function Jt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:r,onEnd:a,animationTimingFunction:i,animationDuration:c}=t,u=bt(e,n);r.stop();let h=!1;r.start(s=>{nt(o,{y:e+u*i(s)}),!h&&s>=1&&(a==null||a(),h=!0)},c)}const ct=(t,e)=>n=>{Jt({...n,animationTimingFunction:t,animationDuration:e})},W={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Qt(t){return!(!B(t)||t>1||t<0)}function Zt(t,e){const n={set(o,r,a,i){return e(r,a),Reflect.set(o,r,a,i)}};return new Proxy(t,n)}function te(...t){console.error(t)}const N={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function ee(t){for(const e of Object.values(N))if(e===t)return!0;return!1}function Ht(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&B(t.p1x)&&B(t.p1y)&&B(t.p2x)&&B(t.p2y))}function F(t,e,n,o){return function(c){return i(r(c))};function r(c){let u=0,h=1,s=c,m;if(c===0||c===1)return c;for(;u<h;){if(m=a(s),Math.abs(m-c)<.001)return s;c>m?u=s:h=s,s=(h+u)/2}return s}function a(c){return 3*t*c*Math.pow(1-c,2)+3*n*Math.pow(c,2)*(1-c)+Math.pow(c,3)}function i(c){return 3*e*c*Math.pow(1-c,2)+3*o*Math.pow(c,2)*(1-c)+Math.pow(c,3)}}const Ot=F(.25,.1,.25,1),ne=F(.42,0,1,1),Lt=F(.42,0,.58,1),oe=F(.4,.1,.6,1),re=F(.45,1.5,.55,1);function ie(t){switch(t){case N.EASE:return Ot;case N.EASE_IN:return ne;case N.EASE_OUT:return Lt;case N.EASE_IN_OUT:return oe;case N.SPRING:return re;default:return Ot}}function xt(t){return typeof t=="boolean"}const ae={ariaLabel:"Bottom sheet",content:"",defaultPosition:W.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,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180,rootStyle:{},containerStyle:{},handleStyle:{},contentWrapperStyle:{},backdropStyle:{}};function se(t){const e={...ae},n=Object.entries(t).reduce((o,r)=>{const[a,i]=r;return st(i)&&(o[a]=i),o},{});return{...e,...n}}function lt(t){if(Ht(t)){const{p1x:e,p1y:n,p2x:o,p2y:r}=t;return F(e,n,o,r)}return ee(t)?ie(t):Lt}function ce(t,e,n,o){function r(a,i){switch(a){case"content":x(i)&&(t.bottomSheetContentWrapper.innerHTML=i);break;case"width":x(i)&&(t.bottomSheetContainer.style.width=i);break;case"shouldShowHandle":xt(i)||Z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":xt(i)||Z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":x(i)&&(t.bottomSheetContainer.style.borderRadius=kt(i));break;case"backdropColor":x(i)&&(t.bottomSheetBackdrop.style.backgroundColor=i);break;case"backDropTransition":x(i)&&(t.bottomSheetBackdrop.style.transition=i);break;case"rootClass":if(!x(i))return;X(t.bottomSheetRoot,n.rootClass,i);break;case"containerClass":if(!x(i))return;X(t.bottomSheetContainer,n.containerClass,i);break;case"handleClass":if(!x(i))return;X(t.bottomSheetHandle,n.handleClass,i);break;case"contentWrapperClass":if(!x(i))return;X(t.bottomSheetContentWrapper,n.contentWrapperClass,i);break;case"backdropClass":if(!x(i))return;X(t.bottomSheetBackdrop,n.backdropClass,i);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"draggingAnimationTimings":if(Ht(i)){const c=lt(i),u=ct(c,n.draggingAnimationDuration);e.translateContainer=u}break;case"draggingAnimationDuration":if(B(i)){const c=lt(n.draggingAnimationTimings),u=ct(c,i);e.translateContainer=u}break;case"rootStyle":n.rootStyle&&Object.assign(t.bottomSheetRoot.style,n.rootStyle);break;case"backdropStyle":n.backdropStyle&&Object.assign(t.bottomSheetBackdrop.style,n.backdropStyle);break;case"containerStyle":n.containerStyle&&Object.assign(t.bottomSheetContainer.style,n.containerStyle);break;case"handleStyle":n.handleStyle&&Object.assign(t.bottomSheetHandleBar.style,n.handleStyle);break;case"contentWrapperStyle":n.contentWrapperStyle&&Object.assign(t.bottomSheetContentWrapper.style,n.contentWrapperStyle);break}}return r}function le(t){const e=se(t),n=lt(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:ct(n,e.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function a(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const i=new Kt,c={animationFrame:i,onClose:T,bottomSheetState:o,draggingState:r,snapTo:y,moveUp:O,moveDown:C},{elements:u,eventHandlers:h}=Xt(e,c),s=Zt(e,ce(u,o,e,h)),{bottomSheetBackdrop:m,bottomSheetRoot:E,bottomSheetContainer:l}=u,w=p=>{const d=p??window.document.body;d.appendChild(E),d.appendChild(m);const b=window.innerHeight;nt(l,{y:b}),h.attachEventListeners(),o.isMounted=!0},f=()=>{h.clearEventListeners(),Object.values(u).forEach(p=>{p.remove()}),a(),o.isMounted=!1},S=()=>{var p;if(A()||te('Bottom Sheet is not mounted yet. call the "mount" method first.'),(p=t.beforeOpen)==null||p.call(t),H())return;rt(m,!0),s.shouldShowBackdrop||_(m,"transparent"),rt([l],!0),nt(l,{y:l.clientHeight});const d=window.innerHeight,b=mt(d,l.clientHeight,s.marginTop,s.defaultPosition),v=P(l).y;o.translateContainer({startY:v,endY:b,animationFrame:i,bottomSheetContainer:l,onEnd:t.afterOpen});const L=document.body.style.overflowY;r.originalDocumentOverflowY=L||"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 T(){var p;if(j())return;(p=t.beforeClose)==null||p.call(t);const d=P(l).y,b=l.clientHeight;o.translateContainer({startY:d,endY:b,animationFrame:i,bottomSheetContainer:l,onEnd:()=>{var v;(v=t.afterClose)==null||v.call(t),rt([m,l],!1),h.clearOnOpenEventListeners()}}),a()}function A(){return o.isMounted}function H(){const p=P(l).y,d=window.innerHeight,b=l.clientHeight>=d?d:l.clientHeight;return p<=b}function j(){return!H()}function V(){const p=P(l).y,d=l.clientHeight,b=window.innerHeight;if(p<=5&&p>=-5)return W.CONTENT_HEIGHT;const v=d-p;if(v===b/2)return W.MIDDLE;const L=b-s.marginTop,D=10;return v<=L+D&&v>=L-D?W.TOP:W.CLOSED}function K(){return l.clientHeight}function U(p){if(!H())return;const d=P(l).y,b=l.clientHeight-d,v=window.innerHeight-p,L=Wt(b,v),D=q(b,v);o.translateContainer({startY:d,endY:d+(L.isUp?-D:D),animationFrame:i,bottomSheetContainer:l})}function $(p,{viewportHeight:d,visibleHeight:b}){let v=null;for(const L of p){const D=L*d,G=q(b,D);(v===null||G<v)&&(v=G)}return{minOffset:v}}function O(){const p=[...s.snapPoints].reverse(),d=P(l).y,b=l.clientHeight,v=b-d;if(!s.expandable&&v>=b)return;const L=window.innerHeight,D=gt("above",{visibleHeight:v,viewportHeight:L},p),{minOffset:G}=$(D,{visibleHeight:v,viewportHeight:L});if(G===null&&v<L-s.marginTop){o.translateContainer({startY:d,endY:mt(L,b,s.marginTop,"top"),animationFrame:i,bottomSheetContainer:l});return}B(G)&&o.translateContainer({startY:d,endY:d-G,animationFrame:i,bottomSheetContainer:l})}function C(){const p=P(l).y,d=l.clientHeight-p;if(d<1)return;const b=window.innerHeight,v=gt("below",{visibleHeight:d,viewportHeight:b},s.snapPoints),{minOffset:L}=$(v,{visibleHeight:d,viewportHeight:b});B(L)&&o.translateContainer({startY:p,endY:p+L,animationFrame:i,bottomSheetContainer:l})}function y(p){const d=window.innerHeight;if(!Qt(p))return;const b=et(d*p,2);U(b)}return{props:s,elements:u,mount:w,unmount:f,open:S,close:T,getIsMounted:A,getIsOpen:H,getIsClosed:j,getPosition:V,getHeight:K,moveTo:U,snapTo:y}}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:()=>W.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const ue=ut(),de=g.forwardRef(function(e,n){const{children:o,isOpen:r,setIsOpen:a,afterClose:i,mountingPointRef:c,...u}=e,h=g.useRef(ue),[s,m]=g.useState(h.current);g.useImperativeHandle(n,()=>s,[s]);const E=g.useCallback(()=>{a(!1),i==null||i()},[i]);g.useEffect(()=>{r?s.open():s.close()},[r]);const l=g.useRef(null);return g.useEffect(function(){var T;if(c&&!c.current)return;const f=Bt((T=e.mountingPointRef)==null?void 0:T.current)?e.mountingPointRef.current:window.document.body;if(!f||s.getIsMounted())return;const S=le({content:"",...u,afterClose:E});return S.mount(f),l.current=S.elements.bottomSheetContentWrapper??null,h.current=S,m(S),()=>{s.unmount()}},[e.mountingPointRef,u,E]),g.useEffect(function(){Object.assign(h.current.props,{...u}),m(h.current)},[u]),g.useEffect(function(){return()=>{h.current.unmount()}},[]),l.current?At.createPortal(e.children,l.current):null}),pe=ut();function he(t={}){const e=g.useRef(pe),[n,o]=g.useState(!1),[r,a]=g.useState(e.current);g.useEffect(()=>{a(e.current)},[e.current]);const{beforeOpen:i,afterOpen:c,beforeClose:u,afterClose:h,onDragStart:s,onDragMove:m,onDragEnd:E,...l}=t,w=()=>{i==null||i()},f=()=>{c==null||c(),o(!0)},S=()=>{u==null||u()},T=()=>{h==null||h(),o(!1)},A=()=>{s==null||s()},H=(C,y)=>{m==null||m(C,y)},j=()=>{E==null||E()},V=g.useMemo(()=>({ref:e,isOpen:n,setIsOpen:o,beforeOpen:w,afterOpen:f,beforeClose:S,afterClose:T,onDragStart:A,onDragMove:H,onDragEnd:j,...l}),[e.current,n,o,t]),K=g.useCallback(()=>{o(!0)},[o]),U=g.useCallback(()=>{o(!0)},[o]),$=g.useCallback((...C)=>{r.moveTo(...C)},[r]),O=g.useCallback((...C)=>{r.snapTo(...C)},[r]);return{props:V,instance:r,isOpen:n,setIsOpen:o,open:K,close:U,moveTo:$,snapTo:O}}M.BottomSheet=de,M.createPlaceholderBottomSheet=ut,M.useBottomSheet=he,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(M,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","react-dom"],g):(M=typeof globalThis<"u"?globalThis:M||self,g(M.BottomSheet={},M.React,M.ReactDOM))})(this,function(M,g,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 B(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){B(n)&&(B(t)&&oe(e,t),_(e,n))}function Q(e){return B(e)?e.trim().replace(/\./g,""):""}function F(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 Fe(e){he(e)&&e.focus()}function Re(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 Y(e,t,n){const o=document.createElement(e);return t.split(" ").forEach(r=>{_(o,r)}),B(n)&&o.setAttribute("data-testid",n),o}Ye([T.Root,T.ContentWrapper]);function fe(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 me(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 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: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 Ne=(e,t,n)=>{t instanceof HTMLElement&&!Pe(t,T.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 c=t.getCoordinates(e).y,u=be(o.startY,c),h=window.innerHeight,s=i.clientHeight,f=s-(o.containerStartTranslate.y+u);if(f>=h)return;const E=me(o.startY,c);if(E.isUp&&!n.expandable&&f>=s||n.preventClosing&&f<=s)return;r.start(()=>{ne(i,{y:o.containerStartTranslate.y+u})},0);const l=h-a,w=s-o.containerStartTranslate.y;if(E.isUp){const m=l-w,v=l-f,k=we(1-te(v/m,2),{min:0,max:1});n.onDragMove(E,k)}else if(E.isDown){const m=we(te(1-f/w,2),{min:0,max:1});n.onDragMove(E,m)}}const $e=(e,t,n,o,r,i,a)=>c=>{if(!o.isDragging||(o.isDragging=!1,!A(o.startY)))return;n.onDragEnd();const u=o.startY,h=e.getCoordinates(c).y,s=P(t).y,f=me(u,h),E=window.innerHeight,l=t.clientHeight;if(f.isUp){const w=[...n.snapPoints].sort((k,x)=>k-x),m=l+-s;if(!n.expandable&&m>=l)return;for(const k of w){const x=k*window.innerHeight;if(m<=x){const H=q(m,x);a.translateContainer({startY:s,endY:s-H,animationFrame:r,bottomSheetContainer:t});return}}const v=Se(E,l,n.marginTop);a.translateContainer({startY:s,endY:v,animationFrame:r,bottomSheetContainer:t})}else if(f.isDown){const w=[...n.snapPoints].sort((m,v)=>v-m);for(const m of w){const v=m*window.innerHeight,k=l+-s;if(k>=v){const x=q(k,v);a.translateContainer({startY:s,endY:s+x,animationFrame:r,bottomSheetContainer:t});return}}if(n.preventClosing){const m=l+-s;if(m>=l){const v=q(m,l);a.translateContainer({startY:s,endY:s+v,animationFrame:r,bottomSheetContainer:t})}return}i()}};var R=(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))(R||{});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:R.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===R.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===R.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",F([T.Root,ae.Dialog,e.rootClass]),T.Root);t.ariaLabel=e.ariaLabel;const n=Y("section",F([T.Container,e.containerClass]),T.Container);e.containerBorderRadius&&(n.style.borderRadius=Te(e.containerBorderRadius));const o=Y("div",T.GapFiller,T.GapFiller);e.containerBackgroundColor&&(n.style.backgroundColor=e.containerBackgroundColor,o.style.backgroundColor=e.containerBackgroundColor);const r=Y("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=Y("span",F([T.HandleBar,e.shouldShowHandle?null:ee.Hidden]),T.HandleBar),a=Y("article",F([T.ContentWrapper,e.contentWrapperClass]),T.ContentWrapper),c=Y("div",F([T.Backdrop,e.backdropClass,ee.Hidden]),T.Backdrop);return e.backdropColor&&(c.style.backgroundColor=e.backdropColor),e.backDropTransition&&(c.style.transition=e.backDropTransition),{bottomSheetRoot:t,bottomSheetBackdrop:c,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:c,bottomSheetBackdrop:u}=e,{animationFrame:h}=n,s=new z(i),f=new z(c),E=new z(a),l=t.dragTriggers.reduce((O,C)=>{const y=o.querySelectorAll(C);if(!y.length)return O;const p=Array.from(y).map(d=>d instanceof HTMLElement?new z(d):null).filter(d=>!!d);return[...O,...p]},[]),w=new z(window),m=je(w,r,t,n.draggingState),v=Ge(w,r,t,n.draggingState,h),k=$e(w,r,t,n.draggingState,h,n.onClose,n.bottomSheetState);function x(O){O.target instanceof Element&&!o.contains(O.target)&&n.onClose()}function H(O){Ne(n.draggingState,O.target,e.bottomSheetContentWrapper)}function j(O){const C=O??t;C.draggable&&(s.addEventListeners({onStart:H}),l.forEach(y=>{y.addEventListeners({onStart:H,onStartOptions:{eventPhase:R.Target}})})),C.draggable&&C.backgroundDraggable&&(f.addEventListeners({onStart:H,onStartOptions:{eventPhase:R.Target}}),E.addEventListeners({onStart:H})),C.draggable&&w.addEventListeners({onStart:m,onMove:v,onEnd:k}),C.draggable&&window.document.addEventListener("keyup",y=>{y.key==="Escape"&&n.onClose()}),i.addEventListener("keyup",y=>{if(y.key==="ArrowUp"){n.moveUp();return}if(y.key==="ArrowDown"){n.moveDown();return}if(y.shiftKey&&y.key==="Tab"){const p=G(e.bottomSheetContentWrapper);Fe(p)}})}function V(){t.shouldCloseOnOutsideClick?u.addEventListener("click",x):u.style.pointerEvents="none"}function K(){u.removeEventListener("click",x)}function G(O){let C=[...Array.from(O.childNodes).reverse()];for(;C.length;){const y=C.shift();if(Re(y))return y;y&&(C=[...C,...Array.from(y.childNodes).reverse()])}return null}function U(){s.removeEventListeners({onStart:H}),f.removeEventListeners({onStart:H}),E.removeEventListeners({onStart:H}),l.forEach(O=>{O.removeEventListeners({onStart:H})}),w.removeEventListeners({onStart:m,onMove:v,onEnd:k})}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,c=n===0?1:te(a/n,2),u=c>=1&&!o;t(c),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:c}=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)},c)}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(c){return a(r(c))};function r(c){let u=0,h=1,s=c,f;if(c===0||c===1)return c;for(;u<h;){if(f=i(s),Math.abs(f-c)<.001)return s;c>f?u=s:h=s,s=(h+u)/2}return s}function i(c){return 3*e*c*Math.pow(1-c,2)+3*n*Math.pow(c,2)*(1-c)+Math.pow(c,3)}function a(c){return 3*t*c*Math.pow(1-c,2)+3*o*Math.pow(c,2)*(1-c)+Math.pow(c,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":B(a)&&(e.bottomSheetContentWrapper.innerHTML=a);break;case"width":B(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":B(a)&&(e.bottomSheetContainer.style.borderRadius=Te(a));break;case"containerBackgroundColor":B(a)&&(e.bottomSheetContainer.style.backgroundColor=a,e.bottomSheetContainerGapFiller.style.backgroundColor=a);break;case"backdropColor":B(a)&&(e.bottomSheetBackdrop.style.backgroundColor=a);break;case"backDropTransition":B(a)&&(e.bottomSheetBackdrop.style.transition=a);break;case"rootClass":if(!B(a))return;X(e.bottomSheetRoot,n.rootClass,a);break;case"containerClass":if(!B(a))return;X(e.bottomSheetContainer,n.containerClass,a);break;case"handleClass":if(!B(a))return;X(e.bottomSheetHandle,n.handleClass,a);break;case"contentWrapperClass":if(!B(a))return;X(e.bottomSheetContentWrapper,n.contentWrapperClass,a);break;case"backdropClass":if(!B(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"draggingAnimationTimings":if(He(a)){const c=le(a),u=ce(c,n.draggingAnimationDuration);t.translateContainer=u}break;case"draggingAnimationDuration":if(A(a)){const c=le(n.draggingAnimationTimings),u=ce(c,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,c={animationFrame:a,onClose:k,bottomSheetState:o,draggingState:r,snapTo:y,moveUp:O,moveDown:C},{elements:u,eventHandlers:h}=Xe(t,c),s=Ze(t,ct(u,o,t,h)),{bottomSheetBackdrop:f,bottomSheetRoot:E,bottomSheetContainer:l}=u,w=p=>{const d=p??window.document.body;d.appendChild(E),d.appendChild(f);const b=window.innerHeight;ne(l,{y:b}),h.attachEventListeners(),o.isMounted=!0},m=()=>{h.clearEventListeners(),Object.values(u).forEach(p=>{p.remove()}),i(),o.isMounted=!1},v=()=>{var p;if(x()||et('Bottom Sheet is not mounted yet. call the "mount" method first.'),(p=e.beforeOpen)==null||p.call(e),H())return;re(f,!0),s.shouldShowBackdrop||_(f,"transparent"),re([l],!0),ne(l,{y:l.clientHeight});const d=window.innerHeight,b=fe(d,l.clientHeight,s.marginTop,s.defaultPosition),S=P(l).y;o.translateContainer({startY:S,endY:b,animationFrame:a,bottomSheetContainer:l,onEnd:e.afterOpen});const L=document.body.style.overflowY;r.originalDocumentOverflowY=L||"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 k(){var p;if(j())return;(p=e.beforeClose)==null||p.call(e);const d=P(l).y,b=l.clientHeight;o.translateContainer({startY:d,endY:b,animationFrame:a,bottomSheetContainer:l,onEnd:()=>{var S;(S=e.afterClose)==null||S.call(e),re([f,l],!1),h.clearOnOpenEventListeners()}}),i()}function x(){return o.isMounted}function H(){const p=P(l).y,d=window.innerHeight,b=l.clientHeight>=d?d:l.clientHeight;return p<=b}function j(){return!H()}function V(){const p=P(l).y,d=l.clientHeight,b=window.innerHeight;if(p<=5&&p>=-5)return I.CONTENT_HEIGHT;const S=d-p;if(S===b/2)return I.MIDDLE;const L=b-s.marginTop,D=10;return S<=L+D&&S>=L-D?I.TOP:I.CLOSED}function K(){return l.clientHeight}function G(p){if(!H())return;const d=P(l).y,b=l.clientHeight-d,S=window.innerHeight-p,L=Ie(b,S),D=q(b,S);o.translateContainer({startY:d,endY:d+(L.isUp?-D:D),animationFrame:a,bottomSheetContainer:l})}function U(p,{viewportHeight:d,visibleHeight:b}){let S=null;for(const L of p){const D=L*d,$=q(b,D);(S===null||$<S)&&(S=$)}return{minOffset:S}}function O(){const p=[...s.snapPoints].reverse(),d=P(l).y,b=l.clientHeight,S=b-d;if(!s.expandable&&S>=b)return;const L=window.innerHeight,D=ge("above",{visibleHeight:S,viewportHeight:L},p),{minOffset:$}=U(D,{visibleHeight:S,viewportHeight:L});if($===null&&S<L-s.marginTop){o.translateContainer({startY:d,endY:fe(L,b,s.marginTop,"top"),animationFrame:a,bottomSheetContainer:l});return}A($)&&o.translateContainer({startY:d,endY:d-$,animationFrame:a,bottomSheetContainer:l})}function C(){const p=P(l).y,d=l.clientHeight-p;if(d<1)return;const b=window.innerHeight,S=ge("below",{visibleHeight:d,viewportHeight:b},s.snapPoints),{minOffset:L}=U(S,{visibleHeight:d,viewportHeight:b});A(L)&&o.translateContainer({startY:p,endY:p+L,animationFrame:a,bottomSheetContainer:l})}function y(p){const d=window.innerHeight;if(!Qe(p))return;const b=te(d*p,2);G(b)}return{props:s,elements:u,mount:w,unmount:m,open:v,close:k,getIsMounted:x,getIsOpen:H,getIsClosed:j,getPosition:V,getHeight:K,moveTo:G,snapTo:y}}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=g.forwardRef(function(t,n){const{children:o,isOpen:r,setIsOpen:i,afterClose:a,mountingPointRef:c,...u}=t,h=g.useRef(ut),[s,f]=g.useState(h.current);g.useImperativeHandle(n,()=>s,[s]);const E=g.useCallback(()=>{i(!1),a==null||a()},[a]);g.useEffect(()=>{r?s.open():s.close()},[r]);const l=g.useRef(null);return g.useEffect(function(){var k;if(c&&!c.current)return;const m=Ae((k=t.mountingPointRef)==null?void 0:k.current)?t.mountingPointRef.current:window.document.body;if(!m||s.getIsMounted())return;const v=lt({content:"",...u,afterClose:E});return v.mount(m),l.current=v.elements.bottomSheetContentWrapper??null,h.current=v,f(v),()=>{s.unmount()}},[t.mountingPointRef,u,E]),g.useEffect(function(){Object.assign(h.current.props,{...u}),f(h.current)},[u]),g.useEffect(function(){return()=>{h.current.unmount()}},[]),l.current?xe.createPortal(t.children,l.current):null}),pt=ue();function ht(e={}){const t=g.useRef(pt),[n,o]=g.useState(!1),[r,i]=g.useState(t.current);g.useEffect(()=>{i(t.current)},[t.current]);const{beforeOpen:a,afterOpen:c,beforeClose:u,afterClose:h,onDragStart:s,onDragMove:f,onDragEnd:E,...l}=e,w=()=>{a==null||a()},m=()=>{c==null||c(),o(!0)},v=()=>{u==null||u()},k=()=>{h==null||h(),o(!1)},x=()=>{s==null||s()},H=(C,y)=>{f==null||f(C,y)},j=()=>{E==null||E()},V=g.useMemo(()=>({ref:t,isOpen:n,setIsOpen:o,beforeOpen:w,afterOpen:m,beforeClose:v,afterClose:k,onDragStart:x,onDragMove:H,onDragEnd:j,...l}),[t.current,n,o,e]),K=g.useCallback(()=>{o(!0)},[o]),G=g.useCallback(()=>{o(!0)},[o]),U=g.useCallback((...C)=>{r.moveTo(...C)},[r]),O=g.useCallback((...C)=>{r.snapTo(...C)},[r]);return{props:V,instance:r,isOpen:n,setIsOpen:o,open:K,close:G,moveTo:U,snapTo:O}}M.BottomSheet=dt,M.createPlaceholderBottomSheet=ue,M.useBottomSheet=ht,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.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@plainsheet/core": "0.7.
|
|
34
|
+
"@plainsheet/core": "0.7.9",
|
|
35
35
|
"@plainsheet/utility": "0.0.3"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@eslint/js": "^9.8.0",
|
|
39
|
-
"@types/react": "^
|
|
40
|
-
"@types/react-dom": "^
|
|
39
|
+
"@types/react": "^19.0.0",
|
|
40
|
+
"@types/react-dom": "^19.0.0",
|
|
41
41
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
42
42
|
"@vitest/ui": "^1.6.0",
|
|
43
43
|
"eslint": "^9.8.0",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"vitest": "^1.6.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"react": "
|
|
56
|
-
"react-dom": "
|
|
55
|
+
"react": ">=17.0.0 <20.0.0",
|
|
56
|
+
"react-dom": ">=17.0.0 <20.0.0"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"dev": "vite build --watch --mode development --emptyOutDir=false",
|