1 |
- import{d8 as I,bx as T,bv as $,dc as B,c as O,n as z,m as H,b as p,d as N,r as w,dg as C,x as E,e as v,di as V,ak as _,i as j,w as b,a4 as A,dh as g,z as D,a5 as u,dm as F,dt as L,a as y,dk as M,k as U}from"./index-d767ef41.js";function W(o,d){if(!I||!window.IntersectionObserver)return;const r=new IntersectionObserver(e=>{d(e[0].intersectionRatio>0)},{root:document.body}),s=()=>{o.value&&r.observe(o.value)},f=()=>{o.value&&r.unobserve(o.value)};T(f),$(f),B(s)}const[Z,q]=O("sticky"),G={zIndex:z,position:H("top"),container:Object,offsetTop:p(0),offsetBottom:p(0)};var J=N({name:Z,props:G,emits:["scroll","change"],setup(o,{emit:d,slots:r}){const s=w(),f=C(s),e=E({fixed:!1,width:0,height:0,transform:0}),c=w(!1),i=v(()=>V(o.position==="top"?o.offsetTop:o.offsetBottom)),k=v(()=>{if(c.value)return;const{fixed:t,height:h,width:n}=e;if(t)return{width:`${n}px`,height:`${h}px`}}),S=v(()=>{if(!e.fixed||c.value)return;const t=_(j(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}),P=t=>d("scroll",{scrollTop:t,isFixed:e.fixed}),m=()=>{if(!s.value||g(s))return;const{container:t,position:h}=o,n=u(s),R=M(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}P(R)};return b(()=>e.fixed,t=>d("change",t)),A("scroll",m,{target:f,passive:!0}),W(s,m),b([F,L],()=>{!s.value||g(s)||!e.fixed||(c.value=!0,D(()=>{const t=u(s);e.width=t.width,e.height=t.height,c.value=!1}))}),()=>{var t;return y("div",{ref:s,style:k.value},[y("div",{class:q({fixed:e.fixed&&!c.value}),style:S.value},[(t=r.default)==null?void 0:t.call(r)])])}}});const Q=U(J);export{Q as S,W as u};
|