import{i as e,f as s,g as t,h as a,j as i,k as n,b as o,l as r,m as l}from"./index-9c365a03.js";import{c as d,m as u,a as c,t as g,u as h,b as f,d as m,e as p,i as v,L as x,w as T,n as b,g as D,p as S}from"./index.daaf9893.js";import{u as H}from"./index.feef7c0f.js";const k=Symbol(),[B,V,j]=d("list");const w=T(s({name:B,props:{error:Boolean,offset:u(300),loading:Boolean,disabled:Boolean,finished:Boolean,errorText:String,direction:c("down"),loadingText:String,finishedText:String,immediateCheck:g},emits:["load","update:error","update:loading"],setup(s,{emit:l,slots:d}){const u=t(s.loading),c=t(),g=t(),T=e(k,null),b=h(c),D=()=>{r((()=>{if(u.value||s.finished||s.disabled||s.error||!1===(null==T?void 0:T.value))return;const{direction:e}=s,t=+s.offset,a=p(b);if(!a.height||v(c))return;let i=!1;const n=p(g);i="up"===e?a.top-n.top<=t:n.bottom-a.bottom<=t,i&&(u.value=!0,l("update:loading",!0),l("load"))}))},S=()=>{if(s.finished){const e=d.finished?d.finished():s.finishedText;if(e)return o("div",{class:V("finished-text")},[e])}},H=()=>{l("update:error",!1),D()},B=()=>{if(s.error){const e=d.error?d.error():s.errorText;if(e)return o("div",{role:"button",class:V("error-text"),tabindex:0,onClick:H},[e])}},w=()=>{if(u.value&&!s.finished&&!s.disabled)return o("div",{class:V("loading")},[d.loading?d.loading():o(x,{class:V("loading-icon")},{default:()=>[s.loadingText||j("loading")]})])};return a((()=>[s.loading,s.finished,s.error]),D),T&&a(T,(e=>{e&&D()})),i((()=>{u.value=s.loading})),n((()=>{s.immediateCheck&&D()})),f({check:D}),m("scroll",D,{target:b,passive:!0}),()=>{var e;const t=null==(e=d.default)?void 0:e.call(d),a=o("div",{ref:g,class:V("placeholder")},null);return o("div",{ref:c,role:"feed",class:V(),"aria-busy":u.value},["down"===s.direction?t:a,w(),S(),B(),"up"===s.direction?t:a])}}})),[y,$,C]=d("pull-refresh"),L=["pulling","loosing","success"];const P=T(s({name:y,props:{disabled:Boolean,modelValue:Boolean,headHeight:u(50),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:b,successDuration:u(500),animationDuration:u(300)},emits:["change","refresh","update:modelValue"],setup(e,{emit:s,slots:i}){let n;const d=t(),u=t(),c=h(d),g=l({status:"normal",distance:0,duration:0}),f=H(),p=()=>{if(50!==e.headHeight)return{height:`${e.headHeight}px`}},v=()=>"loading"!==g.status&&"success"!==g.status&&!e.disabled,T=(t,a)=>{const i=+(e.pullDistance||e.headHeight);g.distance=t,g.status=a?"loading":0===t?"normal":t<i?"pulling":"loosing",s("change",{status:g.status,distance:t})},b=()=>{const{status:s}=g;return"normal"===s?"":e[`${s}Text`]||C(s)},k=()=>{const{status:e,distance:s}=g;if(i[e])return i[e]({distance:s});const t=[];return L.includes(e)&&t.push(o("div",{class:$("text")},[b()])),"loading"===e&&t.push(o(x,{class:$("loading")},{default:b})),t},B=e=>{n=0===D(c.value),n&&(g.duration=0,f.start(e))},V=e=>{v()&&B(e)},j=()=>{n&&f.deltaY.value&&v()&&(g.duration=+e.animationDuration,"loosing"===g.status?(T(+e.headHeight,!0),s("update:modelValue",!0),r((()=>s("refresh")))):T(0))};return a((()=>e.modelValue),(s=>{g.duration=+e.animationDuration,s?T(+e.headHeight,!0):i.success||e.successText?(g.status="success",setTimeout((()=>{T(0)}),+e.successDuration)):T(0,!1)})),m("touchmove",(s=>{if(v()){n||B(s);const{deltaY:t}=f;f.move(s),n&&t.value>=0&&f.isVertical()&&(S(s),T((s=>{const t=+(e.pullDistance||e.headHeight);return s>t&&(s=s<2*t?t+(s-t)/2:1.5*t+(s-2*t)/4),Math.round(s)})(t.value)))}}),{target:u}),()=>{var e;const s={transitionDuration:`${g.duration}ms`,transform:g.distance?`translate3d(0,${g.distance}px, 0)`:""};return o("div",{ref:d,class:$()},[o("div",{ref:u,class:$("track"),style:s,onTouchstartPassive:V,onTouchend:j,onTouchcancel:j},[o("div",{class:$("head"),style:p()},[k()]),null==(e=i.default)?void 0:e.call(i)])])}}}));function Y(e){return e<7?["color--danger"]:e<30?["color--warning"]:["color--success"]}export{w as L,P,Y as g};
