"use strict";const e=require("../../../common/vendor.js"),t=require("../../helper/index.js"),i=require("../../index.js");require("../../helper/test.js"),require("../../helper/digit.js"),require("../../url/index.js"),require("../../store/index.js"),require("../../store/app.js"),require("../../api/promotion/diy.js"),require("../../request/index.js"),require("../../config/index.js"),require("../../platform/index.js"),require("../../platform/provider/wechat/index.js"),require("../../platform/provider/wechat/miniProgram.js"),require("../../api/member/auth.js"),require("../../api/member/social.js"),require("../../api/member/user.js"),require("../../platform/provider/apple/index.js"),require("../../platform/share.js"),require("../../router/index.js"),require("../../hooks/useModal.js"),require("../../api/member/signin.js"),require("../../helper/throttle.js"),require("../../platform/pay.js"),require("../../api/pay/order.js"),require("../../store/user.js"),require("../../store/cart.js"),require("../../api/trade/cart.js"),require("../../api/pay/wallet.js"),require("../../api/trade/order.js"),require("../../api/promotion/coupon.js"),require("../../store/sys.js"),require("../../store/modal.js"),require("../../config/zIndex.js");const s={name:"su-sticky",props:{offsetTop:{type:[String,Number],default:0},customNavHeight:{type:[String,Number],default:i.sheep.$platform.navbar},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.guid(),left:0,width:"auto",height:"auto",fixed:!1}),computed:{style(){const e={};return this.stickyToTop?e.position="static":this.cssSticky?(e.position="sticky",e.zIndex=this.uZindex,e.top=t.addUnit(this.stickyTop)):e.height=this.fixed?this.height+"px":"auto",e.backgroundColor=this.bgColor,t.deepMerge(t.addStyle(this.customStyle),e)},stickyContent(){const e={};return this.cssSticky||(e.position=this.fixed?"fixed":"static",e.top=this.stickyTop+"px",e.left=this.left+"px",e.width="auto"==this.width?"auto":this.width+"px",e.zIndex=this.uZindex),e},uZindex(){return this.zIndex?this.zIndex:970}},mounted(){this.init()},methods:{init(){this.getStickyTop(),this.checkSupportCssSticky(),this.cssSticky||!this.stickyToTop&&this.initObserveContent()},$uGetRect(t,i){return new Promise((s=>{e.index.createSelectorQuery().in(this)[i?"selectAll":"select"](t).boundingClientRect((e=>{i&&Array.isArray(e)&&e.length&&s(e),!i&&e&&s(e)})).exec()}))},initObserveContent(){this.$uGetRect("#"+this.elId).then((e=>{this.height=e.height,this.left=e.left,this.width=e.width,this.$nextTick((()=>{this.observeContent()}))}))},observeContent(){this.disconnectObserver("contentObserver");const t=e.index.createIntersectionObserver({thresholds:[.95,.98,1]});t.relativeToViewport({top:-this.stickyTop}),t.observe(`#${this.elId}`,(e=>{this.setFixed(e.boundingClientRect.top)})),this.contentObserver=t},setFixed(e){const t=e<=this.stickyTop;this.fixed=t},disconnectObserver(e){const t=this[e];t&&t.disconnect()},getStickyTop(){this.stickyTop=t.getPx(this.offsetTop)+t.getPx(this.customNavHeight)},async checkSupportCssSticky(){"android"===t.os()&&Number(t.sys().system)>8&&(this.cssSticky=!0),this.cssSticky=await this.checkComputedStyle(),"ios"===t.os()&&(this.cssSticky=!0)},checkComputedStyle(){return new Promise((t=>{e.index.createSelectorQuery().in(this).select(".u-sticky").fields({computedStyle:["position"]}).exec((e=>{t("sticky"===e[0].position)}))}))},checkCssStickyForH5(){}},beforeDestroy(){this.disconnectObserver("contentObserver")}};const r=e._export_sfc(s,[["render",function(t,i,s,r,o,n){return{a:e.s(n.stickyContent),b:o.elId,c:e.s(n.style)}}],["__scopeId","data-v-8a7972b2"]]);wx.createComponent(r);
