1 |
- import{bs as R,aS as T,aE as $,bj as B,c as E,n as O,m as z,b,d as H,r as p,bB as N,x as j,e as v,bE as C,ai as D,i as V,w,a3 as _,bD as g,z as A,a4 as u,bI as F,bJ as J,a as y,bk as L,k as M}from"./index-9e15b74c.js";function U(o,f){if(!R||!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),B(s)}const[W,Z]=E("sticky"),q={zIndex:O,position:z("top"),container:Object,offsetTop:b(0),offsetBottom:b(0)};var G=H({name:W,props:q,emits:["scroll","change"],setup(o,{emit:f,slots:r}){const s=p(),d=N(s),e=j({fixed:!1,width:0,height:0,transform:0}),c=p(!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`}}),k=v(()=>{if(!e.fixed||c.value)return;const t=D(V(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}),I=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=L(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}I(P)};return w(()=>e.fixed,t=>f("change",t)),_("scroll",m,{target:d,passive:!0}),U(s,m),w([F,J],()=>{!s.value||g(s)||!e.fixed||(c.value=!0,A(()=>{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:Z({fixed:e.fixed&&!c.value}),style:k.value},[(t=r.default)==null?void 0:t.call(r)])])}}});const Q=M(G);export{Q as S,U as u};
|