const e=require("./type.js"),t=require("./canUseDom.js"),n=require("./raf.js"),r=require("./vue-types/index.js"),i=require("./Portal.js"),a=require("./hooks/useScrollLocker.js");let o=require("vue");var s=0,c=t.default(),l=e=>{if(!c)return null;if(e){if(typeof e==`string`)return document.querySelectorAll(e)[0];if(typeof e==`function`)return e();if(typeof e==`object`&&e instanceof window.HTMLElement)return e}return document.body},u=(0,o.defineComponent)({compatConfig:{MODE:3},name:`PortalWrapper`,inheritAttrs:!1,props:{wrapperClassName:String,forceRender:{type:Boolean,default:void 0},getContainer:r.default.any,visible:{type:Boolean,default:void 0},autoLock:e.booleanType(),didUpdate:Function},setup(e,{slots:r}){let u=(0,o.shallowRef)(),d=(0,o.shallowRef)(),f=(0,o.shallowRef)(),p=(0,o.shallowRef)(1),m=t.default()&&document.createElement(`div`),h=()=>{u.value===m&&u.value?.parentNode?.removeChild(u.value),u.value=null},g=null,_=(t=!1)=>t||u.value&&!u.value.parentNode?(g=l(e.getContainer),g?(g.appendChild(u.value),!0):!1):!0,v=()=>c?(u.value||(u.value=m,_(!0)),y(),u.value):null,y=()=>{let{wrapperClassName:t}=e;u.value&&t&&t!==u.value.className&&(u.value.className=t)};return(0,o.onUpdated)(()=>{y(),_()}),a.default((0,o.computed)(()=>e.autoLock&&e.visible&&t.default()&&(u.value===document.body||u.value===m))),(0,o.onMounted)(()=>{let t=!1;(0,o.watch)([()=>e.visible,()=>e.getContainer],([n,r],[i,a])=>{c&&(g=l(e.getContainer),g===document.body&&(n&&!i?s+=1:t&&--s)),t&&(typeof r==`function`&&typeof a==`function`?r.toString()!==a.toString():r!==a)&&h(),t=!0},{immediate:!0,flush:`post`}),(0,o.nextTick)(()=>{_()||(f.value=n.default(()=>{p.value+=1}))})}),(0,o.onBeforeUnmount)(()=>{let{visible:t}=e;c&&g===document.body&&(s=t&&s?s-1:s),h(),n.default.cancel(f.value)}),()=>{let{forceRender:t,visible:n}=e,a=null,c={getOpenCount:()=>s,getContainer:v};return p.value&&(t||n||d.value)&&(a=(0,o.createVNode)(i.default,{getContainer:v,ref:d,didUpdate:e.didUpdate},{default:()=>r.default?.(c)})),a}}});exports.default=u;