index.e91b3eaf.js 1.7 KB

1
  1. import{a5 as S,aa as P,a6 as k,ab as I,G as $,H as R,a1 as T,ac as x,d as B,V as O,ad as H,U as N,X as u,ae as V,K as j,af as z,a4 as C,ag as E,j as p,ah as U,Z as h,ai as Z,P as _}from"./index.c8a33855.js";function A(o,l){if(!S||!window.IntersectionObserver)return;const r=new IntersectionObserver(e=>{l(e[0].intersectionRatio>0)},{root:document.body}),n=()=>{o.value&&r.observe(o.value)},f=()=>{o.value&&r.unobserve(o.value)};P(f),k(f),I(n)}const[D,F]=$("sticky"),G={zIndex:R,position:T("top"),container:Object,offsetTop:x(0),offsetBottom:x(0)};var K=B({name:D,props:G,emits:["scroll","change"],setup(o,{emit:l,slots:r}){const n=O(),f=H(n),e=N({fixed:!1,width:0,height:0,transform:0}),i=u(()=>V(o.position==="top"?o.offsetTop:o.offsetBottom)),b=u(()=>{const{fixed:t,height:d,width:s}=e;if(t)return{width:`${s}px`,height:`${d}px`}}),g=u(()=>{if(!e.fixed)return;const t=j(z(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}),w=t=>l("scroll",{scrollTop:t,isFixed:e.fixed}),v=()=>{if(!n.value||U(n))return;const{container:t,position:d}=o,s=h(n),y=Z(window);if(e.width=s.width,e.height=s.height,d==="top")if(t){const a=h(t),c=a.bottom-i.value-e.height;e.fixed=i.value>s.top&&a.bottom>0,e.transform=c<0?c:0}else e.fixed=i.value>s.top;else{const{clientHeight:a}=document.documentElement;if(t){const c=h(t),m=a-c.top-i.value-e.height;e.fixed=a-i.value<s.bottom&&a>c.top,e.transform=m<0?-m:0}else e.fixed=a-i.value<s.bottom}w(y)};return C(()=>e.fixed,t=>l("change",t)),E("scroll",v,{target:f}),A(n,v),()=>{var t;return p("div",{ref:n,style:b.value},[p("div",{class:F({fixed:e.fixed}),style:g.value},[(t=r.default)==null?void 0:t.call(r)])])}}});const M=_(K);export{M as S};