@plainsheet/core 0.7.1 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/bottom-sheet.d.ts.map +1 -1
- package/dist/initializer/bottom-sheet-initializer.d.ts +2 -0
- package/dist/initializer/bottom-sheet-initializer.d.ts.map +1 -1
- package/dist/initializer/bottom-sheet-props-initializer.d.ts.map +1 -1
- package/dist/initializer/style/style-initializer.d.ts +2 -0
- package/dist/initializer/style/style-initializer.d.ts.map +1 -0
- package/dist/plainsheet-core.cjs.js +2 -2
- package/dist/plainsheet-core.es.js +431 -416
- package/dist/plainsheet-core.umd.js +3 -3
- package/dist/types/bottom-sheet-props.type.d.ts +10 -2
- package/dist/types/bottom-sheet-props.type.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ Without any configs.
|
|
|
59
59
|
## Philosophy
|
|
60
60
|
|
|
61
61
|
As the name suggests, we strive to make the plain bottom sheet minimalistic yet feature-rich and highly configurable.
|
|
62
|
-
|
|
62
|
+
To achieve this goal, we try our best to write concise, well-tested, and maintainable code.
|
|
63
63
|
|
|
64
64
|
## Support the project 🤍
|
|
65
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bottom-sheet.d.ts","sourceRoot":"","sources":["../src/bottom-sheet.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,0BAA0B,CAAC;AAClC,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AAiBjC,OAAO,KAAK,EAEV,oBAAoB,EAErB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bottom-sheet.d.ts","sourceRoot":"","sources":["../src/bottom-sheet.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,0BAA0B,CAAC;AAClC,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC;AAChC,OAAO,yBAAyB,CAAC;AAiBjC,OAAO,KAAK,EAEV,oBAAoB,EAErB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAcjE,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,oBAAoB,GAC1B,eAAe,CAqYjB"}
|
|
@@ -32,6 +32,8 @@ export interface InitializeEventsParams {
|
|
|
32
32
|
interface InitializeEventsReturnType {
|
|
33
33
|
attachEventListeners: () => void;
|
|
34
34
|
clearEventListeners: () => void;
|
|
35
|
+
attacheOnOpenEventListeners: () => void;
|
|
36
|
+
clearOnOpenEventListeners: () => void;
|
|
35
37
|
}
|
|
36
38
|
export {};
|
|
37
39
|
//# sourceMappingURL=bottom-sheet-initializer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bottom-sheet-initializer.d.ts","sourceRoot":"","sources":["../../src/initializer/bottom-sheet-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAejE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAOzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"bottom-sheet-initializer.d.ts","sourceRoot":"","sources":["../../src/initializer/bottom-sheet-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAejE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAOzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAG7E,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,UAAU,uCAAuC;IAC/C,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,aAAa,EAAE,0BAA0B,CAAC;CAC3C;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,QAAQ,CAAC,oBAAoB,CAAC,EACrC,OAAO,EAAE,kBAAkB,GAC1B,uCAAuC,CAsBzC;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,WAAW,CAAC;IAC7B,mBAAmB,EAAE,WAAW,CAAC;IACjC,oBAAoB,EAAE,WAAW,CAAC;IAClC,iBAAiB,EAAE,WAAW,CAAC;IAC/B,oBAAoB,EAAE,WAAW,CAAC;IAClC,yBAAyB,EAAE,WAAW,CAAC;IACvC,6BAA6B,EAAE,WAAW,CAAC;CAC5C;AA4GD,MAAM,WAAW,sBAAsB;IACrC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,gBAAgB,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IACjD,OAAO,EAAE,kBAAkB,CAAC;CAC7B;AAED,UAAU,0BAA0B;IAClC,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,2BAA2B,EAAE,MAAM,IAAI,CAAC;IACxC,yBAAyB,EAAE,MAAM,IAAI,CAAC;CACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bottom-sheet-props-initializer.d.ts","sourceRoot":"","sources":["../../src/initializer/bottom-sheet-props-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAezD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"bottom-sheet-props-initializer.d.ts","sourceRoot":"","sources":["../../src/initializer/bottom-sheet-props-initializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAezD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,oBAAoB,GAC1B,wBAAwB,CAuB1B;AAED,wBAAgB,6BAA6B,CAC3C,wBAAwB,EAAE,oBAAoB,CAAC,0BAA0B,CAAC,GACzE,uBAAuB,CAWzB;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,mBAAmB,EAC7B,gBAAgB,EAAE,gBAAgB,EAClC,iBAAiB,EAAE,QAAQ,CAAC,oBAAoB,CAAC,GAChD,kBAAkB,CAwHpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-initializer.d.ts","sourceRoot":"","sources":["../../../src/initializer/style/style-initializer.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,CAG5E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){"use strict";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%;
|
|
2
|
-
"use strict";var St=Object.defineProperty;var kt=(t,n,e)=>n in t?St(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var W=(t,n,e)=>kt(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function y(t){return typeof t=="string"}function Bt(t,n){return t.classList.contains(tt(n))}function K(t,n){t.classList.add(tt(n))}function et(t,n){t.classList.remove(tt(n))}function G(t,n,e){y(e)&&(y(n)&&et(t,n),K(t,e))}function tt(t){return y(t)?t.trim().replace(/\./g,""):""}function R(t){return t.map(n=>tt(n)).filter(Boolean).join(" ")}function Yt(t){return t.map(n=>n==null?void 0:n.trim()).filter(Boolean).map(n=>`.${n}`).join(" ")}const ut="open",dt="hidden";function nt(t,n){const e=n;if(Array.isArray(t)){t.forEach(o=>{z(o,e),o.setAttribute("aria-modal",e?"true":"false")});return}z(t,e),t.setAttribute("aria-modal",e?"true":"false")}function z(t,n){n?(K(t,ut),et(t,dt)):(K(t,dt),et(t,ut))}function bt(t){return t instanceof HTMLElement}function S(t){return typeof t=="number"&&!Number.isNaN(t)}function It(t){bt(t)&&t.focus()}function Nt(t){if(!bt(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),o=S(e)?parseInt(e,10):-1,r=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),c=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return r||c||o>-1}var b=(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))(b||{}),q=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(q||{}),$=(t=>(t.Hidden="hidden",t))($||{});function I(t,n,e){const o=document.createElement(t);return n.split(" ").forEach(r=>{K(o,r)}),y(e)&&o.setAttribute("data-testid",e),o}const Mt={CONTENTS_WRAPPER:Yt([b.Root,b.ContentWrapper])};function ft(t,n,e,o){switch(o){case"content-height":return n>=t?vt(t,n,e):0;case"middle":return-(t/2-n);case"top":return-(t-n)+e;default:return 0}}function Ct(t,n){const e=n<t,o=n>t;return{isUp:e,isDown:o,stayedSame:n===t}}function Et(t,n){return n<t?-(t-n):n-t}function J(t,n){return t>n?t-n:n-t}function Pt(t,n){const e=t<n,o=t>n;return{isUp:e,isDown:o,stayedSame:t===n}}function gt(t,n,e){const o=t==="above";return e.filter(i=>{const r=i*n.viewportHeight;return o?n.visibleHeight<r:n.visibleHeight>r})}function vt(t,n,e){return-(t-n)+e}function ht(t){return Number(t.replace("px",""))}function Q(t,...n){return Number(t.toFixed(...n))}function wt(t){const n=/(?<type>\w+)\((?<values>[^)]+)\)/g,e=[];let o;for(;(o=n.exec(t))!==null;){const i=o[1],r=o[2].split(",").map(c=>c.trim());e.push({type:i,values:r})}return e}function xt(t){const n=t.style.transform,e=wt(n);return{transform:n,transformValues:e}}function Ht(t,n){const e=t.find(o=>o.type.startsWith(n));return e||null}const rt="translate";function Y(t){const n=t.style.transform,e=wt(n),o=Ht(e,rt);return yt(o??{type:rt,values:[]})}function Z(t,{x:n,y:e}){const{transform:o,transformValues:i}=xt(t),r=Ht(i,rt);if(r){const c=yt(r);t.style.transform=`translate(${n??c.x??0}px,${e??c.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${n??0}px,${e??0}px)`;return}t.style.transform=`translate(${n??0}px,${e??0}px)`}function yt(t){if(t.type!=="translate")throw new Error(`Could not get coordinates from ${t.type}, since is not translate.`);const n=t.values[0],e=t.values[1];return{x:ht(n)??0,y:ht(e)??0}}function ot(t){return t!=null}function mt(t,{min:n,max:e}){return ot(e)&&t>=e?e:ot(n)&&t<=n?n:t}const _t=(t,n,e)=>{n instanceof HTMLElement&&!Bt(n,b.Handle)&&e.scrollTop>=1||(t.isDragging=!0)},Ft=(t,n,e,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=Y(n),e.onDragStart()},Rt=(t,n,e,o,i)=>r=>{Ut(r,t,e,o,i,n,e.marginTop)};function Ut(t,n,e,o,i,r,c){if(!o.isDragging||!S(o.startY))return;const l=n.getCoordinates(t).y,a=Et(o.startY,l),p=window.innerHeight,g=r.clientHeight,u=g-(o.containerStartTranslate.y+a);if(u>=p)return;const C=Ct(o.startY,l);if(C.isUp&&!e.expandable&&u>=g)return;i.start(()=>{Z(r,{y:o.containerStartTranslate.y+a})},0);const H=p-c,s=g-o.containerStartTranslate.y;if(C.isUp){const v=H-s,O=H-u,A=mt(1-Q(O/v,2),{min:0,max:1});e.onDragMove(C,A)}else if(C.isDown){const v=mt(Q(1-u/s,2),{min:0,max:1});e.onDragMove(C,v)}}const Wt=(t,n,e,o,i,r,c)=>l=>{if(!o.isDragging||(o.isDragging=!1,!S(o.startY)))return;e.onDragEnd();const a=o.startY,p=t.getCoordinates(l).y,g=Y(n).y,u=Ct(a,p),C=window.innerHeight,H=n.clientHeight;if(u.isUp){const s=[...e.snapPoints].sort((A,E)=>A-E),v=H+-g;if(!e.expandable&&v>=H)return;for(const A of s){const E=A*window.innerHeight;if(v<=E){const x=J(v,E);c.translateContainer({startY:g,endY:g-x,animationFrame:i,bottomSheetContainer:n});return}}const O=vt(C,H,e.marginTop);c.translateContainer({startY:g,endY:O,animationFrame:i,bottomSheetContainer:n})}else if(u.isDown){const s=[...e.snapPoints].sort((v,O)=>O-v);for(const v of s){const O=v*window.innerHeight,A=H+-g;if(A>=O){const E=J(A,O);c.translateContainer({startY:g,endY:g+E,animationFrame:i,bottomSheetContainer:n});return}}r()}};var P=(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))(P||{});function it(t){switch(t){case 0:return 0;case 1:return 1;case 2:return 2;case 3:return 3;default:return-1}}const Gt={eventPhase:P.All};class V{constructor(n){W(this,"currentTarget");this.currentTarget=n}addEventListeners({onStart:n,onStartOptions:e=Gt,onMove:o,onEnd:i}){this.addTouchEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}),this.addMouseEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i})}addTouchEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}){n&&this.currentTarget.addEventListener("touchstart",r=>{if(e.eventPhase===P.All){n(r);return}it(r.eventPhase)===e.eventPhase&&n(r)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),i&&this.currentTarget.addEventListener("touchend",i)}addMouseEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}){n&&this.currentTarget.addEventListener("mousedown",r=>{if(e.eventPhase===P.All){n(r);return}it(r.eventPhase)===e.eventPhase&&n(r)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),i&&this.currentTarget.addEventListener("mouseup",r=>{i(r)})}removeEventListeners({onStart:n,onMove:e,onEnd:o}){n&&this.currentTarget.removeEventListener("touchstart",n),o&&this.currentTarget.removeEventListener("touchend",o),e&&this.currentTarget.removeEventListener("touchmove",e),n&&this.currentTarget.removeEventListener("mousedown",n),e&&this.currentTarget.removeEventListener("mousemove",e),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(n){if(n.type==="touchstart"||n.type==="mousedown"){if("touches"in n)return{x:n.touches[0].clientX,y:n.touches[0].clientY};if(n instanceof MouseEvent)return{x:n.clientX,y:n.clientY}}if(n.type==="touchend"||n.type==="mouseup"||n.type==="mousemove"||n.type==="touchmove"){if("touches"in n)return{x:n.changedTouches[0].clientX,y:n.changedTouches[0].clientY};if(n instanceof MouseEvent)return{x:n.clientX,y:n.clientY}}return{x:0,y:0}}}function Vt(t,n){const e=$t(t);Xt(e),e.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const i=window.innerHeight;e.bottomSheetContainer.style.maxHeight=`${i}px`,e.bottomSheetContentWrapper.appendChild(o);const r=jt({bottomSheetElements:e,bottomSheetProps:t,options:n});return{elements:e,eventHandlers:r}}function $t(t){const n=I("dialog",R([b.Root,q.Dialog,t.rootClass]),b.Root);n.ariaLabel=t.ariaLabel;const e=I("section",R([b.Container,t.containerClass]),b.Container);t.containerBorderRadius&&(e.style.borderRadius=t.containerBorderRadius);const o=I("div",b.GapFiller,b.GapFiller),i=I("button",R([b.Handle,q.Button,t.shouldShowHandle?null:$.Hidden,t.handleClass]),b.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=I("span",R([b.HandleBar,t.shouldShowHandle?null:$.Hidden]),b.HandleBar),c=I("article",R([b.ContentWrapper,t.contentWrapperClass]),b.ContentWrapper),l=I("div",R([b.Backdrop,t.backdropClass,$.Hidden]),b.Backdrop);return t.backdropColor&&(l.style.backgroundColor=t.backdropColor),t.backDropTransition&&(l.style.transition=t.backDropTransition),{bottomSheetRoot:n,bottomSheetBackdrop:l,bottomSheetContainer:e,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function Xt({bottomSheetRoot:t,bottomSheetContainer:n,bottomSheetHandle:e,bottomSheetHandleBar:o,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:r}){t.appendChild(n),e.appendChild(o),n.appendChild(e),n.appendChild(i),n.appendChild(r)}function jt({bottomSheetElements:t,bottomSheetProps:n,options:e}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:l}=t,{animationFrame:a}=e,p=new V(r),g=new V(l),u=new V(c),C=n.dragTriggers.reduce((T,k)=>{const B=o.querySelectorAll(k);if(!B.length)return T;const j=Array.from(B).map(F=>F instanceof HTMLElement?new V(F):null).filter(F=>!!F);return[...T,...j]},[]),H=new V(window),s=Ft(H,i,n,e.draggingState),v=Rt(H,i,n,e.draggingState,a),O=Wt(H,i,n,e.draggingState,a,e.onClose,e.bottomSheetState);function A(T){T.target instanceof Element&&!o.contains(T.target)&&e.onClose()}function E(T){_t(e.draggingState,T.target,t.bottomSheetContentWrapper)}function x(){n.draggable&&(p.addEventListeners({onStart:E}),C.forEach(T=>{T.addEventListeners({onStart:E,onStartOptions:{eventPhase:P.Target}})})),n.draggable&&n.backgroundDraggable&&(g.addEventListeners({onStart:E,onStartOptions:{eventPhase:P.Target}}),u.addEventListeners({onStart:E})),n.draggable&&H.addEventListeners({onStart:s,onMove:v,onEnd:O}),n.draggable&&window.document.addEventListener("keyup",T=>{T.key==="Escape"&&e.onClose()}),n.shouldCloseOnOutsideClick&&window.document.addEventListener("click",A),r.addEventListener("keyup",T=>{if(T.key==="ArrowUp"){e.moveUp();return}if(T.key==="ArrowDown"){e.moveDown();return}if(T.shiftKey&&T.key==="Tab"){const k=_(t.bottomSheetContentWrapper);It(k)}})}function _(T){let k=[...Array.from(T.childNodes).reverse()];for(;k.length;){const B=k.shift();if(Nt(B))return B;B&&(k=[...k,...Array.from(B.childNodes).reverse()])}return null}function X(){p.removeEventListeners({onStart:E}),g.removeEventListeners({onStart:E}),u.removeEventListeners({onStart:E}),C.forEach(T=>{T.removeEventListeners({onStart:E})}),H.removeEventListeners({onStart:s,onMove:v,onEnd:O}),window.removeEventListener("click",A)}return{attachEventListeners:x,clearEventListeners:X}}class Kt{constructor(){W(this,"animationId");W(this,"isInProgress");W(this,"startedAt");this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(n,e,o=!1){this.isInProgress=!0;const i=r=>{this.startedAt||(this.startedAt=r);const c=r-this.startedAt,a=e===0?1:Q(c/e,2),p=a>=1&&!o;n(a),p?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,S(this.animationId)&&cancelAnimationFrame(this.animationId)}}function zt(t){const{startY:n,endY:e,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:l}=t,a=Et(n,e);i.stop();let p=!1;i.start(g=>{Z(o,{y:n+a*c(g)}),!p&&g>=1&&(r==null||r(),p=!0)},l)}const st=(t,n)=>e=>{zt({...e,animationTimingFunction:t,animationDuration:n})},M={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function qt(t){return!(!S(t)||t>1||t<0)}function Jt(t,n){const e={set(o,i,r,c){return n(i,r),Reflect.set(o,i,r,c)}};return new Proxy(t,e)}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 Ot(t){for(const n of Object.values(N))if(n===t)return!0;return!1}function ct(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&S(t.p1x)&&S(t.p1y)&&S(t.p2x)&&S(t.p2y))}function U(t,n,e,o){return function(a){return l(r(a))};function r(a){let p=0,g=1,u=a,C;if(a===0||a===1)return a;for(;p<g;){if(C=c(u),Math.abs(C-a)<.001)return u;a>C?p=u:g=u,u=(g+p)/2}return u}function c(a){return 3*t*a*Math.pow(1-a,2)+3*e*Math.pow(a,2)*(1-a)+Math.pow(a,3)}function l(a){return 3*n*a*Math.pow(1-a,2)+3*o*Math.pow(a,2)*(1-a)+Math.pow(a,3)}}const pt=U(.25,.1,.25,1),Zt=U(.42,0,1,1),At=U(.42,0,.58,1),tn=U(.4,.1,.6,1),nn=U(.45,1.5,.55,1);function en(t){switch(t){case N.EASE:return pt;case N.EASE_IN:return Zt;case N.EASE_OUT:return At;case N.EASE_IN_OUT:return tn;case N.SPRING:return nn;default:return pt}}function Tt(t){return typeof t=="boolean"}const Lt={ariaLabel:"Bottom sheet",content:"",defaultPosition:M.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 rn(t){const n={...Lt},e=Object.entries(t).reduce((i,r)=>{const[c,l]=r;return ot(l)&&(i[c]=l),i},{});return{...n,...e}}function at(t){if(ct(t)){const{p1x:n,p1y:e,p2x:o,p2y:i}=t;return U(n,e,o,i)}return Ot(t)?en(t):At}function on(t,n,e){function o(i,r){switch(i){case"content":y(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":y(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":Tt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":Tt(r)||z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":y(r)&&(t.bottomSheetContainer.style.borderRadius=r);break;case"backdropColor":y(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":y(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!y(r))return;G(t.bottomSheetRoot,e.rootClass,r);break;case"containerClass":if(!y(r))return;G(t.bottomSheetContainer,e.containerClass,r);break;case"handleClass":if(!y(r))return;G(t.bottomSheetHandle,e.handleClass,r);break;case"contentWrapperClass":if(!y(r))return;G(t.bottomSheetContentWrapper,e.contentWrapperClass,r);break;case"backdropClass":if(!y(r))return;G(t.bottomSheetBackdrop,e.backdropClass,r);break;case"draggingAnimationTimings":if(ct(r)){const c=at(r),l=st(c,e.draggingAnimationDuration);n.translateContainer=l}break;case"draggingAnimationDuration":if(S(r)){const c=at(e.draggingAnimationTimings),l=st(c,r);n.translateContainer=l}break}}return o}function sn(t){const n=rn(t),e=at(t.draggingAnimationTimings),i={isMounted:!1,translateContainer:st(e,n.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function c(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const l=new Kt,a={animationFrame:l,onClose:E,bottomSheetState:i,draggingState:r,snapTo:lt,moveUp:F,moveDown:Dt},{elements:p,eventHandlers:g}=Vt(n,a),u=Jt(n,on(p,i,n)),{bottomSheetBackdrop:C,bottomSheetRoot:H,bottomSheetContainer:s}=p,v=d=>{const f=d??window.document.body;f.appendChild(H),f.appendChild(C);const h=window.innerHeight;Z(s,{y:h}),g.attachEventListeners(),i.isMounted=!0},O=()=>{g.clearEventListeners(),Object.values(p).forEach(d=>{d.remove()}),c(),i.isMounted=!1},A=()=>{var D;if(x()||Qt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(D=t.beforeOpen)==null||D.call(t),_())return;u.shouldShowBackdrop&&nt(C,!0),nt([s],!0),Z(s,{y:s.clientHeight});const f=window.innerHeight,h=ft(f,s.clientHeight,u.marginTop,u.defaultPosition),m=Y(s).y;i.translateContainer({startY:m,endY:h,animationFrame:l,bottomSheetContainer:s,onEnd:t.afterOpen}),p.bottomSheetHandle.focus();const w=document.body.style.overflowY;r.originalDocumentOverflowY=w||"initial";const L=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=L||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain"};function E(){var h;if(X())return;(h=t.beforeClose)==null||h.call(t);const d=Y(s).y,f=s.clientHeight;i.translateContainer({startY:d,endY:f,animationFrame:l,bottomSheetContainer:s,onEnd:()=>{var m;(m=t.afterClose)==null||m.call(t),nt([C,s],!1)}}),c()}function x(){return i.isMounted}function _(){const d=Y(s).y,f=window.innerHeight,h=s.clientHeight>=f?f:s.clientHeight;return d<h}function X(){return!_()}function T(){const d=Y(s).y,f=s.clientHeight,h=window.innerHeight;if(d<=5&&d>=-5)return M.CONTENT_HEIGHT;const m=f-d;if(m===h/2)return M.MIDDLE;const w=h-u.marginTop,L=10;return m<=w+L&&m>=w-L?M.TOP:M.CLOSED}function k(){return s.clientHeight}function B(d){if(!_())return;const f=Y(s).y,m=s.clientHeight-f,w=window.innerHeight-d,L=Pt(m,w),D=J(m,w);i.translateContainer({startY:f,endY:f+(L.isUp?-D:D),animationFrame:l,bottomSheetContainer:s})}function j(d,{viewportHeight:f,visibleHeight:h}){let m=null;for(const w of d){const L=w*f,D=J(h,L);(m===null||D<m)&&(m=D)}return{minOffset:m}}function F(){const d=[...u.snapPoints].reverse(),f=Y(s).y,h=s.clientHeight,m=h-f;if(!u.expandable&&m>=h)return;const w=window.innerHeight,L=gt("above",{visibleHeight:m,viewportHeight:w},d),{minOffset:D}=j(L,{visibleHeight:m,viewportHeight:w});if(D===null&&m<w-u.marginTop){i.translateContainer({startY:f,endY:ft(w,h,u.marginTop,"top"),animationFrame:l,bottomSheetContainer:s});return}S(D)&&i.translateContainer({startY:f,endY:f-D,animationFrame:l,bottomSheetContainer:s})}function Dt(){const d=Y(s).y,h=s.clientHeight-d;if(h<1)return;const m=window.innerHeight,w=gt("below",{visibleHeight:h,viewportHeight:m},u.snapPoints),{minOffset:L}=j(w,{visibleHeight:h,viewportHeight:m});S(L)&&i.translateContainer({startY:d,endY:d+L,animationFrame:l,bottomSheetContainer:s})}function lt(d){const f=window.innerHeight;if(!qt(d))return;const h=Q(f*d,2);B(h)}return{props:u,elements:p,mount:v,unmount:O,open:A,close:E,getIsMounted:x,getIsOpen:_,getIsClosed:X,getPosition:T,getHeight:k,moveTo:B,snapTo:lt}}function an(){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:()=>M.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}exports.BOTTOM_SHEET_DEFAULT_PROPS=Lt;exports.BOTTOM_SHEET_POSITION=M;exports.BOTTOM_SHEET_SELECTORS=Mt;exports.COMMON_ANIMATION_KEYS=N;exports.ClassNames=b;exports.EventPhase=P;exports.ResetClassNames=q;exports.UtilClassNames=$;exports.createBottomSheet=sn;exports.createPlaceholderBottomSheet=an;exports.eventPhaseToEnum=it;exports.isAnimationTimingPoints=ct;exports.isCommonAnimationTimingsKey=Ot;
|
|
1
|
+
(function(){"use strict";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(n){console.error("vite-plugin-css-injected-by-js",n)}})();
|
|
2
|
+
"use strict";var kt=Object.defineProperty;var Bt=(t,n,e)=>n in t?kt(t,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[n]=e;var U=(t,n,e)=>Bt(t,typeof n!="symbol"?n+"":n,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(t){return typeof t=="string"}function Yt(t,n){return t.classList.contains(tt(n))}function V(t,n){t.classList.add(tt(n))}function ot(t,n){t.classList.remove(tt(n))}function W(t,n,e){w(e)&&(w(n)&&ot(t,n),V(t,e))}function tt(t){return w(t)?t.trim().replace(/\./g,""):""}function F(t){return t.map(n=>tt(n)).filter(Boolean).join(" ")}function It(t){return t.map(n=>n==null?void 0:n.trim()).filter(Boolean).map(n=>`.${n}`).join(" ")}const dt="open",ft="hidden";function rt(t,n){const e=n;if(Array.isArray(t)){t.forEach(o=>{z(o,e),o.setAttribute("aria-modal",e?"true":"false")});return}z(t,e),t.setAttribute("aria-modal",e?"true":"false")}function z(t,n){n?(V(t,dt),ot(t,ft)):(V(t,ft),ot(t,dt))}function Et(t){return t instanceof HTMLElement}function k(t){return typeof t=="number"&&!Number.isNaN(t)}function Nt(t){Et(t)&&t.focus()}function Mt(t){if(!Et(t)||t.offsetParent===null||"disabled"in t&&t.disabled)return!1;const e=t.getAttribute("tabindex"),o=k(e)?parseInt(e,10):-1,r=["INPUT","BUTTON","SELECT","TEXTAREA","A","AREA","IFRAME"].includes(t.tagName),c=t instanceof HTMLAnchorElement&&t.href!==""||t instanceof HTMLAreaElement&&t.href!=="";return r||c||o>-1}var E=(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))(E||{}),q=(t=>(t.Button="pbs-button-reset",t.Dialog="pbs-dialog-reset",t))(q||{}),$=(t=>(t.Hidden="hidden",t))($||{});function N(t,n,e){const o=document.createElement(t);return n.split(" ").forEach(r=>{V(o,r)}),w(e)&&o.setAttribute("data-testid",e),o}const Pt={CONTENTS_WRAPPER:It([E.Root,E.ContentWrapper])};function gt(t,n,e,o){switch(o){case"content-height":return n>=t?wt(t,n,e):0;case"middle":return-(t/2-n);case"top":return-(t-n)+e;default:return 0}}function Ct(t,n){const e=n<t,o=n>t;return{isUp:e,isDown:o,stayedSame:n===t}}function vt(t,n){return n<t?-(t-n):n-t}function J(t,n){return t>n?t-n:n-t}function xt(t,n){const e=t<n,o=t>n;return{isUp:e,isDown:o,stayedSame:t===n}}function ht(t,n,e){const o=t==="above";return e.filter(i=>{const r=i*n.viewportHeight;return o?n.visibleHeight<r:n.visibleHeight>r})}function wt(t,n,e){return-(t-n)+e}function mt(t){return Number(t.replace("px",""))}function Q(t,...n){return Number(t.toFixed(...n))}function Ht(t){const n=/(?<type>\w+)\((?<values>[^)]+)\)/g,e=[];let o;for(;(o=n.exec(t))!==null;){const i=o[1],r=o[2].split(",").map(c=>c.trim());e.push({type:i,values:r})}return e}function _t(t){const n=t.style.transform,e=Ht(n);return{transform:n,transformValues:e}}function yt(t,n){const e=t.find(o=>o.type.startsWith(n));return e||null}const it="translate";function I(t){const n=t.style.transform,e=Ht(n),o=yt(e,it);return Ot(o??{type:it,values:[]})}function Z(t,{x:n,y:e}){const{transform:o,transformValues:i}=_t(t),r=yt(i,it);if(r){const c=Ot(r);t.style.transform=`translate(${n??c.x??0}px,${e??c.y??0}px)`;return}if(o){t.style.transform=`${o}, translate(${n??0}px,${e??0}px)`;return}t.style.transform=`translate(${n??0}px,${e??0}px)`}function Ot(t){if(t.type!=="translate")throw new Error(`Could not get coordinates from ${t.type}, since is not translate.`);const n=t.values[0],e=t.values[1];return{x:mt(n)??0,y:mt(e)??0}}function st(t){return t!=null}function pt(t,{min:n,max:e}){return st(e)&&t>=e?e:st(n)&&t<=n?n:t}const Ft=(t,n,e)=>{n instanceof HTMLElement&&!Yt(n,E.Handle)&&e.scrollTop>=1||(t.isDragging=!0)},Rt=(t,n,e,o)=>i=>{o.startY=t.getCoordinates(i).y,o.containerStartTranslate=I(n),e.onDragStart()},Ut=(t,n,e,o,i)=>r=>{Wt(r,t,e,o,i,n,e.marginTop)};function Wt(t,n,e,o,i,r,c){if(!o.isDragging||!k(o.startY))return;const l=n.getCoordinates(t).y,a=vt(o.startY,l),T=window.innerHeight,f=r.clientHeight,d=f-(o.containerStartTranslate.y+a);if(d>=T)return;const b=Ct(o.startY,l);if(b.isUp&&!e.expandable&&d>=f)return;i.start(()=>{Z(r,{y:o.containerStartTranslate.y+a})},0);const A=T-c,s=f-o.containerStartTranslate.y;if(b.isUp){const C=A-s,H=A-d,y=pt(1-Q(H/C,2),{min:0,max:1});e.onDragMove(b,y)}else if(b.isDown){const C=pt(Q(1-d/s,2),{min:0,max:1});e.onDragMove(b,C)}}const Gt=(t,n,e,o,i,r,c)=>l=>{if(!o.isDragging||(o.isDragging=!1,!k(o.startY)))return;e.onDragEnd();const a=o.startY,T=t.getCoordinates(l).y,f=I(n).y,d=Ct(a,T),b=window.innerHeight,A=n.clientHeight;if(d.isUp){const s=[...e.snapPoints].sort((y,D)=>y-D),C=A+-f;if(!e.expandable&&C>=A)return;for(const y of s){const D=y*window.innerHeight;if(C<=D){const O=J(C,D);c.translateContainer({startY:f,endY:f-O,animationFrame:i,bottomSheetContainer:n});return}}const H=wt(b,A,e.marginTop);c.translateContainer({startY:f,endY:H,animationFrame:i,bottomSheetContainer:n})}else if(d.isDown){const s=[...e.snapPoints].sort((C,H)=>H-C);for(const C of s){const H=C*window.innerHeight,y=A+-f;if(y>=H){const D=J(y,H);c.translateContainer({startY:f,endY:f+D,animationFrame:i,bottomSheetContainer:n});return}}r()}};var x=(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))(x||{});function at(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:x.All};class G{constructor(n){U(this,"currentTarget");this.currentTarget=n}addEventListeners({onStart:n,onStartOptions:e=$t,onMove:o,onEnd:i}){this.addTouchEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}),this.addMouseEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i})}addTouchEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}){n&&this.currentTarget.addEventListener("touchstart",r=>{if(e.eventPhase===x.All){n(r);return}at(r.eventPhase)===e.eventPhase&&n(r)},{passive:!0}),o&&this.currentTarget.addEventListener("touchmove",o),i&&this.currentTarget.addEventListener("touchend",i)}addMouseEventListeners({onStart:n,onStartOptions:e,onMove:o,onEnd:i}){n&&this.currentTarget.addEventListener("mousedown",r=>{if(e.eventPhase===x.All){n(r);return}at(r.eventPhase)===e.eventPhase&&n(r)},{passive:!0}),o&&this.currentTarget.addEventListener("mousemove",o),i&&this.currentTarget.addEventListener("mouseup",r=>{i(r)})}removeEventListeners({onStart:n,onMove:e,onEnd:o}){n&&this.currentTarget.removeEventListener("touchstart",n),o&&this.currentTarget.removeEventListener("touchend",o),e&&this.currentTarget.removeEventListener("touchmove",e),n&&this.currentTarget.removeEventListener("mousedown",n),e&&this.currentTarget.removeEventListener("mousemove",e),o&&this.currentTarget.removeEventListener("mouseup",o)}getCoordinates(n){if(n.type==="touchstart"||n.type==="mousedown"){if("touches"in n)return{x:n.touches[0].clientX,y:n.touches[0].clientY};if(n instanceof MouseEvent)return{x:n.clientX,y:n.clientY}}if(n.type==="touchend"||n.type==="mouseup"||n.type==="mousemove"||n.type==="touchmove"){if("touches"in n)return{x:n.changedTouches[0].clientX,y:n.changedTouches[0].clientY};if(n instanceof MouseEvent)return{x:n.clientX,y:n.clientY}}return{x:0,y:0}}}function Lt(t){const n=t;return`${n} ${n} 0px 0px`}function Vt(t,n){const e=Xt(t);jt(e),e.bottomSheetContainer.style.width=t.width;const o=document.createElement("div");o.innerHTML=t.content??"";const i=window.innerHeight;e.bottomSheetContainer.style.maxHeight=`${i}px`,e.bottomSheetContentWrapper.appendChild(o);const r=Kt({bottomSheetElements:e,bottomSheetProps:t,options:n});return{elements:e,eventHandlers:r}}function Xt(t){const n=N("dialog",F([E.Root,q.Dialog,t.rootClass]),E.Root);n.ariaLabel=t.ariaLabel;const e=N("section",F([E.Container,t.containerClass]),E.Container);t.containerBorderRadius&&(e.style.borderRadius=Lt(t.containerBorderRadius));const o=N("div",E.GapFiller,E.GapFiller),i=N("button",F([E.Handle,q.Button,t.shouldShowHandle?null:$.Hidden,t.handleClass]),E.Handle);i.setAttribute("type","button"),i.ariaLabel="bottom sheet close button";const r=N("span",F([E.HandleBar,t.shouldShowHandle?null:$.Hidden]),E.HandleBar),c=N("article",F([E.ContentWrapper,t.contentWrapperClass]),E.ContentWrapper),l=N("div",F([E.Backdrop,t.backdropClass,$.Hidden]),E.Backdrop);return t.backdropColor&&(l.style.backgroundColor=t.backdropColor),t.backDropTransition&&(l.style.transition=t.backDropTransition),{bottomSheetRoot:n,bottomSheetBackdrop:l,bottomSheetContainer:e,bottomSheetHandle:i,bottomSheetHandleBar:r,bottomSheetContentWrapper:c,bottomSheetContainerGapFiller:o}}function jt({bottomSheetRoot:t,bottomSheetContainer:n,bottomSheetHandle:e,bottomSheetHandleBar:o,bottomSheetContentWrapper:i,bottomSheetContainerGapFiller:r}){t.appendChild(n),e.appendChild(o),n.appendChild(e),n.appendChild(i),n.appendChild(r)}function Kt({bottomSheetElements:t,bottomSheetProps:n,options:e}){const{bottomSheetRoot:o,bottomSheetContainer:i,bottomSheetHandle:r,bottomSheetContainerGapFiller:c,bottomSheetContentWrapper:l,bottomSheetBackdrop:a}=t,{animationFrame:T}=e,f=new G(r),d=new G(l),b=new G(c),A=n.dragTriggers.reduce((p,B)=>{const Y=o.querySelectorAll(B);if(!Y.length)return p;const K=Array.from(Y).map(u=>u instanceof HTMLElement?new G(u):null).filter(u=>!!u);return[...p,...K]},[]),s=new G(window),C=Rt(s,i,n,e.draggingState),H=Ut(s,i,n,e.draggingState,T),y=Gt(s,i,n,e.draggingState,T,e.onClose,e.bottomSheetState);function D(p){p.target instanceof Element&&!o.contains(p.target)&&e.onClose()}function O(p){Ft(e.draggingState,p.target,t.bottomSheetContentWrapper)}function _(){n.draggable&&(f.addEventListeners({onStart:O}),A.forEach(p=>{p.addEventListeners({onStart:O,onStartOptions:{eventPhase:x.Target}})})),n.draggable&&n.backgroundDraggable&&(d.addEventListeners({onStart:O,onStartOptions:{eventPhase:x.Target}}),b.addEventListeners({onStart:O})),n.draggable&&s.addEventListeners({onStart:C,onMove:H,onEnd:y}),n.draggable&&window.document.addEventListener("keyup",p=>{p.key==="Escape"&&e.onClose()}),r.addEventListener("keyup",p=>{if(p.key==="ArrowUp"){e.moveUp();return}if(p.key==="ArrowDown"){e.moveDown();return}if(p.shiftKey&&p.key==="Tab"){const B=et(t.bottomSheetContentWrapper);Nt(B)}})}function X(){n.shouldCloseOnOutsideClick?a.addEventListener("click",D):a.style.pointerEvents="none"}function nt(){a.removeEventListener("click",D)}function et(p){let B=[...Array.from(p.childNodes).reverse()];for(;B.length;){const Y=B.shift();if(Mt(Y))return Y;Y&&(B=[...B,...Array.from(Y.childNodes).reverse()])}return null}function j(){f.removeEventListeners({onStart:O}),d.removeEventListeners({onStart:O}),b.removeEventListeners({onStart:O}),A.forEach(p=>{p.removeEventListeners({onStart:O})}),s.removeEventListeners({onStart:C,onMove:H,onEnd:y})}return{attachEventListeners:_,clearEventListeners:j,attacheOnOpenEventListeners:X,clearOnOpenEventListeners:nt}}class zt{constructor(){U(this,"animationId");U(this,"isInProgress");U(this,"startedAt");this.animationId=null,this.isInProgress=!1,this.startedAt=null}start(n,e,o=!1){this.isInProgress=!0;const i=r=>{this.startedAt||(this.startedAt=r);const c=r-this.startedAt,a=e===0?1:Q(c/e,2),T=a>=1&&!o;n(a),T?this.stop():this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}stop(){this.isInProgress=!1,this.startedAt=null,k(this.animationId)&&cancelAnimationFrame(this.animationId)}}function qt(t){const{startY:n,endY:e,bottomSheetContainer:o,animationFrame:i,onEnd:r,animationTimingFunction:c,animationDuration:l}=t,a=vt(n,e);i.stop();let T=!1;i.start(f=>{Z(o,{y:n+a*c(f)}),!T&&f>=1&&(r==null||r(),T=!0)},l)}const ct=(t,n)=>e=>{qt({...e,animationTimingFunction:t,animationDuration:n})},P={TOP:"top",MIDDLE:"middle",CONTENT_HEIGHT:"content-height",CLOSED:"closed"};function Jt(t){return!(!k(t)||t>1||t<0)}function Qt(t,n){const e={set(o,i,r,c){return n(i,r),Reflect.set(o,i,r,c)}};return new Proxy(t,e)}function Zt(...t){console.error(t)}const M={EASE:"ease",EASE_IN:"ease-in",EASE_OUT:"ease-out",EASE_IN_OUT:"ease-in-out",SPRING:"spring"};function At(t){for(const n of Object.values(M))if(n===t)return!0;return!1}function ut(t){return!!(t instanceof Object&&"p1x"in t&&"p1y"in t&&"p2x"in t&&"p2y"in t&&k(t.p1x)&&k(t.p1y)&&k(t.p2x)&&k(t.p2y))}function R(t,n,e,o){return function(a){return l(r(a))};function r(a){let T=0,f=1,d=a,b;if(a===0||a===1)return a;for(;T<f;){if(b=c(d),Math.abs(b-a)<.001)return d;a>b?T=d:f=d,d=(f+T)/2}return d}function c(a){return 3*t*a*Math.pow(1-a,2)+3*e*Math.pow(a,2)*(1-a)+Math.pow(a,3)}function l(a){return 3*n*a*Math.pow(1-a,2)+3*o*Math.pow(a,2)*(1-a)+Math.pow(a,3)}}const Tt=R(.25,.1,.25,1),tn=R(.42,0,1,1),Dt=R(.42,0,.58,1),nn=R(.4,.1,.6,1),en=R(.45,1.5,.55,1);function rn(t){switch(t){case M.EASE:return Tt;case M.EASE_IN:return tn;case M.EASE_OUT:return Dt;case M.EASE_IN_OUT:return nn;case M.SPRING:return en;default:return Tt}}function bt(t){return typeof t=="boolean"}const St={ariaLabel:"Bottom sheet",content:"",defaultPosition:P.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 on(t){const n={...St},e=Object.entries(t).reduce((i,r)=>{const[c,l]=r;return st(l)&&(i[c]=l),i},{});return{...n,...e}}function lt(t){if(ut(t)){const{p1x:n,p1y:e,p2x:o,p2y:i}=t;return R(n,e,o,i)}return At(t)?rn(t):Dt}function sn(t,n,e){function o(i,r){switch(i){case"content":w(r)&&(t.bottomSheetContentWrapper.innerHTML=r);break;case"width":w(r)&&(t.bottomSheetContainer.style.width=r);break;case"shouldShowHandle":bt(r)||z(t.bottomSheetHandle,!1);break;case"shouldShowBackdrop":bt(r)||z(t.bottomSheetBackdrop,!1);break;case"containerBorderRadius":w(r)&&(t.bottomSheetContainer.style.borderRadius=Lt(r));break;case"backdropColor":w(r)&&(t.bottomSheetBackdrop.style.backgroundColor=r);break;case"backDropTransition":w(r)&&(t.bottomSheetBackdrop.style.transition=r);break;case"rootClass":if(!w(r))return;W(t.bottomSheetRoot,e.rootClass,r);break;case"containerClass":if(!w(r))return;W(t.bottomSheetContainer,e.containerClass,r);break;case"handleClass":if(!w(r))return;W(t.bottomSheetHandle,e.handleClass,r);break;case"contentWrapperClass":if(!w(r))return;W(t.bottomSheetContentWrapper,e.contentWrapperClass,r);break;case"backdropClass":if(!w(r))return;W(t.bottomSheetBackdrop,e.backdropClass,r);break;case"draggingAnimationTimings":if(ut(r)){const c=lt(r),l=ct(c,e.draggingAnimationDuration);n.translateContainer=l}break;case"draggingAnimationDuration":if(k(r)){const c=lt(e.draggingAnimationTimings),l=ct(c,r);n.translateContainer=l}break}}return o}function an(t){const n=on(t),e=lt(t.draggingAnimationTimings),i={isMounted:!1,translateContainer:ct(e,n.draggingAnimationDuration)},r={startY:null,containerStartTranslate:{x:0,y:0},isDragging:!1,originalDocumentOverflowY:null,originalDocumentOverscrollBehavior:null};function c(){r.originalDocumentOverflowY&&r.originalDocumentOverflowY!=="hidden"&&(document.body.style.overflowY=r.originalDocumentOverflowY),r.originalDocumentOverscrollBehavior&&(document.body.style.position=r.originalDocumentOverscrollBehavior)}const l=new zt,a={animationFrame:l,onClose:D,bottomSheetState:i,draggingState:r,snapTo:K,moveUp:B,moveDown:Y},{elements:T,eventHandlers:f}=Vt(n,a),d=Qt(n,sn(T,i,n)),{bottomSheetBackdrop:b,bottomSheetRoot:A,bottomSheetContainer:s}=T,C=u=>{const g=u??window.document.body;g.appendChild(A),g.appendChild(b);const h=window.innerHeight;Z(s,{y:h}),f.attachEventListeners(),i.isMounted=!0},H=()=>{f.clearEventListeners(),Object.values(T).forEach(u=>{u.remove()}),c(),i.isMounted=!1},y=()=>{var S;if(O()||Zt('Bottom Sheet is not mounted yet. call the "mount" method first.'),(S=t.beforeOpen)==null||S.call(t),_())return;rt(b,!0),d.shouldShowBackdrop||V(b,"transparent"),rt([s],!0),Z(s,{y:s.clientHeight});const g=window.innerHeight,h=gt(g,s.clientHeight,d.marginTop,d.defaultPosition),m=I(s).y;i.translateContainer({startY:m,endY:h,animationFrame:l,bottomSheetContainer:s,onEnd:t.afterOpen});const v=document.body.style.overflowY;r.originalDocumentOverflowY=v||"initial";const L=document.body.style.overscrollBehavior;r.originalDocumentOverscrollBehavior=L||"initial",document.body.style.overflow="hidden",document.body.style.overscrollBehavior="contain",T.bottomSheetHandle.focus(),f.attacheOnOpenEventListeners()};function D(){var h;if(X())return;(h=t.beforeClose)==null||h.call(t);const u=I(s).y,g=s.clientHeight;i.translateContainer({startY:u,endY:g,animationFrame:l,bottomSheetContainer:s,onEnd:()=>{var m;(m=t.afterClose)==null||m.call(t),rt([b,s],!1),f.clearOnOpenEventListeners()}}),c()}function O(){return i.isMounted}function _(){const u=I(s).y,g=window.innerHeight,h=s.clientHeight>=g?g:s.clientHeight;return u<=h}function X(){return!_()}function nt(){const u=I(s).y,g=s.clientHeight,h=window.innerHeight;if(u<=5&&u>=-5)return P.CONTENT_HEIGHT;const m=g-u;if(m===h/2)return P.MIDDLE;const v=h-d.marginTop,L=10;return m<=v+L&&m>=v-L?P.TOP:P.CLOSED}function et(){return s.clientHeight}function j(u){if(!_())return;const g=I(s).y,m=s.clientHeight-g,v=window.innerHeight-u,L=xt(m,v),S=J(m,v);i.translateContainer({startY:g,endY:g+(L.isUp?-S:S),animationFrame:l,bottomSheetContainer:s})}function p(u,{viewportHeight:g,visibleHeight:h}){let m=null;for(const v of u){const L=v*g,S=J(h,L);(m===null||S<m)&&(m=S)}return{minOffset:m}}function B(){const u=[...d.snapPoints].reverse(),g=I(s).y,h=s.clientHeight,m=h-g;if(!d.expandable&&m>=h)return;const v=window.innerHeight,L=ht("above",{visibleHeight:m,viewportHeight:v},u),{minOffset:S}=p(L,{visibleHeight:m,viewportHeight:v});if(S===null&&m<v-d.marginTop){i.translateContainer({startY:g,endY:gt(v,h,d.marginTop,"top"),animationFrame:l,bottomSheetContainer:s});return}k(S)&&i.translateContainer({startY:g,endY:g-S,animationFrame:l,bottomSheetContainer:s})}function Y(){const u=I(s).y,h=s.clientHeight-u;if(h<1)return;const m=window.innerHeight,v=ht("below",{visibleHeight:h,viewportHeight:m},d.snapPoints),{minOffset:L}=p(v,{visibleHeight:h,viewportHeight:m});k(L)&&i.translateContainer({startY:u,endY:u+L,animationFrame:l,bottomSheetContainer:s})}function K(u){const g=window.innerHeight;if(!Jt(u))return;const h=Q(g*u,2);j(h)}return{props:d,elements:T,mount:C,unmount:H,open:y,close:D,getIsMounted:O,getIsOpen:_,getIsClosed:X,getPosition:nt,getHeight:et,moveTo:j,snapTo:K}}function cn(){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:()=>P.CLOSED,moveTo:()=>{},snapTo:()=>{},props:{content:""}}}exports.BOTTOM_SHEET_DEFAULT_PROPS=St;exports.BOTTOM_SHEET_POSITION=P;exports.BOTTOM_SHEET_SELECTORS=Pt;exports.COMMON_ANIMATION_KEYS=M;exports.ClassNames=E;exports.EventPhase=x;exports.ResetClassNames=q;exports.UtilClassNames=$;exports.createBottomSheet=an;exports.createPlaceholderBottomSheet=cn;exports.eventPhaseToEnum=at;exports.isAnimationTimingPoints=ut;exports.isCommonAnimationTimingsKey=At;
|