react-panel-layout 0.7.0 → 0.7.1

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.
Files changed (44) hide show
  1. package/dist/{FloatingWindow-Bw2djgpz.js → FloatingWindow-CE-WzkNv.js} +2 -2
  2. package/dist/{FloatingWindow-Bw2djgpz.js.map → FloatingWindow-CE-WzkNv.js.map} +1 -1
  3. package/dist/{FloatingWindow-Cvyokf0m.cjs → FloatingWindow-DpFpmX1f.cjs} +2 -2
  4. package/dist/{FloatingWindow-Cvyokf0m.cjs.map → FloatingWindow-DpFpmX1f.cjs.map} +1 -1
  5. package/dist/{GridLayout-DNOClFzz.cjs → GridLayout-EwKszYBy.cjs} +2 -2
  6. package/dist/{GridLayout-DNOClFzz.cjs.map → GridLayout-EwKszYBy.cjs.map} +1 -1
  7. package/dist/{GridLayout-B4aCqSyd.js → GridLayout-kiWdpMLQ.js} +2 -2
  8. package/dist/{GridLayout-B4aCqSyd.js.map → GridLayout-kiWdpMLQ.js.map} +1 -1
  9. package/dist/{PanelSystem-B8Igvnb2.cjs → PanelSystem-Dmy5YI_6.cjs} +2 -2
  10. package/dist/{PanelSystem-B8Igvnb2.cjs.map → PanelSystem-Dmy5YI_6.cjs.map} +1 -1
  11. package/dist/{PanelSystem-DDUSFjXD.js → PanelSystem-DrYsYwuV.js} +3 -3
  12. package/dist/{PanelSystem-DDUSFjXD.js.map → PanelSystem-DrYsYwuV.js.map} +1 -1
  13. package/dist/config.cjs +1 -1
  14. package/dist/config.js +2 -2
  15. package/dist/dialog/index.d.ts +1 -1
  16. package/dist/grid.cjs +1 -1
  17. package/dist/grid.js +2 -2
  18. package/dist/index.cjs +1 -1
  19. package/dist/index.js +4 -4
  20. package/dist/modules/dialog/DialogContainer.d.ts +22 -2
  21. package/dist/modules/dialog/Modal.d.ts +23 -2
  22. package/dist/modules/dialog/SwipeDialogContainer.d.ts +6 -2
  23. package/dist/modules/dialog/types.d.ts +12 -0
  24. package/dist/panels.cjs +1 -1
  25. package/dist/panels.js +1 -1
  26. package/dist/stack.cjs +1 -1
  27. package/dist/stack.js +1 -1
  28. package/dist/{useAnimationFrame-Bg4e-H8O.js → useAnimationFrame-CRuFlk5t.js} +16 -16
  29. package/dist/useAnimationFrame-CRuFlk5t.js.map +1 -0
  30. package/dist/useAnimationFrame-XRpDXkwV.cjs +2 -0
  31. package/dist/useAnimationFrame-XRpDXkwV.cjs.map +1 -0
  32. package/dist/window.cjs +1 -1
  33. package/dist/window.js +1 -1
  34. package/package.json +1 -1
  35. package/src/dialog/index.ts +2 -0
  36. package/src/hooks/gesture/useSwipeInput.spec.ts +69 -0
  37. package/src/hooks/gesture/useSwipeInput.ts +2 -0
  38. package/src/modules/dialog/DialogContainer.tsx +39 -5
  39. package/src/modules/dialog/Modal.tsx +46 -4
  40. package/src/modules/dialog/SwipeDialogContainer.tsx +12 -2
  41. package/src/modules/dialog/types.ts +14 -0
  42. package/dist/useAnimationFrame-BZ6D2lMq.cjs +0 -2
  43. package/dist/useAnimationFrame-BZ6D2lMq.cjs.map +0 -1
  44. package/dist/useAnimationFrame-Bg4e-H8O.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";const h=require("react/jsx-runtime"),xe=require("react"),le=require("react-dom"),_=require("./FloatingPanelFrame-CEmXDvUA.cjs"),U=require("./styles-qf6ptVLD.cjs"),$=require("./useAnimationFrame-BZ6D2lMq.cjs"),Re=require("./useContentCache-DqXtLrLs.cjs");function de(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const s=de(xe),Te=de(le),Ae="data-swipe-safe-zone",Me=({children:e,className:t,style:n})=>h.jsx("div",{className:t,style:n,"data-swipe-safe-zone":"true",children:e});function _e(e,t){let n=e;for(;n&&n!==t;){if(n.hasAttribute(Ae))return!0;n=n.parentElement}return!1}function Le(e){switch(e){case"left":case"right":return"x";case"top":case"bottom":return"y"}}function pe(e){switch(e){case"left":return-1;case"right":return 1;case"top":return-1;case"bottom":return 1}}function Fe(e){return pe(e)*-1}const ke=.3,Ie=.5;function Ne(e,t){return t==="x"?e.clientWidth:e.clientHeight}function We(e,t,n){return n==="x"?t.x-e.x:t.y-e.y}const je={idle:"idle",ended:"ended"};function ze(e){return je[e]??"operating"}function He(e,t,n){const r=e*n;return t==="x"?{x:r,y:0}:{x:0,y:r}}function Be(e,t,n){return t==="x"?Math.max(0,n*e.x):Math.max(0,n*e.y)}function $e(e,t){return e?!t:!1}function Ge(e,t){return e?t:!1}function Ue(e,t){return e?!t:!1}function Ve(e,t){return e==="idle"?!1:t}function Ye(e,t,n){if(!e||!t)return 0;const r=Math.max(1,t.timestamp-e.timestamp);return n/r}function Ze(e){const{edgeContainerRef:t,drawerContentRef:n,direction:r,isOpen:o,onSwipeOpen:i,onSwipeClose:a,enableEdgeSwipeOpen:c=!0,enableSwipeClose:u=!0,edgeWidth:l=20,dismissThreshold:d=ke}=e,p=Le(r),w=pe(r),O=Fe(r),C=s.useRef(0);s.useLayoutEffect(()=>{const m=n.current;if(!m)return;const y=()=>{C.current=Ne(m,p)};y();const T=new ResizeObserver(y);return T.observe(m),()=>T.disconnect()},[n,p]);const D=s.useCallback(m=>{m.direction===O&&i()},[O,i]),{isEdgeGesture:E,state:f,containerProps:g}=$.useEdgeSwipeInput({containerRef:t,edge:r,edgeWidth:l,enabled:$e(c,o),onSwipeEnd:D}),{containerProps:G}=$.useNativeGestureGuard({containerRef:t,active:E,preventEdgeBack:!0,preventOverscroll:!0,edgeWidth:l}),{state:b,onPointerDown:I}=$.usePointerTracking({enabled:Ge(u,o)}),[R,x]=s.useState("idle"),M=s.useRef(0),W=s.useCallback(m=>{if(!u||!o)return;const y=n.current;if(!y)return;const T=m.target;_e(T,y)||$.isScrollableInDirection(T,y,p,w)||I(m)},[u,o,n,p,w,I]),P=s.useMemo(()=>{if(!b.isDown||!b.start||!b.current)return M.current;const y=We(b.start,b.current,p)*w;return Math.max(0,y)},[b.isDown,b.start,b.current,p,w]);s.useEffect(()=>{b.isDown&&b.current&&(M.current=P)},[b.isDown,b.current,P]),s.useEffect(()=>{b.isDown&&R==="idle"&&x("operating")},[b.isDown,R]),s.useEffect(()=>{if(!b.isDown&&R==="operating"){const m=M.current;if(m>1){x("ended");const T=C.current;if(T>0){const A=m/T,N=Ye(b.start,b.current,m);(A>=d||N>=Ie)&&a()}}else x("idle"),M.current=0}},[b.isDown,R,d,a,b.start,b.current]),s.useEffect(()=>{R==="ended"&&queueMicrotask(()=>{x("idle"),M.current=0})},[R]),s.useEffect(()=>{o||(x("idle"),M.current=0)},[o]);const v=Ue(E,o),L=Ve(R,o),j=s.useMemo(()=>v?Be(f.displacement,p,O):L?P:0,[v,L,p,f.displacement,P,O]),F=s.useMemo(()=>{const m=C.current;return m<=0?0:Math.min(j/m,1)},[j]),z=s.useMemo(()=>v?{phase:ze(f.phase),displacement:f.displacement,velocity:f.velocity}:L?{phase:R,displacement:He(w,p,P),velocity:{x:0,y:0}}:$.IDLE_CONTINUOUS_OPERATION_STATE,[v,L,f,R,P,p,w]),H=s.useMemo(()=>$.mergeGestureContainerProps(g,G),[g,G]),S=s.useMemo(()=>({onPointerDown:W,style:{touchAction:"none",userSelect:"none",WebkitUserSelect:"none"}}),[W]);return{state:z,isOpening:v,isClosing:L,progress:F,displacement:j,edgeContainerProps:H,drawerContentProps:S}}const oe={position:"fixed",inset:0,background:U.COLOR_DRAWER_BACKDROP},ie={willChange:"transform"},qe={left:{top:0,bottom:0,left:0,transform:"translateX(-100%)"},right:{top:0,bottom:0,right:0,transform:"translateX(100%)"},top:{top:0,left:0,right:0,transform:"translateY(-100%)"},bottom:{bottom:0,left:0,right:0,transform:"translateY(100%)"}},Xe={left:"translateX(0)",right:"translateX(0)",top:"translateY(0)",bottom:"translateY(0)"};function Ke(e){return qe[e]}function Je(e){return Xe[e]}function Qe(e,t,n){if(e==="none")return;const r=t??U.DRAWER_TRANSITION_DURATION,o=n??U.DRAWER_TRANSITION_EASING;return`transform ${r} ${o}`}function et(e,t){if(e!=="none")return`opacity ${t??"220ms"} ease`}function q(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function tt(e){const{placement:t,inline:n,edgeWidth:r,zIndex:o}=e,i=n?"absolute":"fixed",a=o!==void 0?o-2:1e3;return nt(t,i,r,a)}function nt(e,t,n,r){const o={position:t,zIndex:r,background:"transparent",pointerEvents:"auto"};return e==="left"?{...o,top:0,bottom:0,left:0,width:n}:e==="right"?{...o,top:0,bottom:0,right:0,width:n}:e==="top"?{...o,top:0,left:0,right:0,height:n}:{...o,bottom:0,left:0,right:0,height:n}}const te=20,ne=.3,rt={enabled:!1,edgeSwipeOpen:!1,swipeClose:!1,edgeWidth:te,dismissThreshold:ne},ot={enabled:!0,edgeSwipeOpen:!0,swipeClose:!0,edgeWidth:te,dismissThreshold:ne};function it(e){return e===!0?ot:e===!1||e===void 0?rt:{enabled:!0,edgeSwipeOpen:e.edgeSwipeOpen??!0,swipeClose:e.swipeClose??!0,edgeWidth:e.edgeWidth??te,dismissThreshold:e.dismissThreshold??ne}}function st(e,t){return e||(t?t.left!==void 0?"left":t.right!==void 0?"right":t.top!==void 0?"top":t.bottom!==void 0?"bottom":"right":"right")}function at(e,t,n){return!e.enabled||!e.edgeSwipeOpen?!1:t?n:!0}function k(e,t){if(!t){const r=(()=>({type:e}));return Object.defineProperty(r,"type",{value:e,writable:!1,enumerable:!0}),r}const n=((...r)=>{const o=t(...r);return typeof o>"u"?{type:e}:{type:e,payload:o}});return Object.defineProperty(n,"type",{value:e,writable:!1,enumerable:!0}),n}const ct=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r];n[r]=((...i)=>{const a=o(...i);return t(a),a})}),n},fe=(e,t)=>{const n={};return Object.keys(t).forEach(r=>{const o=t[r];if(!o)return;const i=e[r];if(!i)throw new Error(`Missing action creator for key "${String(r)}"`);n[i.type]=o}),n},ut=100,lt=.3,dt=30,pt=300,ft=1;function mt(e,t,n){if(t<=0||n===null)return 0;const r=Math.min(1,Math.max(0,e/t));return n==="opening"?r:1-r}function wt(e,t,n){return n==="opening"?e>=ut:n==="closing"?(t>0?e/t:0)<lt:!1}const B={swipeStart:k("SWIPE_START",e=>({direction:e})),swipeUpdate:k("SWIPE_UPDATE",e=>({displacement:e})),swipeEnd:k("SWIPE_END"),animationFrame:k("ANIMATION_FRAME",e=>({easedProgress:e})),animationComplete:k("ANIMATION_COMPLETE"),buttonOpen:k("BUTTON_OPEN"),buttonClose:k("BUTTON_CLOSE"),syncOpenState:k("SYNC_OPEN_STATE",e=>({isOpen:e})),initialize:k("INITIALIZE",e=>({isOpen:e}))};function Q(e,t,n){return e?t.getOpenPosition(n):t.getClosedPosition(n)}function ee(e,t,n){const r=Q(e,t,n);return{phase:e?"open":"closed",targetOpen:e,position:r,isOperating:!1,swipeDirection:null,displacement:0,animation:null}}function gt(e){const t=fe(B,{swipeStart:(n,r,o)=>"payload"in r?{...n,isOperating:!0,swipeDirection:r.payload.direction,displacement:0,animation:null}:n,swipeUpdate:(n,r,o)=>{if(!("payload"in r)||!n.isOperating)return n;const i=mt(r.payload.displacement,o.drawerSize,n.swipeDirection),a=e.computePositionFromProgress(i,o);return{...n,displacement:r.payload.displacement,position:a}},swipeEnd:(n,r,o)=>{if(!n.isOperating)return n;const i=wt(n.displacement,o.drawerSize,n.swipeDirection),a=Q(i,e,o);if(e.shouldAnimate(n.position,a)){const c=i?"opening":"closing";return{...n,isOperating:!1,swipeDirection:null,displacement:0,targetOpen:i,phase:c,animation:{type:c,from:n.position,to:a}}}return{...n,isOperating:!1,swipeDirection:null,displacement:0,targetOpen:i,phase:i?"open":"closed",position:a,animation:null}},animationFrame:(n,r,o)=>{if(!("payload"in r)||!n.animation)return n;const i=e.interpolatePosition(n.animation.from,n.animation.to,r.payload.easedProgress);return{...n,position:i}},animationComplete:(n,r,o)=>{if(!n.animation)return n;const i=n.animation.type==="opening";return{...n,phase:i?"open":"closed",position:n.animation.to,animation:null}},buttonOpen:(n,r,o)=>{if(n.phase==="open"||n.phase==="opening"||n.isOperating)return n;const i=e.getOpenPosition(o),a=n.position;return e.shouldAnimate(a,i)?{...n,targetOpen:!0,phase:"opening",animation:{type:"opening",from:a,to:i}}:{...n,targetOpen:!0,phase:"open",position:i,animation:null}},buttonClose:(n,r,o)=>{if(n.phase==="closed"||n.phase==="closing"||n.isOperating)return n;const i=e.getClosedPosition(o),a=n.position;return e.shouldAnimate(a,i)?{...n,targetOpen:!1,phase:"closing",animation:{type:"closing",from:a,to:i}}:{...n,targetOpen:!1,phase:"closed",position:i,animation:null}},syncOpenState:(n,r,o)=>{if(!("payload"in r))return n;const{isOpen:i}=r.payload;if(n.targetOpen===i&&!n.isOperating&&!n.animation)return n;if(n.isOperating)return{...n,targetOpen:i};if(n.animation&&n.animation.type==="opening"===i)return{...n,targetOpen:i};if((n.phase==="open"||n.phase==="opening")===i)return{...n,targetOpen:i};const c=Q(i,e,o),u=n.position;if(e.shouldAnimate(u,c)){const l=i?"opening":"closing";return{...n,targetOpen:i,phase:l,animation:{type:l,from:u,to:c}}}return{...n,targetOpen:i,phase:i?"open":"closed",position:c,animation:null}},initialize:(n,r,o)=>"payload"in r?ee(r.payload.isOpen,e,o):n});return function(r,o,i){const a=t[o.type];return a?a(r,o,i):r}}const ht={left:{axis:"X",sign:1},right:{axis:"X",sign:-1},top:{axis:"Y",sign:1},bottom:{axis:"Y",sign:-1}};function Y(e){return ht[e]}const K={position:"relative",zIndex:"1",background:"#fff"};function se(e){e.style.position="",e.style.zIndex="",e.style.background=""}function St(){document.body.style.overflow="hidden"}function J(){document.body.style.overflow=""}function me(e,t){return e?t?.current??null:document.getElementById("root")??document.body.firstElementChild}function bt(e){e.style.visibility="visible",e.style.pointerEvents="auto"}function Et(e){e.style.visibility="hidden",e.style.pointerEvents="none"}function Pt(e){e.style.visibility="",e.style.pointerEvents=""}function yt(e,t=K.background){e.style.position=K.position,e.style.zIndex=K.zIndex,e.style.background=t}const Ot={getClosedPosition(e){return this.computePositionFromProgress(0,e)},getOpenPosition(e){return this.computePositionFromProgress(1,e)},computePositionFromProgress(e,t){const{sign:n}=Y(t.placement),o=t.drawerSize*(dt/100)*(1-e),i=n>0?-o:o,a=n*t.drawerSize*e;return{drawerPx:i,contentPx:a}},interpolatePosition(e,t,n){return{drawerPx:e.drawerPx+(t.drawerPx-e.drawerPx)*n,contentPx:e.contentPx+(t.contentPx-e.contentPx)*n}},shouldAnimate(e,t){return Math.abs(e.contentPx-t.contentPx)>ft},applyToDOM(e,t,n){const{drawer:r,content:o}=t,{axis:i}=Y(n.placement);r&&(r.style.transition="none",r.style.transform=`translate${i}(${e.drawerPx}px)`),o&&(yt(o,n.contentBackground),o.style.transition="none",o.style.transform=`translate${i}(${e.contentPx}px)`)},clearFromDOM(e){const{drawer:t,content:n}=e;t&&(t.style.transform="",t.style.transition=""),n&&(n.style.transform="",n.style.transition="",se(n))},onOpeningStart(e){e.drawer&&bt(e.drawer)},onClosingComplete(e){const{drawer:t,content:n}=e;t&&(Et(t),t.style.transform="",t.style.transition=""),n&&(n.style.transform="",n.style.transition="",se(n))}},Ct=1,Dt={getClosedPosition(e){const{sign:t}=Y(e.placement);return{drawerPx:-t*e.drawerSize,backdropOpacity:0}},getOpenPosition(){return{drawerPx:0,backdropOpacity:1}},computePositionFromProgress(e,t){const{sign:n}=Y(t.placement);return{drawerPx:-n*t.drawerSize*(1-e),backdropOpacity:e}},interpolatePosition(e,t,n){return{drawerPx:e.drawerPx+(t.drawerPx-e.drawerPx)*n,backdropOpacity:e.backdropOpacity+(t.backdropOpacity-e.backdropOpacity)*n}},shouldAnimate(e,t){return Math.abs(e.drawerPx-t.drawerPx)>Ct},applyToDOM(e,t,n){const{drawer:r,backdrop:o}=t,{axis:i}=Y(n.placement);r&&(r.style.transition="none",r.style.transform=`translate${i}(${e.drawerPx}px)`),o&&(o.style.opacity=String(e.backdropOpacity),o.style.pointerEvents=e.backdropOpacity>0?"auto":"none")},clearFromDOM(e){const{drawer:t,backdrop:n}=e;t&&(t.style.transform="",t.style.transition=""),n&&(n.style.opacity="",n.style.pointerEvents="")},onOpeningStart(){},onClosingComplete(e,t){const{drawer:n,backdrop:r}=e,o=vt(t);n&&(n.style.transform=o,n.style.transition=""),r&&(r.style.opacity="0",r.style.pointerEvents="none")}};function vt(e){switch(e.placement){case"left":return"translateX(-100%)";case"right":return"translateX(100%)";case"top":return"translateY(-100%)";case"bottom":return"translateY(100%)"}}function xt(e){return e==="reveal"?Ot:Dt}function we(e){const{mode:t,drawerRef:n,contentRef:r,backdropRef:o,placement:i,drawerSize:a,isOpen:c,swipeState:u,displacement:l,isOpening:d,isClosing:p,enabled:w,inline:O=!1,gridRef:C,contentBackground:D="#fff"}=e,E=u.phase==="operating",f=xt(t),g=s.useMemo(()=>({placement:i,drawerSize:a,contentBackground:D}),[i,a,D]),G=s.useMemo(()=>gt(f),[f]),b=s.useRef(ee(c,f,g)),[I,R]=s.useState(c?"open":"closed"),x=s.useRef({isOperating:!1,isOpening:!1,isClosing:!1,isOpen:c,enabled:!1}),M=()=>t!=="reveal"?null:r?.current??me(O,C),W=()=>t!=="overlay"?null:o?.current??null,P=s.useCallback(()=>({drawer:n.current,content:M(),backdrop:W()}),[t,n,r,o,O,C]),v=s.useCallback(S=>{const m=G(b.current,S,g);return b.current=m,R(m.phase),m},[G,g]),L=s.useCallback(({easedProgress:S})=>{const m=b.current;if(!m.animation)return;const y=f.interpolatePosition(m.animation.from,m.animation.to,S);b.current={...m,position:y};const T=P();f.applyToDOM(y,T,g)},[f,P,g]),j=s.useCallback(()=>{const S=v(B.animationComplete()),m=P();S.phase==="closed"&&f.onClosingComplete?.(m,g)},[v,f,P,g]),{isAnimating:F,start:z,cancel:H}=$.useAnimationFrame({duration:pt,easing:$.easings.easeOutExpo,onFrame:L,onComplete:j});return s.useLayoutEffect(()=>{if(!w){x.current.enabled=!1;return}if(x.current.enabled)return;x.current.enabled=!0,b.current=ee(c,f,g),R(c?"open":"closed");const S=P();c?(f.onOpeningStart?.(S,g),f.applyToDOM(b.current.position,S,g)):f.onClosingComplete?.(S,g)},[w,c,f,g,P]),s.useLayoutEffect(()=>{if(!w)return;const S=x.current,m=S.isOperating,y=S.isOpening,T=S.isClosing;if(S.isOperating=E,S.isOpening=d,S.isClosing=p,!m&&E){H();const A=d?"opening":p?"closing":null;A&&v(B.swipeStart(A));return}if(m&&!E){const A=v(B.swipeEnd()),N=P();A.animation?(f.onOpeningStart?.(N,g),z()):A.phase==="open"?(f.onOpeningStart?.(N,g),f.applyToDOM(A.position,N,g)):A.phase==="closed"&&f.onClosingComplete?.(N,g);return}if(E){const A=d?"opening":p?"closing":null;A!==(y?"opening":T?"closing":null)&&A&&v(B.swipeStart(A))}},[w,E,d,p,v,H,z,f,g,P]),s.useLayoutEffect(()=>{if(!w||!E||!d&&!p)return;const S=v(B.swipeUpdate(l)),m=P();f.onOpeningStart?.(m,g),f.applyToDOM(S.position,m,g)},[w,E,d,p,l,v,f,g,P]),s.useLayoutEffect(()=>{if(!w)return;const S=x.current;if(S.isOpen===c)return;if(S.isOpen=c,E){v(B.syncOpenState(c));return}if(F&&b.current.animation?.type==="opening"===c)return;const m=v(B.syncOpenState(c)),y=P();m.animation?(f.onOpeningStart?.(y,g),f.applyToDOM(m.animation.from,y,g),z()):F||(m.phase==="open"?(f.onOpeningStart?.(y,g),f.applyToDOM(m.position,y,g)):m.phase==="closed"&&f.onClosingComplete?.(y,g))},[w,c,E,F,v,z,f,g,P]),s.useLayoutEffect(()=>{if(w||!x.current.enabled)return;const S=P();f.clearFromDOM(S,g),S.drawer&&Pt(S.drawer)},[w,f,g,P]),s.useLayoutEffect(()=>{if(!w||t!=="reveal"){t==="reveal"&&J();return}return(c||E?!0:F)?St():J(),()=>{J()}},[w,t,c,E,F]),s.useLayoutEffect(()=>{if(!(!w||t!=="reveal"))return()=>{const S=P();S.content&&f.clearFromDOM({drawer:null,content:S.content,backdrop:null},g)}},[w,t,f,g,P]),{phase:I,isAnimating:F}}function Rt(e){const{drawerRef:t,backdropRef:n,placement:r,swipeState:o,displacement:i,isOpening:a,isClosing:c,isOpen:u,enabled:l}=e,d=s.useRef(0);s.useLayoutEffect(()=>{const p=t.current;if(p){const w=r==="left"||r==="right";d.current=w?p.clientWidth:p.clientHeight}},[t,r]),we({mode:"overlay",drawerRef:t,backdropRef:n,placement:r,drawerSize:d.current,isOpen:u,swipeState:o,displacement:i,isOpening:a,isClosing:c,enabled:l})}const Tt={activeRevealDrawer:null,setRevealState:()=>{},gridRef:null,setGridRef:()=>{}},ge=s.createContext(Tt),At=({children:e})=>{const[t,n]=s.useState(null),[r,o]=s.useState(null),i=s.useCallback(u=>{n(u)},[]),a=s.useCallback(u=>{o(u)},[]),c=s.useMemo(()=>({activeRevealDrawer:t,setRevealState:i,gridRef:r,setGridRef:a}),[t,i,r,a]);return h.jsx(ge.Provider,{value:c,children:e})};function he(){return s.useContext(ge)}function Z(e){return e==="reveal"}function Mt(e){const{drawerRef:t,placement:n,drawerSize:r,isOpen:o,swipeState:i,displacement:a,isOpening:c,isClosing:u,enabled:l,inline:d,gridRef:p,contentBackground:w="#fff"}=e,O=s.useRef(null);return s.useLayoutEffect(()=>{O.current=me(d,p)},[d,p]),we({mode:"reveal",drawerRef:t,contentRef:O,placement:n,drawerSize:r,isOpen:o,swipeState:i,displacement:a,isOpening:c,isClosing:u,enabled:l,inline:d,gridRef:p,contentBackground:w})}const _t=({chrome:e,frameStyle:t,header:n,dismissible:r,onClose:o,children:i})=>e?h.jsxs(_.FloatingPanelFrame,{style:t,children:[h.jsx(Nt,{header:n,dismissible:r,onClose:o}),h.jsx(_.FloatingPanelContent,{style:{padding:U.DRAWER_CONTENT_PADDING,flex:1,display:"flex",flexDirection:"column"},children:i})]}):h.jsx(h.Fragment,{children:i});function Lt(e,t){return e?t:!1}function Ft(e,t){return e?h.jsx(_.FloatingPanelCloseButton,{onClick:t,"aria-label":"Close drawer",style:{marginLeft:"auto"}}):null}function kt(e,t,n,r,o){return e?h.jsx("div",{ref:t,style:n,onPointerDown:r,"data-drawer-edge-zone":o}):null}function It(e,t,n){return e==="left"||e==="right"?typeof t=="number"?t:0:typeof n=="number"?n:0}const Nt=({header:e,dismissible:t,onClose:n})=>{if(!e)return null;const r=e.showCloseButton??!0,o=Lt(t,r);return h.jsxs(_.FloatingPanelHeader,{style:{padding:`${U.DRAWER_HEADER_PADDING_Y} ${U.DRAWER_HEADER_PADDING_X}`,gap:U.DRAWER_HEADER_GAP},children:[h.jsx(_.FloatingPanelTitle,{children:e.title}),Ft(o,n)]})};function Wt(e,t,n,r,o){const i=Z(r.animationMode);return s.useMemo(()=>{const a=r.inline?"absolute":"fixed",c=Ke(e);if(i)return{...ie,position:a,top:c.top,bottom:c.bottom,left:c.left,right:c.right,zIndex:0,visibility:"hidden",pointerEvents:"none",width:q(o.width),height:q(o.height)};const u=n?"none":r.transitionMode,l=Qe(u,r.transitionDuration,r.transitionEasing),d=t?Je(e):c.transform;return{...ie,position:a,...c,transform:d,transition:l,zIndex:o.zIndex,width:q(o.width),height:q(o.height)}},[e,t,n,r,o,i])}function jt(e,t,n,r,o){const i=Z(n.animationMode);return s.useMemo(()=>{if(i)return{display:"none"};const a=n.inline?"absolute":"fixed";if(o)return{...oe,position:a,opacity:0,pointerEvents:"none",zIndex:r!==void 0?r-1:void 0};const c=t?"none":n.transitionMode,u=et(c,n.transitionDuration);return{...oe,position:a,opacity:e?1:0,pointerEvents:e?"auto":"none",transition:u,zIndex:r!==void 0?r-1:void 0}},[e,t,n,r,i,o])}function zt(e){return s.useMemo(()=>{const t={borderRadius:0};return(e==="left"||e==="right")&&(t.height="100%"),t},[e])}const Se=({id:e,config:t,isOpen:n,onClose:r,onOpen:o,children:i,zIndex:a,width:c,height:u,position:l})=>{const{dismissible:d=!0,header:p,chrome:w=!0,inline:O=!1}=t,C=it(t.swipeGestures),D=st(t.anchor,l),E=s.useRef(null),f=s.useRef(null),g=s.useRef(null),G=s.useCallback(()=>{o?.(),t.onStateChange?.(!0)},[o,t]),b=s.useCallback(()=>{r()},[r]),{state:I,displacement:R,edgeContainerProps:x,drawerContentProps:M,isOpening:W,isClosing:P}=Ze({edgeContainerRef:g,drawerContentRef:E,direction:D,isOpen:n,onSwipeOpen:G,onSwipeClose:b,enableEdgeSwipeOpen:C.edgeSwipeOpen,enableSwipeClose:C.swipeClose,edgeWidth:C.edgeWidth,dismissThreshold:C.dismissThreshold}),v=I.phase==="operating"||I.phase==="ended",L=Z(t.animationMode),j=C.enabled?!L:!1;Rt({drawerRef:E,backdropRef:f,placement:D,swipeState:I,displacement:R,isOpening:W,isClosing:P,isOpen:n,enabled:j});const F=It(D,c,u),{gridRef:z}=he();Mt({drawerRef:E,placement:D,drawerSize:F,isOpen:n,swipeState:I,displacement:R,isOpening:W,isClosing:P,enabled:L,inline:O,gridRef:z??void 0,contentBackground:t.revealBackground});const H=Wt(D,n,v,t,{width:c,height:u,zIndex:a}),S=jt(n,v,t,a,j),m=zt(D),y=s.useMemo(()=>({...tt({placement:D,inline:O,edgeWidth:C.edgeWidth,zIndex:a}),...x.style}),[D,O,C.edgeWidth,a,x.style]),T=s.useMemo(()=>C.enabled?{...H,...M.style}:H,[C.enabled,H,M.style]),A=at(C,n,W),N=p?.title??t.ariaLabel??"Drawer",ve=kt(A,g,y,x.onPointerDown,D);return h.jsxs(h.Fragment,{children:[ve,h.jsx("div",{ref:f,style:S,onClick:d?r:void 0}),h.jsx("div",{ref:E,"data-layer-id":e,"data-placement":D,style:T,role:"dialog","aria-modal":d?!0:void 0,"aria-hidden":n?void 0:!0,"aria-label":N,onPointerDown:C.enabled?M.onPointerDown:void 0,children:h.jsx(_t,{chrome:w,frameStyle:m,header:p,dismissible:d,onClose:r,children:i})})]})},Ht=(e,t)=>new Promise(n=>{let r=!1;const o=()=>{r||(r=!0,e.removeEventListener("transitionend",i),n())},i=a=>{a.target===e&&o()};e.addEventListener("transitionend",i),setTimeout(o,t+50)}),re=async(e,t,n,r)=>{switch(t){case"none":e();return;case"css":e(),n&&await Ht(n,r);return}},Bt=e=>{const[t,n]=s.useState({}),r=s.useRef(e);r.current=e;const o=s.useCallback(async(u,l,d)=>{const{mode:p="none",element:w,duration:O=300}=d??{};await re(()=>{n(E=>E[u]===l?E:{...E,[u]:l})},p,w?.current,O);const D=r.current;l?D?.onOpen?.(u):D?.onClose?.(u),D?.onTransitionEnd?.(u,l)},[]),i=s.useCallback(u=>t[u]??!1,[t]),a=s.useCallback((u,l)=>o(u,!0,l),[o]),c=s.useCallback((u,l)=>o(u,!1,l),[o]);return{state:i,open:a,close:c}},$t=e=>{if(!e)return 300;const t=e.match(/(\d+)/);return t?parseInt(t[1],10):300},be=e=>{const[t,n]=s.useState(()=>{const u={};return e.forEach(l=>{l.drawer&&(u[l.id]=l.drawer.defaultOpen??!1)}),u}),r=s.useMemo(()=>{const u=new Map;return e.forEach(l=>u.set(l.id,l)),u},[e]),o=s.useCallback(async(u,l,d)=>{const p=r.get(u);if(!p?.drawer)return;const w=d?.mode??p.drawer.transitionMode??"css",O=d?.duration??$t(p.drawer.transitionDuration),C=d?.element?.current;await re(()=>{p.drawer?.open===void 0&&n(E=>E[u]===l?E:{...E,[u]:l}),p.drawer?.onStateChange?.(l)},w,C,O)},[r]),i=s.useCallback(u=>{const l=r.get(u);return l?.drawer?.open!==void 0?l.drawer.open:t[u]??!1},[r,t]),a=s.useCallback((u,l)=>o(u,!0,l),[o]),c=s.useCallback((u,l)=>o(u,!1,l),[o]);return{state:i,open:a,close:c}};function Gt(e){if(!e.drawer)return!1;const{animationMode:t,inline:n=!1}=e.drawer;return Z(t)?!n:!1}function ae(e,t){const n=new Map;return e.forEach(r=>{n.set(r.id,t(r.id))}),n}const Ut=({layers:e})=>{const t=be(e),n=s.useMemo(()=>e.filter(i=>i.drawer),[e]),r=s.useMemo(()=>ae(n,i=>()=>t.close(i)),[n,t.close]),o=s.useMemo(()=>ae(n,i=>()=>t.open(i)),[n,t.open]);return h.jsx(h.Fragment,{children:n.map(i=>{if(!i.drawer)return null;const a=t.state(i.id),c=r.get(i.id),u=o.get(i.id);if(!c)return null;const l=h.jsx(Se,{id:i.id,config:i.drawer,isOpen:a,onClose:c,onOpen:u,zIndex:i.zIndex,width:i.width,height:i.height,position:i.position,children:i.component},i.id);return Gt(i)?Te.createPortal(l,document.body):l})})},Ee=s.createContext(null),Vt=({value:e,children:t})=>h.jsx(Ee.Provider,{value:e,children:t}),Yt=()=>{const e=s.useContext(Ee);if(!e)throw new Error("useGridLayoutContext must be used within a GridLayoutProvider.");return e},Pe=s.createContext(null),Zt=()=>{const e=s.useContext(Pe);if(!e)throw new Error("usePanelSystem must be used within a PanelSystemProvider.");return e},qt=({config:e,layers:t,style:n,children:r})=>{const o=s.useMemo(()=>{const l=new Map;return t.forEach(d=>{l.set(d.id,d)}),l},[t]),i=s.useCallback(l=>o.get(l)?.component??null,[o]),a=s.useMemo(()=>t.map(l=>l.id),[t]),{getCachedContent:c}=Re.useContentCache({resolveContent:i,validIds:a}),u=s.useMemo(()=>({config:e,style:n,layers:{defs:t,layerById:o},getCachedContent:c}),[e,n,t,o,c]);return h.jsx(Pe.Provider,{value:u,children:r})},ye=s.createContext(null),Oe=({layerId:e,children:t})=>{const n=s.useMemo(()=>({layerId:e}),[e]);return h.jsx(ye.Provider,{value:n,children:t})},Xt=()=>{const e=s.useContext(ye);if(!e)throw new Error("useLayerInstance must be used within a LayerInstanceProvider.");return e},ce=(e,t,n)=>{if(typeof e=="number"&&Number.isFinite(e))return e;throw new Error(`Popup layer "${n}" requires a numeric "${t}" value.`)},Ce=(e,t)=>{if(!e)throw new Error(`Popup layer "${t}" must define position (left/top).`);return{left:ce(e.left,"left",t),top:ce(e.top,"top",t)}},X=e=>`${Math.round(e)}`,V=e=>{if(e!==void 0)return e?"yes":"no"},Kt=(e,t,n,r,o)=>{const i={},a=Ce(t,e);if(typeof n!="number"||typeof r!="number")throw new Error(`Popup layer "${e}" requires numeric width/height.`);i.width=X(n),i.height=X(r),i.left=X(a.left),i.top=X(a.top);const c=o?.features;if(c){const u=V(c.toolbar),l=V(c.menubar),d=V(c.location),p=V(c.status),w=V(c.resizable),O=V(c.scrollbars);u!==void 0&&(i.toolbar=u),l!==void 0&&(i.menubar=l),d!==void 0&&(i.location=d),p!==void 0&&(i.status=p),w!==void 0&&(i.resizable=w),O!==void 0&&(i.scrollbars=O)}return Object.entries(i).map(([u,l])=>`${u}=${l}`).join(",")},ue=(e,t,n,r,o)=>{const i=Ce(n,t);if(typeof r!="number"||typeof o!="number")throw new Error(`Popup layer "${t}" requires numeric width/height.`);e.moveTo(Math.round(i.left),Math.round(i.top)),e.resizeTo(Math.round(r),Math.round(o))},Jt=({layer:e})=>{const t=e.floating;if(!t)throw new Error(`Layer "${e.id}" is missing floating configuration required for popup mode.`);if((t.mode??"embedded")!=="popup")throw new Error(`PopupLayerPortal received layer "${e.id}" that is not configured for popup mode.`);const r=s.useRef(null),o=s.useRef(null),[i,a]=s.useState(!1);return s.useEffect(()=>{if(typeof window>"u")return;const c=Kt(e.id,e.position,e.width,e.height,t.popup),u=t.popup?.name??e.id,l=Qt(u,c,{position:e.position,size:{width:e.width,height:e.height}},t.popup);if(!l)throw new Error(`Failed to open popup window for layer "${e.id}".`);const d=l;o.current=d,t.popup?.focus!==!1&&d.focus(),d.document.title||(d.document.title=e.id),d.document.body.innerHTML="";const p=d.document.createElement("div");p.dataset.layerId=e.id,d.document.body.appendChild(p),r.current=p,a(!0),ue(d,e.id,e.position,e.width,e.height);const w=()=>{o.current=null,r.current=null,a(!1)};return d.addEventListener("beforeunload",w),()=>{d.removeEventListener("beforeunload",w),t.popup?.closeOnUnmount!==!1&&d.close(),o.current=null,r.current=null,a(!1)}},[t.popup?.closeOnUnmount,t.popup?.features?.location,t.popup?.features?.menubar,t.popup?.features?.resizable,t.popup?.features?.scrollbars,t.popup?.features?.status,t.popup?.features?.toolbar,t.popup?.focus,t.popup?.name,e.id]),s.useEffect(()=>{const c=o.current;c&&ue(c,e.id,e.position,e.width,e.height)},[e.position?.left,e.position?.top,e.height,e.width,e.id]),!i||!r.current?null:le.createPortal(h.jsx(Oe,{layerId:e.id,children:e.component}),r.current)},Qt=(e,t,n,r)=>{const o=r?.createWindow;return o?o({name:e,features:t,bounds:n}):window.open("",e,t)},en=({onClick:e})=>h.jsx(_.FloatingPanelControls,{children:h.jsx(_.FloatingPanelCloseButton,{onClick:e,"aria-label":"Close window","data-drag-ignore":"true"})}),tn=({header:e,draggable:t,onClose:n})=>{if(!e)return null;const r=e.showCloseButton??!1,o=t?{"data-drag-handle":"true"}:{},i=t?"grab":void 0;return h.jsxs(_.FloatingPanelHeader,{...o,style:{cursor:i},children:[e.title?h.jsx(_.FloatingPanelTitle,{children:e.title}):null,r?h.jsx(en,{onClick:n}):null]})},nn=({header:e,draggable:t,chrome:n,onClose:r,children:o})=>n?h.jsxs(_.FloatingPanelFrame,{style:{height:"100%",width:"100%"},children:[h.jsx(tn,{header:e,draggable:t,onClose:r}),h.jsx(_.FloatingPanelContent,{style:{flex:1,display:"flex",flexDirection:"column"},children:o})]}):h.jsx(h.Fragment,{children:o}),De=({id:e,config:t,onClose:n,children:r})=>{const o=t.chrome??!1,i=t.draggable??!1,a=t.header?.title??t.ariaLabel??"Floating window";return h.jsx("div",{"data-floating-window":e,role:"dialog","aria-label":a,style:{height:"100%",width:"100%"},children:h.jsx(nn,{header:t.header,draggable:i,chrome:o,onClose:n,children:r})})};De.displayName="FloatingWindow";exports.Drawer=Se;exports.DrawerLayers=Ut;exports.DrawerRevealProvider=At;exports.FloatingWindow=De;exports.GridLayoutProvider=Vt;exports.LayerInstanceProvider=Oe;exports.PanelSystemProvider=qt;exports.PopupLayerPortal=Jt;exports.SwipeSafeZone=Me;exports.bindActionCreators=ct;exports.createAction=k;exports.createActionHandlerMap=fe;exports.isRevealMode=Z;exports.runTransition=re;exports.useDrawerReveal=he;exports.useDrawerState=be;exports.useGridLayoutContext=Yt;exports.useLayerInstance=Xt;exports.usePanelSystem=Zt;exports.useTransitionState=Bt;
2
- //# sourceMappingURL=FloatingWindow-Cvyokf0m.cjs.map
1
+ "use strict";const h=require("react/jsx-runtime"),xe=require("react"),le=require("react-dom"),_=require("./FloatingPanelFrame-CEmXDvUA.cjs"),U=require("./styles-qf6ptVLD.cjs"),$=require("./useAnimationFrame-XRpDXkwV.cjs"),Re=require("./useContentCache-DqXtLrLs.cjs");function de(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const s=de(xe),Te=de(le),Ae="data-swipe-safe-zone",Me=({children:e,className:t,style:n})=>h.jsx("div",{className:t,style:n,"data-swipe-safe-zone":"true",children:e});function _e(e,t){let n=e;for(;n&&n!==t;){if(n.hasAttribute(Ae))return!0;n=n.parentElement}return!1}function Le(e){switch(e){case"left":case"right":return"x";case"top":case"bottom":return"y"}}function pe(e){switch(e){case"left":return-1;case"right":return 1;case"top":return-1;case"bottom":return 1}}function Fe(e){return pe(e)*-1}const ke=.3,Ie=.5;function Ne(e,t){return t==="x"?e.clientWidth:e.clientHeight}function We(e,t,n){return n==="x"?t.x-e.x:t.y-e.y}const je={idle:"idle",ended:"ended"};function ze(e){return je[e]??"operating"}function He(e,t,n){const r=e*n;return t==="x"?{x:r,y:0}:{x:0,y:r}}function Be(e,t,n){return t==="x"?Math.max(0,n*e.x):Math.max(0,n*e.y)}function $e(e,t){return e?!t:!1}function Ge(e,t){return e?t:!1}function Ue(e,t){return e?!t:!1}function Ve(e,t){return e==="idle"?!1:t}function Ye(e,t,n){if(!e||!t)return 0;const r=Math.max(1,t.timestamp-e.timestamp);return n/r}function Ze(e){const{edgeContainerRef:t,drawerContentRef:n,direction:r,isOpen:o,onSwipeOpen:i,onSwipeClose:a,enableEdgeSwipeOpen:c=!0,enableSwipeClose:u=!0,edgeWidth:l=20,dismissThreshold:d=ke}=e,p=Le(r),w=pe(r),O=Fe(r),C=s.useRef(0);s.useLayoutEffect(()=>{const m=n.current;if(!m)return;const y=()=>{C.current=Ne(m,p)};y();const T=new ResizeObserver(y);return T.observe(m),()=>T.disconnect()},[n,p]);const D=s.useCallback(m=>{m.direction===O&&i()},[O,i]),{isEdgeGesture:E,state:f,containerProps:g}=$.useEdgeSwipeInput({containerRef:t,edge:r,edgeWidth:l,enabled:$e(c,o),onSwipeEnd:D}),{containerProps:G}=$.useNativeGestureGuard({containerRef:t,active:E,preventEdgeBack:!0,preventOverscroll:!0,edgeWidth:l}),{state:b,onPointerDown:I}=$.usePointerTracking({enabled:Ge(u,o)}),[R,x]=s.useState("idle"),M=s.useRef(0),W=s.useCallback(m=>{if(!u||!o)return;const y=n.current;if(!y)return;const T=m.target;_e(T,y)||$.isScrollableInDirection(T,y,p,w)||I(m)},[u,o,n,p,w,I]),P=s.useMemo(()=>{if(!b.isDown||!b.start||!b.current)return M.current;const y=We(b.start,b.current,p)*w;return Math.max(0,y)},[b.isDown,b.start,b.current,p,w]);s.useEffect(()=>{b.isDown&&b.current&&(M.current=P)},[b.isDown,b.current,P]),s.useEffect(()=>{b.isDown&&R==="idle"&&x("operating")},[b.isDown,R]),s.useEffect(()=>{if(!b.isDown&&R==="operating"){const m=M.current;if(m>1){x("ended");const T=C.current;if(T>0){const A=m/T,N=Ye(b.start,b.current,m);(A>=d||N>=Ie)&&a()}}else x("idle"),M.current=0}},[b.isDown,R,d,a,b.start,b.current]),s.useEffect(()=>{R==="ended"&&queueMicrotask(()=>{x("idle"),M.current=0})},[R]),s.useEffect(()=>{o||(x("idle"),M.current=0)},[o]);const v=Ue(E,o),L=Ve(R,o),j=s.useMemo(()=>v?Be(f.displacement,p,O):L?P:0,[v,L,p,f.displacement,P,O]),F=s.useMemo(()=>{const m=C.current;return m<=0?0:Math.min(j/m,1)},[j]),z=s.useMemo(()=>v?{phase:ze(f.phase),displacement:f.displacement,velocity:f.velocity}:L?{phase:R,displacement:He(w,p,P),velocity:{x:0,y:0}}:$.IDLE_CONTINUOUS_OPERATION_STATE,[v,L,f,R,P,p,w]),H=s.useMemo(()=>$.mergeGestureContainerProps(g,G),[g,G]),S=s.useMemo(()=>({onPointerDown:W,style:{touchAction:"none",userSelect:"none",WebkitUserSelect:"none"}}),[W]);return{state:z,isOpening:v,isClosing:L,progress:F,displacement:j,edgeContainerProps:H,drawerContentProps:S}}const oe={position:"fixed",inset:0,background:U.COLOR_DRAWER_BACKDROP},ie={willChange:"transform"},qe={left:{top:0,bottom:0,left:0,transform:"translateX(-100%)"},right:{top:0,bottom:0,right:0,transform:"translateX(100%)"},top:{top:0,left:0,right:0,transform:"translateY(-100%)"},bottom:{bottom:0,left:0,right:0,transform:"translateY(100%)"}},Xe={left:"translateX(0)",right:"translateX(0)",top:"translateY(0)",bottom:"translateY(0)"};function Ke(e){return qe[e]}function Je(e){return Xe[e]}function Qe(e,t,n){if(e==="none")return;const r=t??U.DRAWER_TRANSITION_DURATION,o=n??U.DRAWER_TRANSITION_EASING;return`transform ${r} ${o}`}function et(e,t){if(e!=="none")return`opacity ${t??"220ms"} ease`}function q(e){if(e!==void 0)return typeof e=="number"?`${e}px`:e}function tt(e){const{placement:t,inline:n,edgeWidth:r,zIndex:o}=e,i=n?"absolute":"fixed",a=o!==void 0?o-2:1e3;return nt(t,i,r,a)}function nt(e,t,n,r){const o={position:t,zIndex:r,background:"transparent",pointerEvents:"auto"};return e==="left"?{...o,top:0,bottom:0,left:0,width:n}:e==="right"?{...o,top:0,bottom:0,right:0,width:n}:e==="top"?{...o,top:0,left:0,right:0,height:n}:{...o,bottom:0,left:0,right:0,height:n}}const te=20,ne=.3,rt={enabled:!1,edgeSwipeOpen:!1,swipeClose:!1,edgeWidth:te,dismissThreshold:ne},ot={enabled:!0,edgeSwipeOpen:!0,swipeClose:!0,edgeWidth:te,dismissThreshold:ne};function it(e){return e===!0?ot:e===!1||e===void 0?rt:{enabled:!0,edgeSwipeOpen:e.edgeSwipeOpen??!0,swipeClose:e.swipeClose??!0,edgeWidth:e.edgeWidth??te,dismissThreshold:e.dismissThreshold??ne}}function st(e,t){return e||(t?t.left!==void 0?"left":t.right!==void 0?"right":t.top!==void 0?"top":t.bottom!==void 0?"bottom":"right":"right")}function at(e,t,n){return!e.enabled||!e.edgeSwipeOpen?!1:t?n:!0}function k(e,t){if(!t){const r=(()=>({type:e}));return Object.defineProperty(r,"type",{value:e,writable:!1,enumerable:!0}),r}const n=((...r)=>{const o=t(...r);return typeof o>"u"?{type:e}:{type:e,payload:o}});return Object.defineProperty(n,"type",{value:e,writable:!1,enumerable:!0}),n}const ct=(e,t)=>{const n={};return Object.keys(e).forEach(r=>{const o=e[r];n[r]=((...i)=>{const a=o(...i);return t(a),a})}),n},fe=(e,t)=>{const n={};return Object.keys(t).forEach(r=>{const o=t[r];if(!o)return;const i=e[r];if(!i)throw new Error(`Missing action creator for key "${String(r)}"`);n[i.type]=o}),n},ut=100,lt=.3,dt=30,pt=300,ft=1;function mt(e,t,n){if(t<=0||n===null)return 0;const r=Math.min(1,Math.max(0,e/t));return n==="opening"?r:1-r}function wt(e,t,n){return n==="opening"?e>=ut:n==="closing"?(t>0?e/t:0)<lt:!1}const B={swipeStart:k("SWIPE_START",e=>({direction:e})),swipeUpdate:k("SWIPE_UPDATE",e=>({displacement:e})),swipeEnd:k("SWIPE_END"),animationFrame:k("ANIMATION_FRAME",e=>({easedProgress:e})),animationComplete:k("ANIMATION_COMPLETE"),buttonOpen:k("BUTTON_OPEN"),buttonClose:k("BUTTON_CLOSE"),syncOpenState:k("SYNC_OPEN_STATE",e=>({isOpen:e})),initialize:k("INITIALIZE",e=>({isOpen:e}))};function Q(e,t,n){return e?t.getOpenPosition(n):t.getClosedPosition(n)}function ee(e,t,n){const r=Q(e,t,n);return{phase:e?"open":"closed",targetOpen:e,position:r,isOperating:!1,swipeDirection:null,displacement:0,animation:null}}function gt(e){const t=fe(B,{swipeStart:(n,r,o)=>"payload"in r?{...n,isOperating:!0,swipeDirection:r.payload.direction,displacement:0,animation:null}:n,swipeUpdate:(n,r,o)=>{if(!("payload"in r)||!n.isOperating)return n;const i=mt(r.payload.displacement,o.drawerSize,n.swipeDirection),a=e.computePositionFromProgress(i,o);return{...n,displacement:r.payload.displacement,position:a}},swipeEnd:(n,r,o)=>{if(!n.isOperating)return n;const i=wt(n.displacement,o.drawerSize,n.swipeDirection),a=Q(i,e,o);if(e.shouldAnimate(n.position,a)){const c=i?"opening":"closing";return{...n,isOperating:!1,swipeDirection:null,displacement:0,targetOpen:i,phase:c,animation:{type:c,from:n.position,to:a}}}return{...n,isOperating:!1,swipeDirection:null,displacement:0,targetOpen:i,phase:i?"open":"closed",position:a,animation:null}},animationFrame:(n,r,o)=>{if(!("payload"in r)||!n.animation)return n;const i=e.interpolatePosition(n.animation.from,n.animation.to,r.payload.easedProgress);return{...n,position:i}},animationComplete:(n,r,o)=>{if(!n.animation)return n;const i=n.animation.type==="opening";return{...n,phase:i?"open":"closed",position:n.animation.to,animation:null}},buttonOpen:(n,r,o)=>{if(n.phase==="open"||n.phase==="opening"||n.isOperating)return n;const i=e.getOpenPosition(o),a=n.position;return e.shouldAnimate(a,i)?{...n,targetOpen:!0,phase:"opening",animation:{type:"opening",from:a,to:i}}:{...n,targetOpen:!0,phase:"open",position:i,animation:null}},buttonClose:(n,r,o)=>{if(n.phase==="closed"||n.phase==="closing"||n.isOperating)return n;const i=e.getClosedPosition(o),a=n.position;return e.shouldAnimate(a,i)?{...n,targetOpen:!1,phase:"closing",animation:{type:"closing",from:a,to:i}}:{...n,targetOpen:!1,phase:"closed",position:i,animation:null}},syncOpenState:(n,r,o)=>{if(!("payload"in r))return n;const{isOpen:i}=r.payload;if(n.targetOpen===i&&!n.isOperating&&!n.animation)return n;if(n.isOperating)return{...n,targetOpen:i};if(n.animation&&n.animation.type==="opening"===i)return{...n,targetOpen:i};if((n.phase==="open"||n.phase==="opening")===i)return{...n,targetOpen:i};const c=Q(i,e,o),u=n.position;if(e.shouldAnimate(u,c)){const l=i?"opening":"closing";return{...n,targetOpen:i,phase:l,animation:{type:l,from:u,to:c}}}return{...n,targetOpen:i,phase:i?"open":"closed",position:c,animation:null}},initialize:(n,r,o)=>"payload"in r?ee(r.payload.isOpen,e,o):n});return function(r,o,i){const a=t[o.type];return a?a(r,o,i):r}}const ht={left:{axis:"X",sign:1},right:{axis:"X",sign:-1},top:{axis:"Y",sign:1},bottom:{axis:"Y",sign:-1}};function Y(e){return ht[e]}const K={position:"relative",zIndex:"1",background:"#fff"};function se(e){e.style.position="",e.style.zIndex="",e.style.background=""}function St(){document.body.style.overflow="hidden"}function J(){document.body.style.overflow=""}function me(e,t){return e?t?.current??null:document.getElementById("root")??document.body.firstElementChild}function bt(e){e.style.visibility="visible",e.style.pointerEvents="auto"}function Et(e){e.style.visibility="hidden",e.style.pointerEvents="none"}function Pt(e){e.style.visibility="",e.style.pointerEvents=""}function yt(e,t=K.background){e.style.position=K.position,e.style.zIndex=K.zIndex,e.style.background=t}const Ot={getClosedPosition(e){return this.computePositionFromProgress(0,e)},getOpenPosition(e){return this.computePositionFromProgress(1,e)},computePositionFromProgress(e,t){const{sign:n}=Y(t.placement),o=t.drawerSize*(dt/100)*(1-e),i=n>0?-o:o,a=n*t.drawerSize*e;return{drawerPx:i,contentPx:a}},interpolatePosition(e,t,n){return{drawerPx:e.drawerPx+(t.drawerPx-e.drawerPx)*n,contentPx:e.contentPx+(t.contentPx-e.contentPx)*n}},shouldAnimate(e,t){return Math.abs(e.contentPx-t.contentPx)>ft},applyToDOM(e,t,n){const{drawer:r,content:o}=t,{axis:i}=Y(n.placement);r&&(r.style.transition="none",r.style.transform=`translate${i}(${e.drawerPx}px)`),o&&(yt(o,n.contentBackground),o.style.transition="none",o.style.transform=`translate${i}(${e.contentPx}px)`)},clearFromDOM(e){const{drawer:t,content:n}=e;t&&(t.style.transform="",t.style.transition=""),n&&(n.style.transform="",n.style.transition="",se(n))},onOpeningStart(e){e.drawer&&bt(e.drawer)},onClosingComplete(e){const{drawer:t,content:n}=e;t&&(Et(t),t.style.transform="",t.style.transition=""),n&&(n.style.transform="",n.style.transition="",se(n))}},Ct=1,Dt={getClosedPosition(e){const{sign:t}=Y(e.placement);return{drawerPx:-t*e.drawerSize,backdropOpacity:0}},getOpenPosition(){return{drawerPx:0,backdropOpacity:1}},computePositionFromProgress(e,t){const{sign:n}=Y(t.placement);return{drawerPx:-n*t.drawerSize*(1-e),backdropOpacity:e}},interpolatePosition(e,t,n){return{drawerPx:e.drawerPx+(t.drawerPx-e.drawerPx)*n,backdropOpacity:e.backdropOpacity+(t.backdropOpacity-e.backdropOpacity)*n}},shouldAnimate(e,t){return Math.abs(e.drawerPx-t.drawerPx)>Ct},applyToDOM(e,t,n){const{drawer:r,backdrop:o}=t,{axis:i}=Y(n.placement);r&&(r.style.transition="none",r.style.transform=`translate${i}(${e.drawerPx}px)`),o&&(o.style.opacity=String(e.backdropOpacity),o.style.pointerEvents=e.backdropOpacity>0?"auto":"none")},clearFromDOM(e){const{drawer:t,backdrop:n}=e;t&&(t.style.transform="",t.style.transition=""),n&&(n.style.opacity="",n.style.pointerEvents="")},onOpeningStart(){},onClosingComplete(e,t){const{drawer:n,backdrop:r}=e,o=vt(t);n&&(n.style.transform=o,n.style.transition=""),r&&(r.style.opacity="0",r.style.pointerEvents="none")}};function vt(e){switch(e.placement){case"left":return"translateX(-100%)";case"right":return"translateX(100%)";case"top":return"translateY(-100%)";case"bottom":return"translateY(100%)"}}function xt(e){return e==="reveal"?Ot:Dt}function we(e){const{mode:t,drawerRef:n,contentRef:r,backdropRef:o,placement:i,drawerSize:a,isOpen:c,swipeState:u,displacement:l,isOpening:d,isClosing:p,enabled:w,inline:O=!1,gridRef:C,contentBackground:D="#fff"}=e,E=u.phase==="operating",f=xt(t),g=s.useMemo(()=>({placement:i,drawerSize:a,contentBackground:D}),[i,a,D]),G=s.useMemo(()=>gt(f),[f]),b=s.useRef(ee(c,f,g)),[I,R]=s.useState(c?"open":"closed"),x=s.useRef({isOperating:!1,isOpening:!1,isClosing:!1,isOpen:c,enabled:!1}),M=()=>t!=="reveal"?null:r?.current??me(O,C),W=()=>t!=="overlay"?null:o?.current??null,P=s.useCallback(()=>({drawer:n.current,content:M(),backdrop:W()}),[t,n,r,o,O,C]),v=s.useCallback(S=>{const m=G(b.current,S,g);return b.current=m,R(m.phase),m},[G,g]),L=s.useCallback(({easedProgress:S})=>{const m=b.current;if(!m.animation)return;const y=f.interpolatePosition(m.animation.from,m.animation.to,S);b.current={...m,position:y};const T=P();f.applyToDOM(y,T,g)},[f,P,g]),j=s.useCallback(()=>{const S=v(B.animationComplete()),m=P();S.phase==="closed"&&f.onClosingComplete?.(m,g)},[v,f,P,g]),{isAnimating:F,start:z,cancel:H}=$.useAnimationFrame({duration:pt,easing:$.easings.easeOutExpo,onFrame:L,onComplete:j});return s.useLayoutEffect(()=>{if(!w){x.current.enabled=!1;return}if(x.current.enabled)return;x.current.enabled=!0,b.current=ee(c,f,g),R(c?"open":"closed");const S=P();c?(f.onOpeningStart?.(S,g),f.applyToDOM(b.current.position,S,g)):f.onClosingComplete?.(S,g)},[w,c,f,g,P]),s.useLayoutEffect(()=>{if(!w)return;const S=x.current,m=S.isOperating,y=S.isOpening,T=S.isClosing;if(S.isOperating=E,S.isOpening=d,S.isClosing=p,!m&&E){H();const A=d?"opening":p?"closing":null;A&&v(B.swipeStart(A));return}if(m&&!E){const A=v(B.swipeEnd()),N=P();A.animation?(f.onOpeningStart?.(N,g),z()):A.phase==="open"?(f.onOpeningStart?.(N,g),f.applyToDOM(A.position,N,g)):A.phase==="closed"&&f.onClosingComplete?.(N,g);return}if(E){const A=d?"opening":p?"closing":null;A!==(y?"opening":T?"closing":null)&&A&&v(B.swipeStart(A))}},[w,E,d,p,v,H,z,f,g,P]),s.useLayoutEffect(()=>{if(!w||!E||!d&&!p)return;const S=v(B.swipeUpdate(l)),m=P();f.onOpeningStart?.(m,g),f.applyToDOM(S.position,m,g)},[w,E,d,p,l,v,f,g,P]),s.useLayoutEffect(()=>{if(!w)return;const S=x.current;if(S.isOpen===c)return;if(S.isOpen=c,E){v(B.syncOpenState(c));return}if(F&&b.current.animation?.type==="opening"===c)return;const m=v(B.syncOpenState(c)),y=P();m.animation?(f.onOpeningStart?.(y,g),f.applyToDOM(m.animation.from,y,g),z()):F||(m.phase==="open"?(f.onOpeningStart?.(y,g),f.applyToDOM(m.position,y,g)):m.phase==="closed"&&f.onClosingComplete?.(y,g))},[w,c,E,F,v,z,f,g,P]),s.useLayoutEffect(()=>{if(w||!x.current.enabled)return;const S=P();f.clearFromDOM(S,g),S.drawer&&Pt(S.drawer)},[w,f,g,P]),s.useLayoutEffect(()=>{if(!w||t!=="reveal"){t==="reveal"&&J();return}return(c||E?!0:F)?St():J(),()=>{J()}},[w,t,c,E,F]),s.useLayoutEffect(()=>{if(!(!w||t!=="reveal"))return()=>{const S=P();S.content&&f.clearFromDOM({drawer:null,content:S.content,backdrop:null},g)}},[w,t,f,g,P]),{phase:I,isAnimating:F}}function Rt(e){const{drawerRef:t,backdropRef:n,placement:r,swipeState:o,displacement:i,isOpening:a,isClosing:c,isOpen:u,enabled:l}=e,d=s.useRef(0);s.useLayoutEffect(()=>{const p=t.current;if(p){const w=r==="left"||r==="right";d.current=w?p.clientWidth:p.clientHeight}},[t,r]),we({mode:"overlay",drawerRef:t,backdropRef:n,placement:r,drawerSize:d.current,isOpen:u,swipeState:o,displacement:i,isOpening:a,isClosing:c,enabled:l})}const Tt={activeRevealDrawer:null,setRevealState:()=>{},gridRef:null,setGridRef:()=>{}},ge=s.createContext(Tt),At=({children:e})=>{const[t,n]=s.useState(null),[r,o]=s.useState(null),i=s.useCallback(u=>{n(u)},[]),a=s.useCallback(u=>{o(u)},[]),c=s.useMemo(()=>({activeRevealDrawer:t,setRevealState:i,gridRef:r,setGridRef:a}),[t,i,r,a]);return h.jsx(ge.Provider,{value:c,children:e})};function he(){return s.useContext(ge)}function Z(e){return e==="reveal"}function Mt(e){const{drawerRef:t,placement:n,drawerSize:r,isOpen:o,swipeState:i,displacement:a,isOpening:c,isClosing:u,enabled:l,inline:d,gridRef:p,contentBackground:w="#fff"}=e,O=s.useRef(null);return s.useLayoutEffect(()=>{O.current=me(d,p)},[d,p]),we({mode:"reveal",drawerRef:t,contentRef:O,placement:n,drawerSize:r,isOpen:o,swipeState:i,displacement:a,isOpening:c,isClosing:u,enabled:l,inline:d,gridRef:p,contentBackground:w})}const _t=({chrome:e,frameStyle:t,header:n,dismissible:r,onClose:o,children:i})=>e?h.jsxs(_.FloatingPanelFrame,{style:t,children:[h.jsx(Nt,{header:n,dismissible:r,onClose:o}),h.jsx(_.FloatingPanelContent,{style:{padding:U.DRAWER_CONTENT_PADDING,flex:1,display:"flex",flexDirection:"column"},children:i})]}):h.jsx(h.Fragment,{children:i});function Lt(e,t){return e?t:!1}function Ft(e,t){return e?h.jsx(_.FloatingPanelCloseButton,{onClick:t,"aria-label":"Close drawer",style:{marginLeft:"auto"}}):null}function kt(e,t,n,r,o){return e?h.jsx("div",{ref:t,style:n,onPointerDown:r,"data-drawer-edge-zone":o}):null}function It(e,t,n){return e==="left"||e==="right"?typeof t=="number"?t:0:typeof n=="number"?n:0}const Nt=({header:e,dismissible:t,onClose:n})=>{if(!e)return null;const r=e.showCloseButton??!0,o=Lt(t,r);return h.jsxs(_.FloatingPanelHeader,{style:{padding:`${U.DRAWER_HEADER_PADDING_Y} ${U.DRAWER_HEADER_PADDING_X}`,gap:U.DRAWER_HEADER_GAP},children:[h.jsx(_.FloatingPanelTitle,{children:e.title}),Ft(o,n)]})};function Wt(e,t,n,r,o){const i=Z(r.animationMode);return s.useMemo(()=>{const a=r.inline?"absolute":"fixed",c=Ke(e);if(i)return{...ie,position:a,top:c.top,bottom:c.bottom,left:c.left,right:c.right,zIndex:0,visibility:"hidden",pointerEvents:"none",width:q(o.width),height:q(o.height)};const u=n?"none":r.transitionMode,l=Qe(u,r.transitionDuration,r.transitionEasing),d=t?Je(e):c.transform;return{...ie,position:a,...c,transform:d,transition:l,zIndex:o.zIndex,width:q(o.width),height:q(o.height)}},[e,t,n,r,o,i])}function jt(e,t,n,r,o){const i=Z(n.animationMode);return s.useMemo(()=>{if(i)return{display:"none"};const a=n.inline?"absolute":"fixed";if(o)return{...oe,position:a,opacity:0,pointerEvents:"none",zIndex:r!==void 0?r-1:void 0};const c=t?"none":n.transitionMode,u=et(c,n.transitionDuration);return{...oe,position:a,opacity:e?1:0,pointerEvents:e?"auto":"none",transition:u,zIndex:r!==void 0?r-1:void 0}},[e,t,n,r,i,o])}function zt(e){return s.useMemo(()=>{const t={borderRadius:0};return(e==="left"||e==="right")&&(t.height="100%"),t},[e])}const Se=({id:e,config:t,isOpen:n,onClose:r,onOpen:o,children:i,zIndex:a,width:c,height:u,position:l})=>{const{dismissible:d=!0,header:p,chrome:w=!0,inline:O=!1}=t,C=it(t.swipeGestures),D=st(t.anchor,l),E=s.useRef(null),f=s.useRef(null),g=s.useRef(null),G=s.useCallback(()=>{o?.(),t.onStateChange?.(!0)},[o,t]),b=s.useCallback(()=>{r()},[r]),{state:I,displacement:R,edgeContainerProps:x,drawerContentProps:M,isOpening:W,isClosing:P}=Ze({edgeContainerRef:g,drawerContentRef:E,direction:D,isOpen:n,onSwipeOpen:G,onSwipeClose:b,enableEdgeSwipeOpen:C.edgeSwipeOpen,enableSwipeClose:C.swipeClose,edgeWidth:C.edgeWidth,dismissThreshold:C.dismissThreshold}),v=I.phase==="operating"||I.phase==="ended",L=Z(t.animationMode),j=C.enabled?!L:!1;Rt({drawerRef:E,backdropRef:f,placement:D,swipeState:I,displacement:R,isOpening:W,isClosing:P,isOpen:n,enabled:j});const F=It(D,c,u),{gridRef:z}=he();Mt({drawerRef:E,placement:D,drawerSize:F,isOpen:n,swipeState:I,displacement:R,isOpening:W,isClosing:P,enabled:L,inline:O,gridRef:z??void 0,contentBackground:t.revealBackground});const H=Wt(D,n,v,t,{width:c,height:u,zIndex:a}),S=jt(n,v,t,a,j),m=zt(D),y=s.useMemo(()=>({...tt({placement:D,inline:O,edgeWidth:C.edgeWidth,zIndex:a}),...x.style}),[D,O,C.edgeWidth,a,x.style]),T=s.useMemo(()=>C.enabled?{...H,...M.style}:H,[C.enabled,H,M.style]),A=at(C,n,W),N=p?.title??t.ariaLabel??"Drawer",ve=kt(A,g,y,x.onPointerDown,D);return h.jsxs(h.Fragment,{children:[ve,h.jsx("div",{ref:f,style:S,onClick:d?r:void 0}),h.jsx("div",{ref:E,"data-layer-id":e,"data-placement":D,style:T,role:"dialog","aria-modal":d?!0:void 0,"aria-hidden":n?void 0:!0,"aria-label":N,onPointerDown:C.enabled?M.onPointerDown:void 0,children:h.jsx(_t,{chrome:w,frameStyle:m,header:p,dismissible:d,onClose:r,children:i})})]})},Ht=(e,t)=>new Promise(n=>{let r=!1;const o=()=>{r||(r=!0,e.removeEventListener("transitionend",i),n())},i=a=>{a.target===e&&o()};e.addEventListener("transitionend",i),setTimeout(o,t+50)}),re=async(e,t,n,r)=>{switch(t){case"none":e();return;case"css":e(),n&&await Ht(n,r);return}},Bt=e=>{const[t,n]=s.useState({}),r=s.useRef(e);r.current=e;const o=s.useCallback(async(u,l,d)=>{const{mode:p="none",element:w,duration:O=300}=d??{};await re(()=>{n(E=>E[u]===l?E:{...E,[u]:l})},p,w?.current,O);const D=r.current;l?D?.onOpen?.(u):D?.onClose?.(u),D?.onTransitionEnd?.(u,l)},[]),i=s.useCallback(u=>t[u]??!1,[t]),a=s.useCallback((u,l)=>o(u,!0,l),[o]),c=s.useCallback((u,l)=>o(u,!1,l),[o]);return{state:i,open:a,close:c}},$t=e=>{if(!e)return 300;const t=e.match(/(\d+)/);return t?parseInt(t[1],10):300},be=e=>{const[t,n]=s.useState(()=>{const u={};return e.forEach(l=>{l.drawer&&(u[l.id]=l.drawer.defaultOpen??!1)}),u}),r=s.useMemo(()=>{const u=new Map;return e.forEach(l=>u.set(l.id,l)),u},[e]),o=s.useCallback(async(u,l,d)=>{const p=r.get(u);if(!p?.drawer)return;const w=d?.mode??p.drawer.transitionMode??"css",O=d?.duration??$t(p.drawer.transitionDuration),C=d?.element?.current;await re(()=>{p.drawer?.open===void 0&&n(E=>E[u]===l?E:{...E,[u]:l}),p.drawer?.onStateChange?.(l)},w,C,O)},[r]),i=s.useCallback(u=>{const l=r.get(u);return l?.drawer?.open!==void 0?l.drawer.open:t[u]??!1},[r,t]),a=s.useCallback((u,l)=>o(u,!0,l),[o]),c=s.useCallback((u,l)=>o(u,!1,l),[o]);return{state:i,open:a,close:c}};function Gt(e){if(!e.drawer)return!1;const{animationMode:t,inline:n=!1}=e.drawer;return Z(t)?!n:!1}function ae(e,t){const n=new Map;return e.forEach(r=>{n.set(r.id,t(r.id))}),n}const Ut=({layers:e})=>{const t=be(e),n=s.useMemo(()=>e.filter(i=>i.drawer),[e]),r=s.useMemo(()=>ae(n,i=>()=>t.close(i)),[n,t.close]),o=s.useMemo(()=>ae(n,i=>()=>t.open(i)),[n,t.open]);return h.jsx(h.Fragment,{children:n.map(i=>{if(!i.drawer)return null;const a=t.state(i.id),c=r.get(i.id),u=o.get(i.id);if(!c)return null;const l=h.jsx(Se,{id:i.id,config:i.drawer,isOpen:a,onClose:c,onOpen:u,zIndex:i.zIndex,width:i.width,height:i.height,position:i.position,children:i.component},i.id);return Gt(i)?Te.createPortal(l,document.body):l})})},Ee=s.createContext(null),Vt=({value:e,children:t})=>h.jsx(Ee.Provider,{value:e,children:t}),Yt=()=>{const e=s.useContext(Ee);if(!e)throw new Error("useGridLayoutContext must be used within a GridLayoutProvider.");return e},Pe=s.createContext(null),Zt=()=>{const e=s.useContext(Pe);if(!e)throw new Error("usePanelSystem must be used within a PanelSystemProvider.");return e},qt=({config:e,layers:t,style:n,children:r})=>{const o=s.useMemo(()=>{const l=new Map;return t.forEach(d=>{l.set(d.id,d)}),l},[t]),i=s.useCallback(l=>o.get(l)?.component??null,[o]),a=s.useMemo(()=>t.map(l=>l.id),[t]),{getCachedContent:c}=Re.useContentCache({resolveContent:i,validIds:a}),u=s.useMemo(()=>({config:e,style:n,layers:{defs:t,layerById:o},getCachedContent:c}),[e,n,t,o,c]);return h.jsx(Pe.Provider,{value:u,children:r})},ye=s.createContext(null),Oe=({layerId:e,children:t})=>{const n=s.useMemo(()=>({layerId:e}),[e]);return h.jsx(ye.Provider,{value:n,children:t})},Xt=()=>{const e=s.useContext(ye);if(!e)throw new Error("useLayerInstance must be used within a LayerInstanceProvider.");return e},ce=(e,t,n)=>{if(typeof e=="number"&&Number.isFinite(e))return e;throw new Error(`Popup layer "${n}" requires a numeric "${t}" value.`)},Ce=(e,t)=>{if(!e)throw new Error(`Popup layer "${t}" must define position (left/top).`);return{left:ce(e.left,"left",t),top:ce(e.top,"top",t)}},X=e=>`${Math.round(e)}`,V=e=>{if(e!==void 0)return e?"yes":"no"},Kt=(e,t,n,r,o)=>{const i={},a=Ce(t,e);if(typeof n!="number"||typeof r!="number")throw new Error(`Popup layer "${e}" requires numeric width/height.`);i.width=X(n),i.height=X(r),i.left=X(a.left),i.top=X(a.top);const c=o?.features;if(c){const u=V(c.toolbar),l=V(c.menubar),d=V(c.location),p=V(c.status),w=V(c.resizable),O=V(c.scrollbars);u!==void 0&&(i.toolbar=u),l!==void 0&&(i.menubar=l),d!==void 0&&(i.location=d),p!==void 0&&(i.status=p),w!==void 0&&(i.resizable=w),O!==void 0&&(i.scrollbars=O)}return Object.entries(i).map(([u,l])=>`${u}=${l}`).join(",")},ue=(e,t,n,r,o)=>{const i=Ce(n,t);if(typeof r!="number"||typeof o!="number")throw new Error(`Popup layer "${t}" requires numeric width/height.`);e.moveTo(Math.round(i.left),Math.round(i.top)),e.resizeTo(Math.round(r),Math.round(o))},Jt=({layer:e})=>{const t=e.floating;if(!t)throw new Error(`Layer "${e.id}" is missing floating configuration required for popup mode.`);if((t.mode??"embedded")!=="popup")throw new Error(`PopupLayerPortal received layer "${e.id}" that is not configured for popup mode.`);const r=s.useRef(null),o=s.useRef(null),[i,a]=s.useState(!1);return s.useEffect(()=>{if(typeof window>"u")return;const c=Kt(e.id,e.position,e.width,e.height,t.popup),u=t.popup?.name??e.id,l=Qt(u,c,{position:e.position,size:{width:e.width,height:e.height}},t.popup);if(!l)throw new Error(`Failed to open popup window for layer "${e.id}".`);const d=l;o.current=d,t.popup?.focus!==!1&&d.focus(),d.document.title||(d.document.title=e.id),d.document.body.innerHTML="";const p=d.document.createElement("div");p.dataset.layerId=e.id,d.document.body.appendChild(p),r.current=p,a(!0),ue(d,e.id,e.position,e.width,e.height);const w=()=>{o.current=null,r.current=null,a(!1)};return d.addEventListener("beforeunload",w),()=>{d.removeEventListener("beforeunload",w),t.popup?.closeOnUnmount!==!1&&d.close(),o.current=null,r.current=null,a(!1)}},[t.popup?.closeOnUnmount,t.popup?.features?.location,t.popup?.features?.menubar,t.popup?.features?.resizable,t.popup?.features?.scrollbars,t.popup?.features?.status,t.popup?.features?.toolbar,t.popup?.focus,t.popup?.name,e.id]),s.useEffect(()=>{const c=o.current;c&&ue(c,e.id,e.position,e.width,e.height)},[e.position?.left,e.position?.top,e.height,e.width,e.id]),!i||!r.current?null:le.createPortal(h.jsx(Oe,{layerId:e.id,children:e.component}),r.current)},Qt=(e,t,n,r)=>{const o=r?.createWindow;return o?o({name:e,features:t,bounds:n}):window.open("",e,t)},en=({onClick:e})=>h.jsx(_.FloatingPanelControls,{children:h.jsx(_.FloatingPanelCloseButton,{onClick:e,"aria-label":"Close window","data-drag-ignore":"true"})}),tn=({header:e,draggable:t,onClose:n})=>{if(!e)return null;const r=e.showCloseButton??!1,o=t?{"data-drag-handle":"true"}:{},i=t?"grab":void 0;return h.jsxs(_.FloatingPanelHeader,{...o,style:{cursor:i},children:[e.title?h.jsx(_.FloatingPanelTitle,{children:e.title}):null,r?h.jsx(en,{onClick:n}):null]})},nn=({header:e,draggable:t,chrome:n,onClose:r,children:o})=>n?h.jsxs(_.FloatingPanelFrame,{style:{height:"100%",width:"100%"},children:[h.jsx(tn,{header:e,draggable:t,onClose:r}),h.jsx(_.FloatingPanelContent,{style:{flex:1,display:"flex",flexDirection:"column"},children:o})]}):h.jsx(h.Fragment,{children:o}),De=({id:e,config:t,onClose:n,children:r})=>{const o=t.chrome??!1,i=t.draggable??!1,a=t.header?.title??t.ariaLabel??"Floating window";return h.jsx("div",{"data-floating-window":e,role:"dialog","aria-label":a,style:{height:"100%",width:"100%"},children:h.jsx(nn,{header:t.header,draggable:i,chrome:o,onClose:n,children:r})})};De.displayName="FloatingWindow";exports.Drawer=Se;exports.DrawerLayers=Ut;exports.DrawerRevealProvider=At;exports.FloatingWindow=De;exports.GridLayoutProvider=Vt;exports.LayerInstanceProvider=Oe;exports.PanelSystemProvider=qt;exports.PopupLayerPortal=Jt;exports.SwipeSafeZone=Me;exports.bindActionCreators=ct;exports.createAction=k;exports.createActionHandlerMap=fe;exports.isRevealMode=Z;exports.runTransition=re;exports.useDrawerReveal=he;exports.useDrawerState=be;exports.useGridLayoutContext=Yt;exports.useLayerInstance=Xt;exports.usePanelSystem=Zt;exports.useTransitionState=Bt;
2
+ //# sourceMappingURL=FloatingWindow-DpFpmX1f.cjs.map