ivt
Version:
Ivt Components Library
3 lines (2 loc) • 2.59 kB
JavaScript
import*as e from"react";import{u as n}from"./index-C99OdH8-.mjs";function t(e,n){if("function"==typeof e)return e(n);null!=e&&(e.current=n)}function r(...e){return n=>{let r=!1;const o=e.map((e=>{const o=t(e,n);return r||"function"!=typeof o||(r=!0),o}));if(r)return()=>{for(let n=0;n<o.length;n++){const r=o[n];"function"==typeof r?r():t(e[n],null)}}}}function o(...n){return e.useCallback(r(...n),n)}function u(e,n,{checkForDefaultPrevented:t=!0}={}){return function(r){if(e?.(r),!1===t||!r.defaultPrevented)return n?.(r)}}var i=t=>{const{present:r,children:u}=t,i=function(t){const[r,o]=e.useState(),u=e.useRef(null),i=e.useRef(t),a=e.useRef("none"),c=t?"mounted":"unmounted",[f,l]=function(n,t){return e.useReducer(((e,n)=>t[e][n]??e),n)}(c,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return e.useEffect((()=>{const e=s(u.current);a.current="mounted"===f?e:"none"}),[f]),n((()=>{const e=u.current,n=i.current;if(n!==t){const r=a.current,o=s(e);if(t)l("MOUNT");else if("none"===o||"none"===e?.display)l("UNMOUNT");else{l(n&&r!==o?"ANIMATION_OUT":"UNMOUNT")}i.current=t}}),[t,l]),n((()=>{if(r){let e;const n=r.ownerDocument.defaultView??window,t=t=>{const o=s(u.current).includes(t.animationName);if(t.target===r&&o&&(l("ANIMATION_END"),!i.current)){const t=r.style.animationFillMode;r.style.animationFillMode="forwards",e=n.setTimeout((()=>{"forwards"===r.style.animationFillMode&&(r.style.animationFillMode=t)}))}},o=e=>{e.target===r&&(a.current=s(u.current))};return r.addEventListener("animationstart",o),r.addEventListener("animationcancel",t),r.addEventListener("animationend",t),()=>{n.clearTimeout(e),r.removeEventListener("animationstart",o),r.removeEventListener("animationcancel",t),r.removeEventListener("animationend",t)}}l("ANIMATION_END")}),[r,l]),{isPresent:["mounted","unmountSuspended"].includes(f),ref:e.useCallback((e=>{u.current=e?getComputedStyle(e):null,o(e)}),[])}}(r),a="function"==typeof u?u({present:i.isPresent}):e.Children.only(u),c=o(i.ref,function(e){let n=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,t=n&&"isReactWarning"in n&&n.isReactWarning;if(t)return e.ref;if(n=Object.getOwnPropertyDescriptor(e,"ref")?.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t)return e.props.ref;return e.props.ref||e.ref}(a));return"function"==typeof u||i.isPresent?e.cloneElement(a,{ref:c}):null};function s(e){return e?.animationName||"none"}i.displayName="Presence";export{i as P,r as a,u as c,o as u};
//# sourceMappingURL=index-BgU_7G37.mjs.map