index-16c9a443.js 1.9 KB

1
  1. import{bx as R,aX as T,aI as $,bo as O,c as B,n as N,m as z,b as p,d as H,r as b,bG as j,x as C,e as v,bJ as E,aj as V,i as _,w,a4 as A,bI as g,z as D,a5 as u,bN as F,bO as G,a as y,bp as J,k as L}from"./index-85bbea71.js";function M(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),O(s)}const[U,W]=B("sticky"),X={zIndex:N,position:z("top"),container:Object,offsetTop:p(0),offsetBottom:p(0)};var Z=H({name:U,props:X,emits:["scroll","change"],setup(o,{emit:f,slots:r}){const s=b(),d=j(s),e=C({fixed:!1,width:0,height:0,transform:0}),c=b(!1),i=v(()=>E(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=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=J(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)),A("scroll",m,{target:d,passive:!0}),M(s,m),w([F,G],()=>{!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:S.value},[y("div",{class:W({fixed:e.fixed&&!c.value}),style:k.value},[(t=r.default)==null?void 0:t.call(r)])])}}});const K=L(Z);export{K as S,M as u};