"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("vue"),N=require("./Portal.js"),v=require("./canUseDom.js"),P=require("./hooks/useScrollLocker.js"),w=require("./raf.js"),R=require("./type.js"),S=require("./vue-types/index.js");let u=0;const r=v.default(),C=e=>{if(!r)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=o.defineComponent({compatConfig:{MODE:3},name:"PortalWrapper",inheritAttrs:!1,props:{wrapperClassName:String,forceRender:{type:Boolean,default:void 0},getContainer:S.default.any,visible:{type:Boolean,default:void 0},autoLock:R.booleanType(),didUpdate:Function},setup(e,{slots:q}){const t=o.shallowRef(),m=o.shallowRef(),p=o.shallowRef(),y=o.shallowRef(1),i=v.default()&&document.createElement("div"),b=()=>{t.value===i&&t.value?.parentNode?.removeChild(t.value),t.value=null};let l=null;const c=(n=!1)=>n||t.value&&!t.value.parentNode?(l=C(e.getContainer),l?(l.appendChild(t.value),!0):!1):!0,h=()=>r?(t.value||(t.value=i,c(!0)),g(),t.value):null,g=()=>{const{wrapperClassName:n}=e;t.value&&n&&n!==t.value.className&&(t.value.className=n)};return o.onUpdated(()=>{g(),c()}),P.default(o.computed(()=>e.autoLock&&e.visible&&v.default()&&(t.value===document.body||t.value===i))),o.onMounted(()=>{let n=!1;o.watch([()=>e.visible,()=>e.getContainer],([f,a],[d,s])=>{r&&(l=C(e.getContainer),l===document.body&&(f&&!d?u+=1:n&&(u-=1))),n&&(typeof a=="function"&&typeof s=="function"?a.toString()!==s.toString():a!==s)&&b(),n=!0},{immediate:!0,flush:"post"}),o.nextTick(()=>{c()||(p.value=w.default(()=>{y.value+=1}))})}),o.onBeforeUnmount(()=>{const{visible:n}=e;r&&l===document.body&&(u=n&&u?u-1:u),b(),w.default.cancel(p.value)}),()=>{const{forceRender:n,visible:f}=e;let a=null;const d={getOpenCount:()=>u,getContainer:h};return y.value&&(n||f||m.value)&&(a=o.createVNode(N.default,{getContainer:h,ref:m,didUpdate:e.didUpdate},{default:()=>q.default?.(d)})),a}}});exports.default=U;
