"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../../context/LazyContext.mjs.js"),o=require("../../context/MotionConfigContext.mjs.js"),n=require("../../context/MotionContext/index.mjs.js"),i=require("../../context/PresenceContext.mjs.js"),r=require("../../context/SwitchLayoutGroupContext.mjs.js"),a=require("../../utils/is-ref-object.mjs.js"),s=require("../../utils/use-isomorphic-effect.mjs.js"),u=require("../../../../../motion-dom/dist/es/animation/optimized-appear/data-id.mjs.js");function c(t){if(t)return!1!==t.options.allowProjection?t.projection:c(t.parent)}exports.useVisualElement=function(l,d,p,m,f,C){const{visualElement:y}=t.useContext(n.MotionContext),j=t.useContext(e.LazyContext),x=t.useContext(i.PresenceContext),M=t.useContext(o.MotionConfigContext),w=M.reducedMotion,h=M.skipAnimations,g=t.useRef(null),q=t.useRef(!1);m=m||j.renderer,!g.current&&m&&(g.current=m(l,{visualState:d,parent:y,props:p,presenceContext:x,blockInitialAnimation:!!x&&!1===x.initial,reducedMotionConfig:w,skipAnimations:h,isSVG:C}),q.current&&g.current&&(g.current.manuallyAnimateOnMount=!0));const A=g.current,S=t.useContext(r.SwitchLayoutGroupContext);!A||A.projection||!f||"html"!==A.type&&"svg"!==A.type||function(t,e,o,n){const{layoutId:i,layout:r,drag:s,dragConstraints:u,layoutScroll:l,layoutRoot:d,layoutAnchor:p,layoutCrossfade:m}=e;t.projection=new o(t.latestValues,e["data-framer-portal-id"]?void 0:c(t.parent)),t.projection.setOptions({layoutId:i,layout:r,alwaysMeasureLayout:Boolean(s)||u&&a.isRefObject(u),visualElement:t,animationType:"string"==typeof r?r:"both",initialPromotionConfig:n,crossfade:m,layoutScroll:l,layoutRoot:d,layoutAnchor:p})}(g.current,p,f,S);const v=t.useRef(!1);t.useInsertionEffect((()=>{A&&v.current&&A.update(p,x)}));const R=p[u.optimizedAppearDataAttribute],I=t.useRef(Boolean(R)&&"undefined"!=typeof window&&!window.MotionHandoffIsComplete?.(R)&&window.MotionHasOptimisedAnimation?.(R));return s.useIsomorphicLayoutEffect((()=>{q.current=!0,A&&(v.current=!0,window.MotionIsMounted=!0,A.updateFeatures(),A.scheduleRenderMicrotask(),I.current&&A.animationState&&A.animationState.animateChanges())})),t.useEffect((()=>{A&&(!I.current&&A.animationState&&A.animationState.animateChanges(),I.current&&(queueMicrotask((()=>{window.MotionHandoffMarkAsComplete?.(R)})),I.current=!1),A.enteringChildren=void 0)})),A};
//# sourceMappingURL=use-visual-element.mjs.js.map
