import{j as E}from"./jsx-runtime-Byf2O5Qf.js";import{r as t}from"./chunk-HA7DTUK3-Cv5eIhAv.js";import{M as b,u as z,P as S,d as W,b as A,L as D}from"./proxy-CaJS_0Fl.js";class H extends t.Component{getSnapshotBeforeUpdate(l){const e=this.props.childRef.current;if(e&&l.isPresent&&!this.props.isPresent){const r=e.offsetParent,u=r instanceof HTMLElement&&r.offsetWidth||0,n=this.props.sizeRef.current;n.height=e.offsetHeight||0,n.width=e.offsetWidth||0,n.top=e.offsetTop,n.left=e.offsetLeft,n.right=u-n.width-n.left}return null}componentDidUpdate(){}render(){return this.props.children}}function K({children:c,isPresent:l,anchorX:e}){const r=t.useId(),u=t.useRef(null),n=t.useRef({width:0,height:0,top:0,left:0,right:0}),{nonce:h}=t.useContext(b);return t.useInsertionEffect(()=>{const{width:x,height:o,top:m,left:s,right:p}=n.current;if(l||!u.current||!x||!o)return;const d=e==="left"?`left: ${s}`:`right: ${p}`;u.current.dataset.motionPopId=r;const f=document.createElement("style");return h&&(f.nonce=h),document.head.appendChild(f),f.sheet&&f.sheet.insertRule(` [data-motion-pop-id="${r}"] { position: absolute !important; width: ${x}px !important; height: ${o}px !important; ${d}px !important; top: ${m}px !important; } `),()=>{document.head.removeChild(f)}},[l]),E.jsx(H,{isPresent:l,childRef:u,sizeRef:n,children:t.cloneElement(c,{ref:u})})}const U=({children:c,initial:l,isPresent:e,onExitComplete:r,custom:u,presenceAffectsLayout:n,mode:h,anchorX:x})=>{const o=z(B),m=t.useId(),s=t.useCallback(d=>{o.set(d,!0);for(const f of o.values())if(!f)return;r&&r()},[o,r]),p=t.useMemo(()=>({id:m,initial:l,isPresent:e,custom:u,onExitComplete:s,register:d=>(o.set(d,!1),()=>o.delete(d))}),n?[Math.random(),s]:[e,s]);return t.useMemo(()=>{o.forEach((d,f)=>o.set(f,!1))},[e]),t.useEffect(()=>{!e&&!o.size&&r&&r()},[e]),h==="popLayout"&&(c=E.jsx(K,{isPresent:e,anchorX:x,children:c})),E.jsx(S.Provider,{value:p,children:c})};function B(){return new Map}const M=c=>c.key||"";function v(c){const l=[];return t.Children.forEach(c,e=>{t.isValidElement(e)&&l.push(e)}),l}const T=({children:c,custom:l,initial:e=!0,onExitComplete:r,presenceAffectsLayout:u=!0,mode:n="sync",propagate:h=!1,anchorX:x="left"})=>{const[o,m]=W(h),s=t.useMemo(()=>v(c),[c]),p=h&&!o?[]:s.map(M),d=t.useRef(!0),f=t.useRef(s),g=z(()=>new Map),[L,k]=t.useState(s),[C,j]=t.useState(s);A(()=>{d.current=!1,f.current=s;for(let a=0;a{const i=M(a),y=h&&!o?!1:s===C||p.includes(i),w=()=>{if(g.has(i))g.set(i,!0);else return;let $=!0;g.forEach(I=>{I||($=!1)}),$&&(R==null||R(),j(f.current),h&&(m==null||m()),r&&r())};return E.jsx(U,{isPresent:y,initial:!d.current||e?void 0:!1,custom:l,presenceAffectsLayout:u,mode:n,onExitComplete:y?void 0:w,anchorX:x,children:a},i)})})};export{T as A};

AltStyle によって変換されたページ (->オリジナル) /