"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("vue"),I=require("../_util/classNames.js"),M=require("../_util/omit.js"),P=require("../_util/throttleByAnimationFrame.js"),U=require("../_util/type.js"),j=require("../config-provider/hooks/useConfigInject.js"),V=require("../vc-resize-observer/index.js"),z=require("./style/index.js"),r=require("./utils.js");function D(){return typeof window<"u"?window:null}var p=(function(e){return e[e.None=0]="None",e[e.Prepare=1]="Prepare",e})(p||{});function R(){return{offsetTop:Number,offsetBottom:Number,target:{type:Function,default:D},prefixCls:String,onChange:Function,onTestUpdatePosition:Function}}const _=o.defineComponent({compatConfig:{MODE:3},name:"AAffix",inheritAttrs:!1,props:R(),setup(e,{slots:B,emit:q,expose:C,attrs:A}){const u=o.shallowRef(),m=o.shallowRef(),s=o.reactive({affixStyle:void 0,placeholderStyle:void 0,status:p.None,lastAffix:!1,prevTarget:null,timeout:null}),v=o.getCurrentInstance(),x=o.computed(()=>e.offsetBottom===void 0&&e.offsetTop===void 0?0:e.offsetTop),T=o.computed(()=>e.offsetBottom),F=()=>{const{status:a,lastAffix:i}=s,{target:f}=e;if(a!==p.Prepare||!m.value||!u.value||!f)return;const c=f();if(!c)return;const n={status:p.None},t=r.getTargetRect(u.value);if(t.top===0&&t.left===0&&t.width===0&&t.height===0)return;const d=r.getTargetRect(c),S=r.getFixedTop(t,d,x.value),b=r.getFixedBottom(t,d,T.value);if(!(t.top===0&&t.left===0&&t.width===0&&t.height===0)){if(S!==void 0){const g=`${t.width}px`,h=`${t.height}px`;n.affixStyle={position:"fixed",top:S,width:g,height:h},n.placeholderStyle={width:g,height:h}}else if(b!==void 0){const g=`${t.width}px`,h=`${t.height}px`;n.affixStyle={position:"fixed",bottom:b,width:g,height:h},n.placeholderStyle={width:g,height:h}}n.lastAffix=!!n.affixStyle,i!==n.lastAffix&&q("change",n.lastAffix),Object.assign(s,n)}},y=()=>{Object.assign(s,{status:p.Prepare,affixStyle:void 0,placeholderStyle:void 0})},l=P.default(()=>{y()}),w=P.default(()=>{const{target:a}=e,{affixStyle:i}=s;if(a&&i){const f=a();if(f&&u.value){const c=r.getTargetRect(f),n=r.getTargetRect(u.value),t=r.getFixedTop(n,c,x.value),d=r.getFixedBottom(n,c,T.value);if(t!==void 0&&i.top===t||d!==void 0&&i.bottom===d)return}}y()});C({updatePosition:l,lazyUpdatePosition:w}),o.watch(()=>e.target,a=>{const i=a?.()||null;s.prevTarget!==i&&(r.removeObserveTarget(v),i&&(r.addObserveTarget(i,v),l()),s.prevTarget=i)}),o.watch(()=>[e.offsetTop,e.offsetBottom],l),o.onMounted(()=>{const{target:a}=e;a&&(s.timeout=setTimeout(()=>{r.addObserveTarget(a(),v),l()}))}),o.onUpdated(()=>{F()}),o.onUnmounted(()=>{clearTimeout(s.timeout),r.removeObserveTarget(v),l.cancel(),w.cancel()});const{prefixCls:N}=j.default("affix",e),[O,$]=z.default(N);return()=>{const{affixStyle:a,placeholderStyle:i,status:f}=s,c=I.default({[N.value]:a,[$.value]:!0}),n=M.default(e,["prefixCls","offsetTop","offsetBottom","target","onChange","onTestUpdatePosition"]);return O(o.createVNode(V.default,{onResize:l},{default:()=>[o.createVNode("div",{...n,...A,ref:u,"data-measure-status":f},[a&&o.createVNode("div",{style:i,"aria-hidden":"true"},null),o.createVNode("div",{class:c,ref:m,style:a},[B.default?.()])])]}))}}}),E=U.withInstall(_);exports.affixProps=R;exports.default=E;
