@undp/design-system-react
Version:
React based design system for UNDP
2 lines • 2.87 kB
JavaScript
const e=require("./rolldown-runtime-mLOUI7ql.cjs"),t=require("./dist-DluBSGxD.cjs");let n=require("react");n=e.r(n,1);var r=Object.defineProperty,i=(e,t)=>r(e,`name`,{value:t,configurable:!0});function a(e,t){return n.useReducer((e,n)=>t[e][n]??e,e)}i(a,`useStateMachine`);var o=i(e=>{let{present:t,children:r}=e,i=s(t),a=typeof r==`function`?r({present:i.isPresent}):n.Children.only(r),o=l(i.ref,d(a));return typeof r==`function`||i.isPresent?n.cloneElement(a,{ref:o}):null},`Presence`);function s(e){let[r,o]=n.useState(),s=n.useRef(null),c=n.useRef(e),l=n.useRef(`none`),d=n.useRef(void 0),[f,p]=a(e?`mounted`:`unmounted`,{mounted:{UNMOUNT:`unmounted`,ANIMATION_OUT:`unmountSuspended`},unmountSuspended:{MOUNT:`mounted`,ANIMATION_END:`unmounted`},unmounted:{MOUNT:`mounted`}});return n.useEffect(()=>{f===`mounted`?(l.current=d.current??u(s.current),d.current=void 0):l.current=`none`},[f]),t.t(()=>{let t=s.current,n=c.current;if(n!==e){let r=l.current,i=u(t);e?(d.current=i,p(`MOUNT`)):i===`none`||t?.display===`none`?p(`UNMOUNT`):p(n&&r!==i?`ANIMATION_OUT`:`UNMOUNT`),c.current=e}},[e,p]),t.t(()=>{if(r){let e,t=r.ownerDocument.defaultView??window,n=i(n=>{let i=u(s.current).includes(CSS.escape(n.animationName));if(n.target===r&&i&&(p(`ANIMATION_END`),!c.current)){let n=r.style.animationFillMode;r.style.animationFillMode=`forwards`,e=t.setTimeout(()=>{r.style.animationFillMode===`forwards`&&(r.style.animationFillMode=n)})}},`handleAnimationEnd`),a=i(e=>{e.target===r&&(l.current=u(s.current))},`handleAnimationStart`);return r.addEventListener(`animationstart`,a),r.addEventListener(`animationcancel`,n),r.addEventListener(`animationend`,n),()=>{t.clearTimeout(e),r.removeEventListener(`animationstart`,a),r.removeEventListener(`animationcancel`,n),r.removeEventListener(`animationend`,n)}}else p(`ANIMATION_END`)},[r,p]),{isPresent:[`mounted`,`unmountSuspended`].includes(f),ref:n.useCallback(e=>{if(e){let t=getComputedStyle(e);s.current=t,d.current=u(t)}else s.current=null;o(e)},[])}}i(s,`usePresence`);function c(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}i(c,`setRef`);function l(...e){let t=n.useRef(e);return t.current=e,n.useCallback(e=>{let n=t.current,r=!1,i=n.map(t=>{let n=c(t,e);return!r&&typeof n==`function`&&(r=!0),n});if(r)return()=>{for(let e=0;e<i.length;e++){let t=i[e];typeof t==`function`?t():c(n[e],null)}}},[])}i(l,`useStableComposedRefs`);function u(e){return e?.animationName||`none`}i(u,`getAnimationName`);function d(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}i(d,`getElementRef`),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
//# sourceMappingURL=dist-odcXV7N3.cjs.map