UNPKG

@tarojs/components

Version:
1 lines 3.38 kB
import{r as t,c as s,h as o,H as i,g as l}from"./p-d0cabaaa.js";import{c as r}from"./p-160d710a.js";import{d as e}from"./p-5893c3ed.js";import{h}from"./p-dbdb9de9.js";import"@tarojs/taro";function c(t,s,o=500,i){if(t===s||"number"!=typeof t)return;const l=s-t,r=Date.now(),e=s>=t;!function h(){var c;c=Date.now()-r,t=l*c/o+t,e&&t>=s||!e&&s>=t?i(s):(i(t),requestAnimationFrame(h))}()}const a=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=e((()=>{const{offsetWidth:t,offsetHeight:s,scrollLeft:o,scrollTop:i,scrollHeight:l,scrollWidth:r}=this.el,e=Number(this.lowerThreshold),h=Number(this.upperThreshold);!isNaN(e)&&(this.scrollY&&s+i+e>=l||this.scrollX&&t+o+e>=r)&&this.onScrollToLower.emit({direction:this.scrollX?"right":this.scrollY?"bottom":""}),!isNaN(h)&&(this.scrollY&&i<=h||this.scrollX&&o<=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 s=Number(t),{animated:o}=this;this.mpScrollToMethod({left:s,animated:o})}watchScrollTop(t){const s=Number(t),{animated:o}=this;this.mpScrollToMethod({top:s,animated:o})}watchScrollIntoView(t){this.mpScrollIntoViewMethod(t)}handleScroll(t){var s;if(t instanceof CustomEvent)return;t.stopPropagation(),null===(s=t.stopImmediatePropagation)||void 0===s||s.call(t);const{scrollLeft:o,scrollTop:i,scrollHeight:l,scrollWidth:r}=this.el;this._scrollLeft=o,this._scrollTop=i,this.upperAndLower(),this.onScroll.emit({scrollLeft:o,scrollTop:i,scrollHeight:l,scrollWidth:r})}handleTouchMove(t){t instanceof CustomEvent||t.stopPropagation()}async mpScrollToMethod(t){let{top:s,left:o,duration:i,animated:l=!1}=t;this.scrollY&&"number"==typeof s&&!isNaN(s)&&s!==this._scrollTop&&(l?c(this._scrollTop,s,i,(t=>this.el.scrollTop=t)):this.el.scrollTop=s,this._scrollTop=s),this.scrollX&&"number"==typeof o&&!isNaN(o)&&o!==this._scrollLeft&&(l?c(this._scrollLeft,o,i,(t=>this.el.scrollLeft=t)):this.el.scrollLeft=o,this._scrollLeft=o)}async mpScrollIntoViewMethod(t){var s;"string"==typeof t&&t&&(null===(s=document.querySelector(`#${t}`))||void 0===s||s.scrollIntoView({behavior:this.animated?"smooth":"auto",block:this.scrollY&&this.mpScrollIntoViewAlignment||"center",inline:this.scrollX&&this.mpScrollIntoViewAlignment||"start"}))}componentDidLoad(){const t=Number(this.mpScrollTop),s=Number(this.mpScrollLeft),{animated:o}=this;this.mpScrollToMethod({top:t,left:s,animated:o})}componentDidRender(){h(this.el)}render(){const{scrollX:t,scrollY:s}=this,l=r({"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"]}}};a.style="taro-scroll-view-core{-webkit-overflow-scrolling:auto;width:100%;display:block}taro-scroll-view-core::-webkit-scrollbar{display:none}.taro-scroll-view__scroll-x{overflow:scroll hidden}.taro-scroll-view__scroll-y{overflow:hidden scroll}";export{a as taro_scroll_view_core}