"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("../../../../../react/jsx-runtime.js");var e=require("react"),t=require("../../context/MotionConfigContext.mjs.js"),r=require("../../utils/use-composed-ref.mjs.js"),o=require("../../../../../motion-dom/dist/es/utils/is-html-element.mjs.js"),n=require("../../../../../../_virtual/jsx-runtime.js");function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=i(e);class p extends s.Component{getSnapshotBeforeUpdate(e){const t=this.props.childRef.current;if(o.isHTMLElement(t)&&e.isPresent&&!this.props.isPresent&&!1!==this.props.pop){const e=t.offsetParent,r=o.isHTMLElement(e)&&e.offsetWidth||0,n=o.isHTMLElement(e)&&e.offsetHeight||0,i=getComputedStyle(t),s=this.props.sizeRef.current;s.height=parseFloat(i.height),s.width=parseFloat(i.width),s.top=t.offsetTop,s.left=t.offsetLeft,s.right=r-s.width-s.left,s.bottom=n-s.height-s.top,s.direction=i.direction}return null}componentDidUpdate(){}render(){return this.props.children}}exports.PopChild=function(o){let{children:i,isPresent:c,anchorX:u,anchorY:f,root:l,pop:d}=o;const h=e.useId(),a=e.useRef(null),m=e.useRef({width:0,height:0,top:0,left:0,right:0,bottom:0,direction:"ltr"}),{nonce:g}=e.useContext(t.MotionConfigContext),j=i.props?.ref??i?.ref,x=r.useComposedRefs(a,j);return e.useInsertionEffect((()=>{const{width:e,height:t,top:r,left:o,right:n,bottom:i,direction:s}=m.current;if(c||!1===d||!a.current||!e||!t)return;const p="rtl"===s,j="left"===u?p?`right: ${n}`:`left: ${o}`:p?`left: ${o}`:`right: ${n}`,x="bottom"===f?`bottom: ${i}`:`top: ${r}`;a.current.dataset.motionPopId=h;const b=document.createElement("style");g&&(b.nonce=g);const C=l??document.head;return C.appendChild(b),b.sheet&&b.sheet.insertRule(`\n          [data-motion-pop-id="${h}"] {\n            position: absolute !important;\n            width: ${e}px !important;\n            height: ${t}px !important;\n            ${j}px !important;\n            ${x}px !important;\n          }\n        `),()=>{a.current?.removeAttribute("data-motion-pop-id"),C.contains(b)&&C.removeChild(b)}}),[c]),n.exports.jsx(p,{isPresent:c,childRef:a,sizeRef:m,pop:d,children:!1===d?i:s.cloneElement(i,{ref:x})})};
//# sourceMappingURL=PopChild.mjs.js.map
