index.61ab9823.js 1.9 KB

1
  1. import{aa as I,b1 as T,ab as $,aH as N,t as B,z as H,u as O,w as p,d as z,R as w,ap as _,r as A,y as v,aM as C,N as D,ax as E,Z as b,a0 as M,aA as g,_ as V,an as u,aN as Z,at as j,c as y,ar as F,D as L}from"./index.5f7ffb46.js";function U(o,f){if(!I||!window.IntersectionObserver)return;const r=new IntersectionObserver(e=>{f(e[0].intersectionRatio>0)},{root:document.body}),s=()=>{o.value&&r.observe(o.value)},d=()=>{o.value&&r.unobserve(o.value)};T(d),$(d),N(s)}const[W,q]=B("sticky"),G={zIndex:H,position:O("top"),container:Object,offsetTop:p(0),offsetBottom:p(0)};var J=z({name:W,props:G,emits:["scroll","change"],setup(o,{emit:f,slots:r}){const s=w(),d=_(s),e=A({fixed:!1,width:0,height:0,transform:0}),c=w(!1),i=v(()=>C(o.position==="top"?o.offsetTop:o.offsetBottom)),S=v(()=>{if(c.value)return;const{fixed:t,height:h,width:n}=e;if(t)return{width:`${n}px`,height:`${h}px`}}),R=v(()=>{if(!e.fixed||c.value)return;const t=D(E(o.zIndex),{width:`${e.width}px`,height:`${e.height}px`,[o.position]:`${i.value}px`});return e.transform&&(t.transform=`translate3d(0, ${e.transform}px, 0)`),t}),k=t=>f("scroll",{scrollTop:t,isFixed:e.fixed}),m=()=>{if(!s.value||g(s))return;const{container:t,position:h}=o,n=u(s),P=F(window);if(e.width=n.width,e.height=n.height,h==="top")if(t){const a=u(t),l=a.bottom-i.value-e.height;e.fixed=i.value>n.top&&a.bottom>0,e.transform=l<0?l:0}else e.fixed=i.value>n.top;else{const{clientHeight:a}=document.documentElement;if(t){const l=u(t),x=a-l.top-i.value-e.height;e.fixed=a-i.value<n.bottom&&a>l.top,e.transform=x<0?-x:0}else e.fixed=a-i.value<n.bottom}k(P)};return b(()=>e.fixed,t=>f("change",t)),M("scroll",m,{target:d,passive:!0}),U(s,m),b([Z,j],()=>{!s.value||g(s)||!e.fixed||(c.value=!0,V(()=>{const t=u(s);e.width=t.width,e.height=t.height,c.value=!1}))}),()=>{var t;return y("div",{ref:s,style:S.value},[y("div",{class:q({fixed:e.fixed&&!c.value}),style:R.value},[(t=r.default)==null?void 0:t.call(r)])])}}});const Q=L(J);export{Q as S,U as u};