@plainsheet/react 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +70 -0
- package/dist/ReactPlainBottomSheet.d.ts +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/plainsheet-core.cjs.js +1 -0
- package/dist/plainsheet-core.es.js +1217 -0
- package/dist/plainsheet-core.umd.js +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dong Hyeok Byun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
Footer
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://plain-bottom-sheet-pbs-docs.vercel.app/">
|
|
3
|
+
<img src="./documents/assets/header.png" width="328" height="167">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<a href="https://bundlejs.com/?q=core@latest" target="\_parent">
|
|
8
|
+
<img alt="" src="https://deno.bundlejs.com/badge?q=core@latest&badge=detailed" />
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
<a href="https://bundlejs.com/?q=@plainsheet/react@latest" target="\_parent">
|
|
12
|
+
<img alt="" src="https://deno.bundlejs.com/badge?q=@plainsheet/react@latest" />
|
|
13
|
+
</a>
|
|
14
|
+
|
|
15
|
+
<a href="https://codecov.io/gh/PeterByun/plain-bottom-sheet" >
|
|
16
|
+
<img src="https://codecov.io/gh/PeterByun/plain-bottom-sheet/graph/badge.svg?token=WFHGUAI3GC"/>
|
|
17
|
+
</a>
|
|
18
|
+
|
|
19
|
+
The **minimalistic**, **configurable** bottom sheet for any web project.
|
|
20
|
+
|
|
21
|
+
### [Check out our website](https://plain-bottom-sheet-pbs-docs.vercel.app/), for a quick start guide, APIs, examples, and more!
|
|
22
|
+
|
|
23
|
+
## Why?
|
|
24
|
+
|
|
25
|
+
### 🧩 Framework-agnostic
|
|
26
|
+
|
|
27
|
+
Works with vanilla JavaScript🍦, or React ⚛️.
|
|
28
|
+
|
|
29
|
+
### ⛓️💥 Zero Dependencies
|
|
30
|
+
|
|
31
|
+
So your app does not depend on any other libraries that you don't need.
|
|
32
|
+
|
|
33
|
+
### ☁️ Super Lightweight(Only 7 kB, compressed)
|
|
34
|
+
|
|
35
|
+
So you don't have to compromise loading speed.
|
|
36
|
+
|
|
37
|
+
### 📱 Mobile-friendly
|
|
38
|
+
|
|
39
|
+
Works just like the native bottom sheet.
|
|
40
|
+
|
|
41
|
+
### 🎛 Highly Configurable
|
|
42
|
+
|
|
43
|
+
- Style it anyway you want, using CSS.
|
|
44
|
+
- Change its behaviors, on the fly.
|
|
45
|
+
- Hook into life-cycle events, and states.
|
|
46
|
+
|
|
47
|
+
### 🦮 Accessibility Support
|
|
48
|
+
|
|
49
|
+
Keyboard interactions and focus management works out-of-box.
|
|
50
|
+
|
|
51
|
+
### 🍰 Works Out of The Box
|
|
52
|
+
|
|
53
|
+
Without any configs.
|
|
54
|
+
|
|
55
|
+
### 🦾 Fully-typed
|
|
56
|
+
|
|
57
|
+
### ⚡️ Performant By Default
|
|
58
|
+
|
|
59
|
+
## Philosophy
|
|
60
|
+
|
|
61
|
+
As the name suggests, we strive to make the plain bottom sheet minimalistic yet feature-rich and highly configurable.
|
|
62
|
+
We try our best to write concise, well-tested, and maintainable code to achieve this goal.
|
|
63
|
+
|
|
64
|
+
## Support the project 🤍
|
|
65
|
+
|
|
66
|
+
We very much appreciate all your support.
|
|
67
|
+
|
|
68
|
+
- If you find it useful or interesting, please [star the repository](https://github.com/plainsheet/plainsheet/stargazers),
|
|
69
|
+
- [Share this repository](https://github.com/plainsheet/plainsheet?tab=readme-ov-file) with others, if you would like to.
|
|
70
|
+
- If you find any issues, feel free to [open an issue](https://github.com/plainsheet/plainsheet/issues). We appreciate every opinion.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { BottomSheet, BottomSheetProps } from '@plainsheet/core';
|
|
3
|
+
import { OmitKeyof } from 'pbs-utility';
|
|
4
|
+
|
|
5
|
+
export { createPlaceholderBottomSheet } from '@plainsheet/core';
|
|
6
|
+
export type { BottomSheet } from '@plainsheet/core';
|
|
7
|
+
export type PlainBottomSheetProps = {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
isOpen: boolean;
|
|
10
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
11
|
+
mountingPoint?: Element | null;
|
|
12
|
+
} & CoreProps;
|
|
13
|
+
type CoreProps = OmitKeyof<BottomSheetProps, "content", "safely">;
|
|
14
|
+
export declare const ReactPlainBottomSheet: import('react').ForwardRefExoticComponent<{
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
18
|
+
mountingPoint?: Element | null;
|
|
19
|
+
} & CoreProps & import("react").RefAttributes<BottomSheet>>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ReactPlainBottomSheet';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("react"),Lt=require("react-dom");function xt(t){return t!=null}(function(){try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode('.pbs-root{position:fixed;left:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;width:100%;height:fit-content;max-height:100vh;z-index:2}.pbs-dialog-reset{background-color:transparent;color:inherit;border:none;outline:none;padding:0;margin:0}.pbs-backdrop{position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;background-color:transparent;z-index:1;transition:background-color .2s ease-out}.pbs-backdrop.hidden{display:none}.pbs-backdrop.open{background-color:#454545b3}.pbs-container{--pbs-container-background-color: rgb(240, 240, 240);background-color:var(--pbs-container-background-color);position:relative;display:none;flex-direction:column;align-items:center;justify-content:flex-start;width:92%;height:fit-content;max-height:100vh;border-radius:10px 10px 0 0}.pbs-container.open{display:flex}.pbs-container .pbs-gap-filler{position:absolute;bottom:calc(-100vh + .5px);left:0;background-color:var(--pbs-container-background-color);content:"";width:100%;height:100vh}.pbs-handle{position:relative;display:flex;align-items:center;justify-content:center;width:100%;height:30px;cursor:pointer}.pbs-handle.hidden{display:none}.pbs-button-reset{background-color:transparent;-webkit-appearance:none;-moz-appearance:none;appearance:none;outline:none;border:none}button:focus.pbs-button-reset{outline:none}.pbs-handle-bar{background-color:#a8a8a8;position:relative;width:12%;height:7px;border-radius:12px}.pbs-handle-bar.hidden{display:none}.pbs-content-wrapper{position:relative;width:100%;height:fit-content;max-height:100%;overflow-y:scroll}.pbs-content-wrapper::-webkit-scrollbar{display:none}.example{-ms-overflow-style:none;scrollbar-width:none}')),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();var At=Object.defineProperty,Ot=(t,e,n)=>e in t?At(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,_=(t,e,n)=>(Ot(t,typeof e!="symbol"?e+"":e,n),n);function H(t){return typeof t=="string"}function Dt(t,e){return t.classList.contains(Q(e))}function q(t,e){t.classList.add(Q(e))}function nt(t,e){t.classList.remove(Q(e))}function j(t,e,n){H(n)&&(H(e)&&nt(t,e),q(t,n))}function Q(t){return H(t)?t.trim().replace(/\./g,""):""}function R(t){return t.map(e=>Q(e)).filter(Boolean).join(" ")}function Pt(t){return t.map(e=>e==null?void 0:e.trim()).filter(Boolean).map(e=>`.${e}`).join(" ")}const ct="open",lt="hidden";function et(t,e){const n=e;if(Array.isArray(t)){t.forEach(o=>{X(o,n),o.setAttribute("aria-modal",n?"true":"false")});return}X(t,n),t.setAttribute("aria-modal",n?"true":"false")}function X(t,e){e?(q(t,ct),nt(t,lt)):(q(t,lt),nt(t,ct))}function bt(t){return t instanceof HTMLElement}function L(t){return typeof t=="number"&&!Number.isNaN(t)}function Bt(t){bt(t)&&t.focus()}function Mt(t){if(!bt(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),n=L(e)?parseInt(e,10):-1,o=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),i=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return o||i||n>-1}var y=(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))(y||{}),ot=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(ot||{}),$=(t=>(t.Hidden="hidden",t))($||{});function M(t,e,n){const o=document.createElement(t);return e.split(" ").forEach(i=>{q(o,i)}),H(n)&&o.setAttribute("data-testid",n),o}Pt([y.Root,y.ContentWrapper]);function ut(t,e,n,o){switch(o){case"content-height":return e>=t?Ct(t,e,n):0;case"middle":return-(t/2-e);case"top":return-(t-e)+n;default:return 0}}function vt(t,e){const n=e<t,o=e>t;return{isUp:n,isDown:o,stayedSame:e===t}}function St(t,e){return e<t?-(t-e):e-t}function z(t,e){return t>e?t-e:e-t}function Yt(t,e){const n=t<e,o=t>e;return{isUp:n,isDown:o,stayedSame:t===e}}function dt(t,e,n){const o=t==="above";return n.filter(i=>{const r=i*e.viewportHeight;return o?e.visibleHeight<r:e.visibleHeight>r})}function Ct(t,e,n){return-(t-e)+n}function pt(t){return Number(t.replace("px",""))}function V(t,...e){return Number(t.toFixed(...e))}function wt(t){const e=/(?<type>\w+)\((?<values>[^)]+)\)/g,n=[];let o;for(;(o=e.exec(t))!==null;){const i=o[1],r=o[2].split(",").map(c=>c.trim());n.push({type:i,values:r})}return n}function It(t){const e=t.style.transform,n=wt(e);return{transform:e,transformValues:n}}function yt(t,e){return t.find(o=>o.type.startsWith(e))||null}const rt="translate";function P(t){const e=t.style.transform,n=wt(e),o=yt(n,rt);return Et(o??{type:rt,values:[]})}function K(t,{x:e,y:n}){const{transform:o,transformValues:i}=It(t),r=yt(i,rt);if(r){const c=Et(r);t.style.transform=`translate(${e??c.x??0}px,${n??c.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${e??0}px,${n??0}px)`;return}t.style.transform=`translate(${e??0}px,${n??0}px)`}function 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:pt(e)??0,y:pt(n)??0}}function it(t){return t!=null}function ht(t,{min:e,max:n}){return it(n)&&t>=n?n:it(e)&&t<=e?e:t}const Rt=(t,e,n)=>{e instanceof HTMLElement&&!Dt(e,y.Handle)&&n.scrollTop>=1||(t.isDragging=!0)},Nt=(t,e,n,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=P(e),o.originalDocumentOverflowY=document.body.style.overflowY,document.body.style.overflowY="hidden",n.onDragStart()},Ft=(t,e,n,o,i)=>r=>{Wt(r,t,n,o,i,e,n.marginTop)};function Wt(t,e,n,o,i,r,c){if(!o.isDragging||!L(o.startY))return;const a=e.getCoordinates(t).y,m=St(o.startY,a),u=window.innerHeight,l=r.clientHeight,b=l-(o.containerStartTranslate.y+m);if(b>=u)return;const s=vt(o.startY,a);if(s.isUp&&!n.expandable&&b>=l)return;i.start(()=>{K(r,{y:o.containerStartTranslate.y+m})},0);const v=u-c,k=l-o.containerStartTranslate.y;if(s.isUp){const S=v-k,C=v-b,E=ht(1-V(C/S,2),{min:0,max:1});n.onDragMove(s,E)}else if(s.isDown){const S=ht(V(1-b/k,2),{min:0,max:1});n.onDragMove(s,S)}}const Ut=(t,e,n,o,i,r,c)=>a=>{if(!o.isDragging||(o.isDragging=!1,document.body.style.overflowY=o.originalDocumentOverflowY,!L(o.startY)))return;n.onDragEnd();const m=o.startY,u=t.getCoordinates(a).y,l=P(e).y,b=vt(m,u),s=window.innerHeight,v=e.clientHeight;if(b.isUp){const k=[...n.snapPoints].sort((E,w)=>E-w),S=v+-l;if(!n.expandable&&S>=v)return;for(const E of k){const w=E*window.innerHeight;if(S<=w){const Y=z(S,w);c.translateContainer({startY:l,endY:l-Y,animationFrame:i,bottomSheetContainer:e});return}}const C=Ct(s,v,n.marginTop);c.translateContainer({startY:l,endY:C,animationFrame:i,bottomSheetContainer:e})}else if(b.isDown){const k=[...n.snapPoints].sort((S,C)=>C-S);for(const S of k){const C=S*window.innerHeight,E=v+-l;if(E>=C){const w=z(E,C);c.translateContainer({startY:l,endY:l+w,animationFrame:i,bottomSheetContainer:e});return}}r()}};var W=(t=>(t[t.All=-1]="All",t[t.None=0]="None",t[t.Capture=1]="Capture",t[t.Target=2]="Target",t[t.Bubble=3]="Bubble",t))(W||{});function mt(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const jt={eventPhase:W.All};class G{constructor(e){_(this,"currentTarget"),this.currentTarget=e}addEventListeners({onStart:e,onStartOptions:n=jt,onMove:o,onEnd:i}){this.addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}),this.addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i})}addTouchEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("touchstart",r=>{if(n.eventPhase===W.All){e(r);return}mt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),i&&this.currentTarget.addEventListener("touchend",i)}addMouseEventListeners({onStart:e,onStartOptions:n,onMove:o,onEnd:i}){e&&this.currentTarget.addEventListener("mousedown",r=>{if(n.eventPhase===W.All){e(r);return}mt(r.eventPhase)===n.eventPhase&&e(r)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),i&&this.currentTarget.addEventListener("mouseup",r=>{i(r)})}removeEventListeners({onStart:e,onMove:n,onEnd:o}){e&&this.currentTarget.removeEventListener("touchstart",e),o&&this.currentTarget.removeEventListener("touchend",o),n&&this.currentTarget.removeEventListener("touchmove",n),e&&this.currentTarget.removeEventListener("mousedown",e),n&&this.currentTarget.removeEventListener("mousemove",n),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(e){if(e.type==="touchstart"||e.type==="mousedown"){if("touches"in e)return{x:e.touches[0].clientX,y:e.touches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}if(e.type==="touchend"||e.type==="mouseup"||e.type==="mousemove"||e.type==="touchmove"){if("touches"in e)return{x:e.changedTouches[0].clientX,y:e.changedTouches[0].clientY};if(e instanceof MouseEvent)return{x:e.clientX,y:e.clientY}}return{x:0,y:0}}}function Gt(t,e){const n=_t(t);$t(n),n.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const i=window.innerHeight;n.bottomSheetContainer.style.maxHeight=`${i}px`,n.bottomSheetContentWrapper.appendChild(o);const r=qt({bottomSheetElements:n,bottomSheetProps:t,options:e});return{elements:n,eventHandlers:r}}function _t(t){const e=M("dialog",R([y.Root,ot.Dialog,t.rootClass]),y.Root);e.ariaLabel=t.ariaLabel;const n=M("section",R([y.Container,t.containerClass]),y.Container);t.containerBorderRadius&&(n.style.borderRadius=t.containerBorderRadius);const o=M("div",y.GapFiller,y.GapFiller),i=M("button",R([y.Handle,ot.Button,t.shouldShowHandle?null:$.Hidden,t.handleClass]),y.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=M("span",R([y.HandleBar,t.shouldShowHandle?null:$.Hidden]),y.HandleBar),c=M("article",R([y.ContentWrapper,t.contentWrapperClass]),y.ContentWrapper),a=M("div",R([y.Backdrop,t.backdropClass,$.Hidden]),y.Backdrop);return t.backdropColor&&(a.style.backgroundColor=t.backdropColor),t.backDropTransition&&(a.style.transition=t.backDropTransition),{bottomSheetRoot:e,bottomSheetBackdrop:a,bottomSheetContainer:n,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function $t({bottomSheetRoot:t,bottomSheetContainer:e,bottomSheetHandle:n,bottomSheetHandleBar:o,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:r}){t.appendChild(e),n.appendChild(o),e.appendChild(n),e.appendChild(i),e.appendChild(r)}function qt({bottomSheetElements:t,bottomSheetProps:e,options:n}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:a}=t,{animationFrame:m}=n,u=new G(r),l=new G(a),b=new G(c),s=e.dragTriggers.reduce((f,x)=>{const A=o.querySelectorAll(x);if(!A.length)return f;const tt=Array.from(A).map(B=>B instanceof HTMLElement?new G(B):null).filter(B=>!!B);return[...f,...tt]},[]),v=new G(window),k=Nt(v,i,e,n.draggingState),S=Ft(v,i,e,n.draggingState,m),C=Ut(v,i,e,n.draggingState,m,n.onClose,n.bottomSheetState);function E(f){f.target instanceof Element&&!o.contains(f.target)&&n.onClose()}function w(f){Rt(n.draggingState,f.target,t.bottomSheetContentWrapper)}function Y(){e.draggable&&(u.addEventListeners({onStart:w}),s.forEach(f=>{f.addEventListeners({onStart:w,onStartOptions:{eventPhase:W.Target}})})),e.draggable&&e.backgroundDraggable&&(l.addEventListeners({onStart:w,onStartOptions:{eventPhase:W.Target}}),b.addEventListeners({onStart:w})),e.draggable&&v.addEventListeners({onStart:k,onMove:S,onEnd:C}),e.draggable&&window.document.addEventListener("keyup",f=>{f.key==="Escape"&&n.onClose()}),e.shouldCloseOnOutsideClick&&window.document.addEventListener("click",E),r.addEventListener("keyup",f=>{if(f.key==="ArrowUp"){n.moveUp();return}if(f.key==="ArrowDown"){n.moveDown();return}if(f.shiftKey&&f.key==="Tab"){const x=Z(t.bottomSheetContentWrapper);Bt(x)}})}function Z(f){let x=[...Array.from(f.childNodes).reverse()];for(;x.length;){const A=x.shift();if(Mt(A))return A;A&&(x=[...x,...Array.from(A.childNodes).reverse()])}return null}function J(){u.removeEventListeners({onStart:w}),l.removeEventListeners({onStart:w}),b.removeEventListeners({onStart:w}),s.forEach(f=>{f.removeEventListeners({onStart:w})}),v.removeEventListeners({onStart:k,onMove:S,onEnd:C}),window.removeEventListener("click",E)}return{attachEventListeners:Y,clearEventListeners:J}}class Xt{constructor(){_(this,"animationId"),_(this,"isInProgress"),_(this,"startedAt"),this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(e,n,o=!1){this.isInProgress=!0;const i=r=>{this.startedAt||(this.startedAt=r);const c=r-this.startedAt,a=n===0?1:V(c/n,2),m=a>=1&&!o;e(a),m?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,L(this.animationId)&&cancelAnimationFrame(this.animationId)}}function zt(t){const{startY:e,endY:n,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:a}=t,m=St(e,n);i.stop();let u=!1;i.start(l=>{K(o,{y:e+m*c(l)}),!u&&l>=1&&(r==null||r(),u=!0)},a)}const at=(t,e)=>n=>{zt({...n,animationTimingFunction:t,animationDuration:e})},F={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Vt(t){return!(!L(t)||t>1||t<0)}function Kt(t,e){const n={set(o,i,r,c){return e(i,r),Reflect.set(o,i,r,c)}};return new Proxy(t,n)}function Qt(...t){console.error(t)}const N={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function Zt(t){for(const e of Object.values(N))if(e===t)return!0;return!1}function Tt(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&L(t.p1x)&&L(t.p1y)&&L(t.p2x)&&L(t.p2y))}function U(t,e,n,o){return function(a){return c(i(a))};function i(a){let m=0,u=1,l=a,b;if(a===0||a===1)return a;for(;m<u;){if(b=r(l),Math.abs(b-a)<.001)return l;a>b?m=l:u=l,l=(u+m)/2}return l}function r(a){return 3*t*a*Math.pow(1-a,2)+3*n*Math.pow(a,2)*(1-a)+Math.pow(a,3)}function c(a){return 3*e*a*Math.pow(1-a,2)+3*o*Math.pow(a,2)*(1-a)+Math.pow(a,3)}}const Jt=U(.25,.1,.25,1),te=U(.42,0,1,1),Ht=U(.42,0,.58,1),ft=U(.4,.1,.6,1),ee=U(.45,1.5,.55,1);function ne(t){switch(t){case N.EASE:return Jt;case N.EASE_IN:return te;case N.EASE_OUT:return Ht;case N.EASE_IN_OUT:return ft;case N.SPRING:return ee;default:return ft}}function gt(t){return typeof t=="boolean"}const oe={ariaLabel:"Bottom sheet",content:"",defaultPosition:F.CONTENT_HEIGHT,marginTop:20,snapPoints:[],width:"92%",dragTriggers:[],beforeOpen:()=>{},afterOpen:()=>{},beforeClose:()=>{},afterClose:()=>{},onDragStart:()=>{},onDragMove:()=>{},onDragEnd:()=>{},expandable:!0,draggable:!0,backgroundDraggable:!0,shouldCloseOnOutsideClick:!0,shouldShowBackdrop:!0,shouldShowHandle:!0,backDropTransition:null,backdropColor:null,containerBorderRadius:null,rootClass:null,containerClass:null,handleClass:null,contentWrapperClass:null,backdropClass:null,draggingAnimationTimings:"ease-in-out",draggingAnimationDuration:180};function re(t){const e={...oe},n=Object.entries(t).reduce((o,i)=>{const[r,c]=i;return it(c)&&(o[r]=c),o},{});return{...e,...n}}function st(t){if(Tt(t)){const{p1x:e,p1y:n,p2x:o,p2y:i}=t;return U(e,n,o,i)}return Zt(t)?ne(t):Ht}function ie(t,e,n){function o(i,r){switch(i){case"content":H(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":H(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":gt(r)||X(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":gt(r)||X(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":H(r)&&(t.bottomSheetContainer.style.borderRadius=r);break;case"backdropColor":H(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":H(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!H(r))return;j(t.bottomSheetRoot,n.rootClass,r);break;case"containerClass":if(!H(r))return;j(t.bottomSheetContainer,n.containerClass,r);break;case"handleClass":if(!H(r))return;j(t.bottomSheetHandle,n.handleClass,r);break;case"contentWrapperClass":if(!H(r))return;j(t.bottomSheetContentWrapper,n.contentWrapperClass,r);break;case"backdropClass":if(!H(r))return;j(t.bottomSheetBackdrop,n.backdropClass,r);break;case"draggingAnimationTimings":if(Tt(r)){const c=st(r),a=at(c,n.draggingAnimationDuration);e.translateContainer=a}break;case"draggingAnimationDuration":if(L(r)){const c=st(n.draggingAnimationTimings),a=at(c,r);e.translateContainer=a}break}}return o}function ae(t){const e=re(t),n=st(t.draggingAnimationTimings),o={isMounted:!1,translateContainer:at(n,e.draggingAnimationDuration)},i={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:document.body.style.overflowY},r=new Xt,c={animationFrame:r,onClose:C,bottomSheetState:o,draggingState:i,snapTo:B,moveUp:A,moveDown:tt},{elements:a,eventHandlers:m}=Gt(e,c),u=Kt(e,ie(a,o,e)),{bottomSheetBackdrop:l,bottomSheetRoot:b,bottomSheetContainer:s}=a,v=d=>{const p=d??window.document.body;p.appendChild(b),p.appendChild(l);const h=window.innerHeight;K(s,{y:h}),m.attachEventListeners(),o.isMounted=!0},k=()=>{m.clearEventListeners(),Object.values(a).forEach(d=>{d.remove()}),o.isMounted=!1},S=()=>{var d;if(E()||Qt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(d=t.beforeOpen)==null||d.call(t),w())return;u.shouldShowBackdrop&&et(l,!0),et([s],!0),K(s,{y:s.clientHeight});const p=window.innerHeight,h=ut(p,s.clientHeight,u.marginTop,u.defaultPosition),g=P(s).y;o.translateContainer({startY:g,endY:h,animationFrame:r,bottomSheetContainer:s,onEnd:t.afterOpen}),a.bottomSheetHandle.focus()};function C(){var d;if(Y())return;(d=t.beforeClose)==null||d.call(t);const p=P(s).y,h=s.clientHeight;o.translateContainer({startY:p,endY:h,animationFrame:r,bottomSheetContainer:s,onEnd:()=>{var g;(g=t.afterClose)==null||g.call(t),et([l,s],!1)}})}function E(){return o.isMounted}function w(){const d=P(s).y,p=window.innerHeight,h=s.clientHeight>=p?p:s.clientHeight;return d<h}function Y(){return!w()}function Z(){const d=P(s).y,p=s.clientHeight,h=window.innerHeight;if(d<=5&&d>=-5)return F.CONTENT_HEIGHT;const g=p-d;if(g===h/2)return F.MIDDLE;const T=h-u.marginTop,O=10;return g<=T+O&&g>=T-O?F.TOP:F.CLOSED}function J(){return s.clientHeight}function f(d){const p=P(s).y,h=s.clientHeight-p,g=window.innerHeight-d,T=Yt(h,g),O=z(h,g);o.translateContainer({startY:p,endY:p+(T.isUp?-O:O),animationFrame:r,bottomSheetContainer:s})}function x(d,{viewportHeight:p,visibleHeight:h}){let g=null;for(const T of d){const O=T*p,I=z(h,O);(g===null||I<g)&&(g=I)}return{minOffset:g}}function A(){const d=[...u.snapPoints].reverse(),p=P(s).y,h=s.clientHeight,g=h-p;if(!u.expandable&&g>=h)return;const T=window.innerHeight,O=dt("above",{visibleHeight:g,viewportHeight:T},d),{minOffset:I}=x(O,{visibleHeight:g,viewportHeight:T});if(I===null&&g<T-u.marginTop){o.translateContainer({startY:p,endY:ut(T,h,u.marginTop,"top"),animationFrame:r,bottomSheetContainer:s});return}L(I)&&o.translateContainer({startY:p,endY:p-I,animationFrame:r,bottomSheetContainer:s})}function tt(){const d=P(s).y,p=s.clientHeight-d;if(p<1)return;const h=window.innerHeight,g=dt("below",{visibleHeight:p,viewportHeight:h},u.snapPoints),{minOffset:T}=x(g,{visibleHeight:p,viewportHeight:h});L(T)&&o.translateContainer({startY:d,endY:d+T,animationFrame:r,bottomSheetContainer:s})}function B(d){const p=window.innerHeight;if(!Vt(d))return;const h=V(p*d,2);f(h)}return{props:u,elements:a,mount:v,unmount:k,open:S,close:C,getIsMounted:E,getIsOpen:w,getIsClosed:Y,getPosition:Z,getHeight:J,moveTo:f,snapTo:B}}function kt(){return{elements:{bottomSheetRoot:void 0,bottomSheetBackdrop:void 0,bottomSheetContainer:void 0,bottomSheetHandle:void 0,bottomSheetHandleBar:void 0,bottomSheetContentWrapper:void 0,bottomSheetContainerGapFiller:void 0},mount:()=>{},unmount:()=>{},open:()=>{},close:()=>{},getIsMounted:()=>!1,getHeight:()=>0,getIsOpen:()=>!1,getIsClosed:()=>!0,getPosition:()=>F.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}const se=kt(),ce=D.forwardRef(function(e,n){const{children:o,isOpen:i,setIsOpen:r,afterClose:c,mountingPoint:a,...m}=e,u=D.useRef(se),[l,b]=D.useState(u.current);D.useImperativeHandle(n,()=>l,[l]);const s=D.useCallback(()=>{r(!1),c==null||c()},[c]);D.useEffect(()=>{i?l.open():l.close()},[i]);const v=D.useRef(null);return D.useEffect(function(){const S=xt(e.mountingPoint)?e.mountingPoint:window.document.body;if(!S||l.getIsMounted())return;const C=ae({content:"",...m,afterClose:s});return C.mount(S),v.current=C.elements.bottomSheetContentWrapper??null,u.current=C,b(C),()=>{l.unmount()}},[e.mountingPoint,m,s]),D.useEffect(function(){Object.assign(u.current.props,{...m}),b(u.current)},[m]),v.current?Lt.createPortal(e.children,v.current):null});exports.ReactPlainBottomSheet=ce;exports.createPlaceholderBottomSheet=kt;
|