import{r as t,c as s,h as o,H as i,g as l}from"./p-78e3ebb9.js";import{c as e}from"./p-2fad2a65.js";import{d as r}from"./p-d3c7f87d.js";const c="taro-scroll-view-core{display:block;width:100%;-webkit-overflow-scrolling:auto}taro-scroll-view-core::-webkit-scrollbar{display:none}.taro-scroll-view__scroll-x{overflow-x:scroll;overflow-y:hidden}.taro-scroll-view__scroll-y{overflow-x:hidden;overflow-y:scroll}";function h(t,s,o=500,i){if(t===s||typeof t!=="number"){return}const l=s-t;const e=Date.now();const r=s>=t;function c(t,s,o,i){return o*t/i+s}function h(){t=c(Date.now()-e,t,l,o);if(r&&t>=s||!r&&s>=t){i(s);return}i(t);requestAnimationFrame(h)}h()}const n=class{constructor(o){t(this,o);this.onScroll=s(this,"scroll",3);this.onScrollToUpper=s(this,"scrolltoupper",3);this.onScrollToLower=s(this,"scrolltolower",3);this._scrollLeft=0;this._scrollTop=0;this.upperAndLower=r((()=>{const{offsetWidth:t,offsetHeight:s,scrollLeft:o,scrollTop:i,scrollHeight:l,scrollWidth:e}=this.el;const r=Number(this.lowerThreshold);const c=Number(this.upperThreshold);if(!isNaN(r)&&(this.scrollY&&s+i+r>=l||this.scrollX&&t+o+r>=e)){this.onScrollToLower.emit({direction:this.scrollX?"right":this.scrollY?"bottom":""})}if(!isNaN(c)&&(this.scrollY&&i<=c||this.scrollX&&o<=c)){this.onScrollToUpper.emit({direction:this.scrollX?"left":this.scrollY?"top":""})}}),200);this.scrollX=false;this.scrollY=false;this.upperThreshold=50;this.lowerThreshold=50;this.mpScrollTop=undefined;this.mpScrollLeft=undefined;this.mpScrollIntoView=undefined;this.animated=false}watchScrollLeft(t){const s=Number(t);const{animated:o}=this;this.mpScrollToMethod({left:s,animated:o})}watchScrollTop(t){const s=Number(t);const{animated:o}=this;this.mpScrollToMethod({top:s,animated:o})}watchScrollIntoView(t){this.mpScrollIntoViewMethod(t)}handleScroll(t){if(t instanceof CustomEvent)return;t.stopPropagation();const{scrollLeft:s,scrollTop:o,scrollHeight:i,scrollWidth:l}=this.el;this._scrollLeft=s;this._scrollTop=o;this.upperAndLower();this.onScroll.emit({scrollLeft:s,scrollTop:o,scrollHeight:i,scrollWidth:l})}async mpScrollToMethod(t){let{top:s,left:o,duration:i,animated:l=false}=t;if(this.scrollY&&typeof s==="number"&&!isNaN(s)&&s!==this._scrollTop){if(l){h(this._scrollTop,s,i,(t=>this.el.scrollTop=t))}else{this.el.scrollTop=s}this._scrollTop=s}if(this.scrollX&&typeof o==="number"&&!isNaN(o)&&o!==this._scrollLeft){if(l){h(this._scrollLeft,o,i,(t=>this.el.scrollLeft=t))}else{this.el.scrollLeft=o}this._scrollLeft=o}}async mpScrollIntoViewMethod(t){var s;if(typeof t==="string"&&t){(s=document.querySelector(`#${t}`))===null||s===void 0?void 0:s.scrollIntoView({behavior:"smooth",block:"center",inline:"start"})}}componentDidLoad(){const t=Number(this.mpScrollTop);const s=Number(this.mpScrollLeft);const{animated:o}=this;this.mpScrollToMethod({top:t,left:s,animated:o})}render(){const{scrollX:t,scrollY:s}=this;const l=e({"taro-scroll-view__scroll-x":t,"taro-scroll-view__scroll-y":s});return o(i,{class:l},o("slot",null))}get el(){return l(this)}static get watchers(){return{mpScrollLeft:["watchScrollLeft"],mpScrollTop:["watchScrollTop"],mpScrollIntoView:["watchScrollIntoView"]}}};n.style=c;export{n as taro_scroll_view_core};
//# sourceMappingURL=p-359d78f2.entry.js.map