import{av as t,ag as e,ah as s,af as i,ad as o,aw as n,ai as c,ax as r,ak as h,d as a,e as d,f as l,g as u,h as y,A as p,p as k}from"./index-45b322f7.js";import{_ as f}from"./_plugin-vue_export-helper.1b428a4d.js";const x=f({name:"su-sticky",props:{offsetTop:{type:[String,Number],default:0},customNavHeight:{type:[String,Number],default:0},stickyToTop:{type:Boolean,default:!1},bgColor:{type:String,default:"transparent"},zIndex:{type:[String,Number],default:""},index:{type:[String,Number],default:""},customStyle:{type:[Object,String],default:()=>({})}},data:()=>({cssSticky:!1,stickyTop:0,elId:t(),left:0,width:"auto",height:"auto",fixed:!1}),computed:{style(){const t={};return this.stickyToTop?t.position="static":this.cssSticky?(t.position="sticky",t.zIndex=this.uZindex,t.top=e(this.stickyTop)):t.height=this.fixed?this.height+"px":"auto",t.backgroundColor=this.bgColor,s(i(this.customStyle),t)},stickyContent(){const t={};return this.cssSticky||(t.position=this.fixed?"fixed":"static",t.top=this.stickyTop+"px",t.left=this.left+"px",t.width="auto"==this.width?"auto":this.width+"px",t.zIndex=this.uZindex),t},uZindex(){return this.zIndex?this.zIndex:970}},mounted(){this.init()},methods:{init(){this.getStickyTop(),this.checkSupportCssSticky(),this.cssSticky||!this.stickyToTop&&this.initObserveContent()},$uGetRect(t,e){return new Promise((s=>{o().in(this)[e?"selectAll":"select"](t).boundingClientRect((t=>{e&&Array.isArray(t)&&t.length&&s(t),!e&&t&&s(t)})).exec()}))},initObserveContent(){this.$uGetRect("#"+this.elId).then((t=>{this.height=t.height,this.left=t.left,this.width=t.width,this.$nextTick((()=>{this.observeContent()}))}))},observeContent(){this.disconnectObserver("contentObserver");const t=n({thresholds:[.95,.98,1]});t.relativeToViewport({top:-this.stickyTop}),t.observe(`#${this.elId}`,(t=>{this.setFixed(t.boundingClientRect.top)})),this.contentObserver=t},setFixed(t){const e=t<=this.stickyTop;this.fixed=e},disconnectObserver(t){const e=this[t];e&&e.disconnect()},getStickyTop(){this.stickyTop=c(this.offsetTop)+c(this.customNavHeight)},checkSupportCssSticky(){return t=this,e=null,s=function*(){this.checkCssStickyForH5()&&(this.cssSticky=!0),"android"===r()&&Number(h().system)>8&&(this.cssSticky=!0),"ios"===r()&&(this.cssSticky=!0)},new Promise(((i,o)=>{var n=t=>{try{r(s.next(t))}catch(e){o(e)}},c=t=>{try{r(s.throw(t))}catch(e){o(e)}},r=t=>t.done?i(t.value):Promise.resolve(t.value).then(n,c);r((s=s.apply(t,e)).next())}));var t,e,s},checkComputedStyle(){},checkCssStickyForH5(){const t=["","-webkit-","-ms-","-moz-","-o-"],e=t.length,s=document.createElement("div");for(let i=0;i<e;i++)if(s.style.position=t[i]+"sticky",""!==s.style.position)return!0;return!1}},beforeDestroy(){this.disconnectObserver("contentObserver")}},[["render",function(t,e,s,i,o,n){const c=k;return a(),d(c,{class:"u-sticky",id:o.elId,style:y([n.style])},{default:l((()=>[u(c,{style:y([n.stickyContent]),class:"u-sticky__content"},{default:l((()=>[p(t.$slots,"default",{},void 0,!0)])),_:3},8,["style"])])),_:3},8,["id","style"])}],["__scopeId","data-v-9c896470"]]);export{x as _};
