import{r as t,c as o,h as s,H as i,g as l}from"./p-9137dcab.js";import{c as r}from"./p-de951a46.js";import{d as e}from"./p-d3c7f87d.js";import{h}from"./p-dbdb9de9.js";import"@tarojs/taro";function c(t,o,s=500,i){if(t===o||"number"!=typeof t)return;const l=o-t,r=Date.now(),e=o>=t;!function h(){var c;c=Date.now()-r,t=l*c/s+t,e&&t>=o||!e&&o>=t?i(o):(i(t),requestAnimationFrame(h))}()}const a=class{constructor(s){t(this,s),this.onScroll=o(this,"scroll",3),this.onScrollToUpper=o(this,"scrolltoupper",3),this.onScrollToLower=o(this,"scrolltolower",3),this._scrollLeft=0,this._scrollTop=0,this.upperAndLower=e((()=>{const{offsetWidth:t,offsetHeight:o,scrollLeft:s,scrollTop:i,scrollHeight:l,scrollWidth:r}=this.el,e=Number(this.lowerThreshold),h=Number(this.upperThreshold);!isNaN(e)&&(this.scrollY&&o+i+e>=l||this.scrollX&&t+s+e>=r)&&this.onScrollToLower.emit({direction:this.scrollX?"right":this.scrollY?"bottom":""}),!isNaN(h)&&(this.scrollY&&i<=h||this.scrollX&&s<=h)&&this.onScrollToUpper.emit({direction:this.scrollX?"left":this.scrollY?"top":""})}),200),this.scrollX=!1,this.scrollY=!1,this.upperThreshold=50,this.lowerThreshold=50,this.mpScrollTop=void 0,this.mpScrollLeft=void 0,this.mpScrollIntoView=void 0,this.mpScrollIntoViewAlignment=void 0,this.animated=!1}watchScrollLeft(t){const o=Number(t),{animated:s}=this;this.mpScrollToMethod({left:o,animated:s})}watchScrollTop(t){const o=Number(t),{animated:s}=this;this.mpScrollToMethod({top:o,animated:s})}watchScrollIntoView(t){this.mpScrollIntoViewMethod(t)}handleScroll(t){if(t instanceof CustomEvent)return;t.stopPropagation();const{scrollLeft:o,scrollTop:s,scrollHeight:i,scrollWidth:l}=this.el;this._scrollLeft=o,this._scrollTop=s,this.upperAndLower(),this.onScroll.emit({scrollLeft:o,scrollTop:s,scrollHeight:i,scrollWidth:l})}handleTouchMove(t){t instanceof CustomEvent||t.stopPropagation()}async mpScrollToMethod(t){let{top:o,left:s,duration:i,animated:l=!1}=t;this.scrollY&&"number"==typeof o&&!isNaN(o)&&o!==this._scrollTop&&(l?c(this._scrollTop,o,i,(t=>this.el.scrollTop=t)):this.el.scrollTop=o,this._scrollTop=o),this.scrollX&&"number"==typeof s&&!isNaN(s)&&s!==this._scrollLeft&&(l?c(this._scrollLeft,s,i,(t=>this.el.scrollLeft=t)):this.el.scrollLeft=s,this._scrollLeft=s)}async mpScrollIntoViewMethod(t){var o;"string"==typeof t&&t&&(null===(o=document.querySelector(`#${t}`))||void 0===o||o.scrollIntoView({behavior:this.animated?"smooth":"auto",block:this.scrollY&&this.mpScrollIntoViewAlignment||"center",inline:this.scrollX&&this.mpScrollIntoViewAlignment||"start"}))}componentDidLoad(){const t=Number(this.mpScrollTop),o=Number(this.mpScrollLeft),{animated:s}=this;this.mpScrollToMethod({top:t,left:o,animated:s})}componentDidRender(){h(this.el)}render(){const{scrollX:t,scrollY:o}=this,l=r({"taro-scroll-view__scroll-x":t,"taro-scroll-view__scroll-y":o});return s(i,{class:l},s("slot",null))}get el(){return l(this)}static get watchers(){return{mpScrollLeft:["watchScrollLeft"],mpScrollTop:["watchScrollTop"],mpScrollIntoView:["watchScrollIntoView"]}}};a.style="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}";export{a as taro_scroll_view_core}