index-46efa2bb.js 3.6 KB

1
  1. import{c as $,n as x,m as b,e as N,g as R,b as w,C as p,I as z,k as U,M as j,N as E,w as I,H as G,v as O}from"./index-c2909177.js";import{d as _,r as S,a as Y,o as q,E as F,G as X,y as B,c as i,m as Z,T as J,z as C,l as K}from"./index-e4df6086.js";import{u as Q}from"./index-8665d1db.js";import{L as W}from"./index-29e84163.js";function tt(e,r){let n=null,l=0;return function(...d){if(n)return;const c=Date.now()-l,f=()=>{l=Date.now(),n=!1,e.apply(this,d)};c>=r?f():n=setTimeout(f,r)}}const[et,P]=$("back-top"),at={right:x,bottom:x,zIndex:x,target:[String,Object],offset:b(200),immediate:Boolean,teleport:{type:[String,Object],default:"body"}};var st=_({name:et,inheritAttrs:!1,props:at,emits:["click"],setup(e,{emit:r,slots:n,attrs:l}){let d=!1;const c=S(!1),f=S(),a=S(),h=Y(()=>N(R(e.zIndex),{right:w(e.right),bottom:w(e.bottom)})),D=o=>{var g;r("click",o),(g=a.value)==null||g.scrollTo({top:0,behavior:e.immediate?"auto":"smooth"})},m=()=>{c.value=a.value?E(a.value)>=+e.offset:!1},k=()=>{const{target:o}=e;if(typeof o=="string"){const g=document.querySelector(o);if(g)return g}else return o},u=()=>{U&&C(()=>{a.value=e.target?k():j(f.value),m()})};return p("scroll",tt(m,100),{target:a}),q(u),F(()=>{d&&(c.value=!0,d=!1)}),X(()=>{c.value&&e.teleport&&(c.value=!1,d=!0)}),B(()=>e.target,u),()=>{const o=i("div",Z({ref:e.teleport?void 0:f,class:P({active:c.value}),style:h.value,onClick:D},l),[n.default?n.default():i(z,{name:"back-top",class:P("icon")},null)]);return e.teleport?[i("div",{ref:f,class:P("placeholder")},null),i(J,{to:e.teleport},{default:()=>[o]})]:o}}});const ht=I(st),[nt,T,ot]=$("pull-refresh"),V=50,lt=["pulling","loosing","success"],ct={disabled:Boolean,modelValue:Boolean,headHeight:b(V),successText:String,pullingText:String,loosingText:String,loadingText:String,pullDistance:x,successDuration:b(500),animationDuration:b(300)};var ut=_({name:nt,props:ct,emits:["change","refresh","update:modelValue"],setup(e,{emit:r,slots:n}){let l;const d=S(),c=S(),f=G(d),a=K({status:"normal",distance:0,duration:0}),h=Q(),D=()=>{if(e.headHeight!==V)return{height:`${e.headHeight}px`}},m=()=>a.status!=="loading"&&a.status!=="success"&&!e.disabled,k=t=>{const s=+(e.pullDistance||e.headHeight);return t>s&&(t<s*2?t=s+(t-s)/2:t=s*1.5+(t-s*2)/4),Math.round(t)},u=(t,s)=>{const v=+(e.pullDistance||e.headHeight);a.distance=t,s?a.status="loading":t===0?a.status="normal":t<v?a.status="pulling":a.status="loosing",r("change",{status:a.status,distance:t})},o=()=>{const{status:t}=a;return t==="normal"?"":e[`${t}Text`]||ot(t)},g=()=>{const{status:t,distance:s}=a;if(n[t])return n[t]({distance:s});const v=[];return lt.includes(t)&&v.push(i("div",{class:T("text")},[o()])),t==="loading"&&v.push(i(W,{class:T("loading")},{default:o})),v},A=()=>{a.status="success",setTimeout(()=>{u(0)},+e.successDuration)},y=t=>{l=E(f.value)===0,l&&(a.duration=0,h.start(t))},L=t=>{m()&&y(t)},M=t=>{if(m()){l||y(t);const{deltaY:s}=h;h.move(t),l&&s.value>=0&&h.isVertical()&&(O(t),u(k(s.value)))}},H=()=>{l&&h.deltaY.value&&m()&&(a.duration=+e.animationDuration,a.status==="loosing"?(u(+e.headHeight,!0),r("update:modelValue",!0),C(()=>r("refresh"))):u(0))};return B(()=>e.modelValue,t=>{a.duration=+e.animationDuration,t?u(+e.headHeight,!0):n.success||e.successText?A():u(0,!1)}),p("touchmove",M,{target:c}),()=>{var t;const s={transitionDuration:`${a.duration}ms`,transform:a.distance?`translate3d(0,${a.distance}px, 0)`:""};return i("div",{ref:d,class:T()},[i("div",{ref:c,class:T("track"),style:s,onTouchstartPassive:L,onTouchend:H,onTouchcancel:H},[i("div",{class:T("head"),style:D()},[g()]),(t=n.default)==null?void 0:t.call(n)])])}}});const gt=I(ut);export{ht as B,gt as P};