index-b8b170d9.js 3.7 KB

1
  1. import{an as L,e as _,aV as $,s as W,l as J,u as K,i as Q,d as X,o as Y,b as U,aq as Z,aR as z}from"./index-fb7a0cf7.js";import{d as k,k as B,r as ee,g as te,e as I,w as F,o as ne,a as ae,b as ie,f as P}from"./vue-18ee037d.js";function R(n){var e,t=function(l){return function(){e=null,n.apply(void 0,_(l))}},a=function(){if(e==null){for(var l=arguments.length,d=new Array(l),c=0;c<l;c++)d[c]=arguments[c];e=L(t(d))}};return a.cancel=function(){return L.cancel(e)},a}function T(n){return n!==window?n.getBoundingClientRect():{top:0,bottom:window.innerHeight}}function H(n,e,t){if(t!==void 0&&e.top>n.top-t)return"".concat(t+e.top,"px")}function M(n,e,t){if(t!==void 0&&e.bottom<n.bottom+t){var a=window.innerHeight-e.bottom;return"".concat(t+a,"px")}}var q=["resize","scroll","touchstart","touchmove","touchend","pageshow","load"],y=[];function j(n,e){if(n){var t=y.find(function(a){return a.target===n});t?t.affixList.push(e):(t={target:n,affixList:[e],eventHandlers:{}},y.push(t),q.forEach(function(a){t.eventHandlers[a]=$(n,a,function(){t.affixList.forEach(function(s){var l=s.exposed.lazyUpdatePosition;l()},(a==="touchstart"||a==="touchmove")&&W?{passive:!0}:!1)})}))}}function V(n){var e=y.find(function(t){var a=t.affixList.some(function(s){return s===n});return a&&(t.affixList=t.affixList.filter(function(s){return s!==n})),a});e&&e.affixList.length===0&&(y=y.filter(function(t){return t!==e}),q.forEach(function(t){var a=e.eventHandlers[t];a&&a.remove&&a.remove()}))}function re(){return typeof window<"u"?window:null}var g;(function(n){n[n.None=0]="None",n[n.Prepare=1]="Prepare"})(g||(g={}));var oe=function(){return{offsetTop:Number,offsetBottom:Number,target:{type:Function,default:re},prefixCls:String,onChange:Function,onTestUpdatePosition:Function}},fe=k({compatConfig:{MODE:3},name:"AAffix",props:oe(),setup:function(e,t){var a=t.slots,s=t.emit,l=t.expose,d=B(),c=B(),f=ee({affixStyle:void 0,placeholderStyle:void 0,status:g.None,lastAffix:!1,prevTarget:null,timeout:null}),m=te(),S=I(function(){return e.offsetBottom===void 0&&e.offsetTop===void 0?0:e.offsetTop}),b=I(function(){return e.offsetBottom}),D=function(){var r=f.status,x=f.lastAffix,v=e.target;if(!(r!==g.Prepare||!c.value||!d.value||!v)){var p=v();if(p){var o={status:g.None},w=T(p),u=T(d.value),N=H(u,w,S.value),E=M(u,w,b.value);N!==void 0?(o.affixStyle={position:"fixed",top:N,width:u.width+"px",height:u.height+"px"},o.placeholderStyle={width:u.width+"px",height:u.height+"px"}):E!==void 0&&(o.affixStyle={position:"fixed",bottom:E,width:u.width+"px",height:u.height+"px"},o.placeholderStyle={width:u.width+"px",height:u.height+"px"}),o.lastAffix=!!o.affixStyle,x!==o.lastAffix&&s("change",o.lastAffix),z(f,o)}}},A=function(){z(f,{status:g.Prepare,affixStyle:void 0,placeholderStyle:void 0}),m.update()},h=R(function(){A()}),C=R(function(){var i=e.target,r=f.affixStyle;if(i&&r){var x=i();if(x&&d.value){var v=T(x),p=T(d.value),o=H(p,v,S.value),w=M(p,v,b.value);if(o!==void 0&&r.top===o||w!==void 0&&r.bottom===w)return}}A()});l({updatePosition:h,lazyUpdatePosition:C}),F(function(){return e.target},function(i){var r=(i==null?void 0:i())||null;f.prevTarget!==r&&(V(m),r&&(j(r,m),h()),f.prevTarget=r)}),F(function(){return[e.offsetTop,e.offsetBottom]},h),ne(function(){var i=e.target;i&&(f.timeout=setTimeout(function(){j(i(),m),h()}))}),ae(function(){D()}),ie(function(){clearTimeout(f.timeout),V(m),h.cancel(),C.cancel()});var G=K("affix",e),O=G.prefixCls;return function(){var i,r=f.affixStyle,x=f.placeholderStyle,v=Q(X({},O.value,r)),p=Y(e,["prefixCls","offsetTop","offsetBottom","target","onChange","onTestUpdatePosition"]);return P(Z,{onResize:h},{default:function(){return[P("div",U(U({},p),{},{style:x,ref:d}),[P("div",{class:v,ref:c,style:r},[(i=a.default)===null||i===void 0?void 0:i.call(a)])])]}})}}});const le=J(fe);export{le as A};