"use strict";const e=require("vue"),C=require("vue-virtual-scroller");;/* empty css                                       */const b={class:"ptr-track"},L={class:"ptr-text"},Y={key:0,class:"ptr-scroller-wrap"},q={key:0,class:"ptr-loadmore"},F={key:1,class:"ptr-finished"},_=e.defineComponent({name:"ClPullToRefresh",__name:"Index",props:{className:String,disabled:Boolean,threshold:{type:Number,default:60},list:{type:Array,default:void 0},minItemSize:{type:Number,default:60},sizeDependencies:{type:Function,default:void 0},finished:Boolean,loading:Boolean,pullIcon:{type:String,default:"ptr-icon-arrow"},loadingIcon:{type:String,default:"ptr-icon-spinner"},loadingText:{type:String,default:"加载中..."},finishedText:{type:String,default:"没有更多了"}},emits:["refresh","loadMore"],setup(l,{expose:V,emit:T}){const o=l,g=T,y=e.ref(),r=e.ref("idle"),i=e.ref(0),S=e.ref(0),a=e.ref(!1),s=e.ref(!1),E=e.ref(0);let n=null,c=0;const u=e.computed(()=>o.threshold||60),d=e.computed(()=>Array.isArray(o.list)),B=e.computed(()=>{const t={};return o.disabled&&(t["ptr-disabled"]=!0),s.value&&(t["ptr-is-pulling"]=!0),o.className&&(t[o.className]=!0),t}),D=e.computed(()=>({height:`${i.value}px`})),x=e.computed(()=>{switch(r.value){case"loading":return"加载中...";case"ready":return"释放即可刷新…";case"pulling":return"下拉即可刷新…";default:return""}}),I=()=>{if(d.value)return E.value<=0;const t=y.value;return t?t.scrollTop<=0:!0},N=t=>"touches"in t?t.touches[0].clientY:t.clientY,w=t=>{E.value=t?.target?.scrollTop||0},A=()=>{!o.finished&&!o.loading&&g("loadMore")},M=()=>{document.addEventListener("mousemove",m),document.addEventListener("mouseup",f)},P=()=>{document.removeEventListener("mousemove",m),document.removeEventListener("mouseup",f)},k=t=>{o.disabled||r.value==="loading"||(S.value=N(t),a.value=!0,"touches"in t||M())},m=t=>{a.value&&(c=N(t)-S.value,c>0&&I()?(s.value||(s.value=!0),t.preventDefault(),n===null&&(n=requestAnimationFrame(()=>{n=null;const p=c*.4;i.value=p,r.value=p>=u.value?"ready":"pulling"}))):s.value&&v())},f=()=>{a.value&&(a.value=!1,P(),n!==null&&(cancelAnimationFrame(n),n=null),s.value&&r.value==="ready"?(r.value="loading",i.value=u.value,g("refresh")):v())},v=()=>{n!==null&&(cancelAnimationFrame(n),n=null),s.value=!1,i.value=0,r.value="idle"};return V({finishRefresh:()=>{v()}}),(t,p)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["cl-pulltorefresh",B.value])},[e.createElementVNode("div",b,[e.createElementVNode("div",{class:"ptr-indicator",style:e.normalizeStyle(D.value)},[e.createElementVNode("div",{class:e.normalizeClass(["ptr-indicator-inner",`ptr-state-${r.value}`])},[e.renderSlot(t.$slots,"indicator",{state:r.value,distance:i.value,threshold:u.value},()=>[e.createElementVNode("i",{class:e.normalizeClass(l.pullIcon)},null,2),e.createElementVNode("span",L,e.toDisplayString(x.value),1)])],2)],4),e.createElementVNode("div",{ref_key:"refElContent",ref:y,class:e.normalizeClass(["ptr-content",{"ptr-content-virtual":d.value}]),onTouchstart:k,onTouchmove:m,onTouchend:f,onMousedown:k},[d.value?(e.openBlock(),e.createElementBlock("div",Y,[e.createVNode(e.unref(C.DynamicScroller),{class:"ptr-scroller",items:l.list,"min-item-size":l.minItemSize,"key-field":"id",onScroll:w,onScrollEnd:A},{default:e.withCtx(({item:h,index:$,active:z})=>[e.createVNode(e.unref(C.DynamicScrollerItem),{item:h,active:z,"size-dependencies":l.sizeDependencies?l.sizeDependencies(h):void 0},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"item",{item:h,index:$,active:z})]),_:2},1032,["item","active","size-dependencies"])]),after:e.withCtx(()=>[l.loading?(e.openBlock(),e.createElementBlock("div",q,[e.renderSlot(t.$slots,"loadMore",{},()=>[e.createElementVNode("i",{class:e.normalizeClass(l.loadingIcon)},null,2),e.createElementVNode("span",null,e.toDisplayString(l.loadingText),1)])])):e.createCommentVNode("",!0),l.finished&&!l.loading?(e.openBlock(),e.createElementBlock("div",F,[e.renderSlot(t.$slots,"finished",{},()=>[e.createElementVNode("span",null,e.toDisplayString(l.finishedText),1)])])):e.createCommentVNode("",!0)]),_:3},8,["items","min-item-size"])])):e.renderSlot(t.$slots,"default",{key:1})],34)])],2))}});module.exports=_;
//# sourceMappingURL=ClPullToRefresh.cjs.map
