import{useContext as e,useRef as t,createElement as r,Fragment as n,cloneElement as i,Children as o,isValidElement as u}from"react";import{__spread as c}from"../../../../node_modules/tslib/tslib.es6.js";import{SharedLayoutContext as s,isSharedLayout as a}from"../../context/SharedLayoutContext.js";import{useForceUpdate as f}from"../../utils/use-force-update.js";import{PresenceChild as l}from"./PresenceChild.js";function p(e){return e.key||""}var d=function(d){var m=d.children,v=d.custom,h=d.initial,E=void 0===h||h,y=d.onExitComplete,x=d.exitBeforeEnter,k=d.presenceAffectsLayout,w=void 0===k||k,A=f(),N=e(s);a(N)&&(A=N.forceUpdate);var O=t(!0),P=function(e){var t=[];return o.forEach(e,(function(e){u(e)&&t.push(e)})),t}(m),C=t(P),L=t(new Map).current,b=t(new Set).current;if(function(e,t){var r="production"!==process.env.NODE_ENV?new Set:null;e.forEach((function(e){var n=p(e);"production"!==process.env.NODE_ENV&&r&&(r.has(n)&&console.warn('Children of AnimatePresence require unique keys. "'+n+'" is a duplicate.'),r.add(n)),t.set(n,e)}))}(P,L),O.current)return O.current=!1,r(n,null,P.map((function(e){return r(l,{key:p(e),isPresent:!0,initial:!!E&&void 0,presenceAffectsLayout:w},e)})));for(var g=c(P),j=C.current.map(p),_=P.map(p),z=j.length,D=0;D<z;D++){var S=j[D];-1===_.indexOf(S)?b.add(S):b.delete(S)}return x&&b.size&&(g=[]),b.forEach((function(e){if(-1===_.indexOf(e)){var t=L.get(e);if(t){var n=j.indexOf(e);g.splice(n,0,r(l,{key:p(t),isPresent:!1,onExitComplete:function(){L.delete(e),b.delete(e);var t=C.current.findIndex((function(t){return t.key===e}));C.current.splice(t,1),b.size||(C.current=P,A(),y&&y())},custom:v,presenceAffectsLayout:w},t))}}})),g=g.map((function(e){var t=e.key;return b.has(t)?e:r(l,{key:p(e),isPresent:!0,presenceAffectsLayout:w},e)})),C.current=g,"production"!==process.env.NODE_ENV&&x&&g.length>1&&console.warn("You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour."),r(n,null,b.size?g:g.map((function(e){return i(e)})))};export{d as AnimatePresence};
//# sourceMappingURL=index.js.map
