import{G as _,ac as h,H as b,d as y,V as U,ad as $,U as w,aj as A,a4 as N,j as c,aU as Y,ar as j,Y as p,ai as B,P as G}from"./ResizeObserver.es.62ab429c.js";const[I,r,L]=_("pull-refresh"),S=50,M=["pulling","loosing","success"],R={disabled:Boolean,modelValue:Boolean,headHeight:h(S),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:b,successDuration:h(500),animationDuration:h(300)};var C=y({name:I,props:R,emits:["refresh","update:modelValue"],setup(s,{emit:f,slots:o}){let u;const g=U(),D=$(g),e=w({status:"normal",distance:0,duration:0}),i=A(),x=()=>{if(s.headHeight!==S)return{height:`${s.headHeight}px`}},d=()=>e.status!=="loading"&&e.status!=="success"&&!s.disabled,H=t=>{const a=+(s.pullDistance||s.headHeight);return t>a&&(t<a*2?t=a+(t-a)/2:t=a*1.5+(t-a*2)/4),Math.round(t)},n=(t,a)=>{const l=+(s.pullDistance||s.headHeight);e.distance=t,a?e.status="loading":t===0?e.status="normal":t<l?e.status="pulling":e.status="loosing"},T=()=>{const{status:t}=e;return t==="normal"?"":s[`${t}Text`]||L(t)},P=()=>{const{status:t,distance:a}=e;if(o[t])return o[t]({distance:a});const l=[];return M.includes(t)&&l.push(c("div",{class:r("text")},[T()])),t==="loading"&&l.push(c(Y,{class:r("loading")},{default:T})),l},V=()=>{e.status="success",setTimeout(()=>{n(0)},+s.successDuration)},m=t=>{u=B(D.value)===0,u&&(e.duration=0,i.start(t))},k=t=>{d()&&m(t)},E=t=>{if(d()){u||m(t);const{deltaY:a}=i;i.move(t),u&&a.value>=0&&i.isVertical()&&(j(t),n(H(a.value)))}},v=()=>{u&&i.deltaY.value&&d()&&(e.duration=+s.animationDuration,e.status==="loosing"?(n(+s.headHeight,!0),f("update:modelValue",!0),p(()=>f("refresh"))):n(0))};return N(()=>s.modelValue,t=>{e.duration=+s.animationDuration,t?n(+s.headHeight,!0):o.success||s.successText?V():n(0,!1)}),()=>{var t;const a={transitionDuration:`${e.duration}ms`,transform:e.distance?`translate3d(0,${e.distance}px, 0)`:""};return c("div",{ref:g,class:r()},[c("div",{class:r("track"),style:a,onTouchstart:k,onTouchmove:E,onTouchend:v,onTouchcancel:v},[c("div",{class:r("head"),style:x()},[P()]),(t=o.default)==null?void 0:t.call(o)])])}}});const X=G(C);export{X as P};
