index-97e235af.js 5.1 KB

1
  1. import{r as i,V as L,M as ee,w as g,d as B,c as v,L as R,T as N,h as Y,v as F,a as te,y as oe,o as ne,p as ae,U as se,F as le,m as A}from"./index-9e59d463.js";import{n as b,t as C,F as K,W as ce,U as re,p as M,c as j,C as X,e as $,g as ie,j as H,w as U,y as x,I as ue}from"./index-706bc599.js";import{u as de,a as E}from"./use-scope-id-5881aa3d.js";import{T as D,H as ve}from"./constant-7967f80c.js";import{P as fe,c as me}from"./on-popup-reopen-0a926119.js";let ye=2e3;const he=()=>++ye,V={show:Boolean,zIndex:b,overlay:C,duration:b,teleport:[String,Object],lockScroll:C,lazyRender:C,beforeClose:Function,overlayStyle:Object,overlayClass:K,transitionAppear:Boolean,closeOnClickOverlay:C},pe=Object.keys(V);function Ie(e,t){return e>t?"horizontal":t>e?"vertical":""}function Oe(){const e=i(0),t=i(0),o=i(0),r=i(0),a=i(0),l=i(0),n=i(""),c=i(!0),w=()=>n.value==="vertical",O=()=>n.value==="horizontal",u=()=>{o.value=0,r.value=0,a.value=0,l.value=0,n.value="",c.value=!0};return{move:d=>{const f=d.touches[0];o.value=(f.clientX<0?0:f.clientX)-e.value,r.value=f.clientY-t.value,a.value=Math.abs(o.value),l.value=Math.abs(r.value);const I=10;(!n.value||a.value<I&&l.value<I)&&(n.value=Ie(a.value,l.value)),c.value&&(a.value>D||l.value>D)&&(c.value=!1)},start:d=>{u(),e.value=d.touches[0].clientX,t.value=d.touches[0].clientY},reset:u,startX:e,startY:t,deltaX:o,deltaY:r,offsetX:a,offsetY:l,direction:n,isVertical:w,isHorizontal:O,isTap:c}}let P=0;const _="van-overflow-hidden";function Ce(e,t){const o=Oe(),r="01",a="10",l=u=>{o.move(u);const h=o.deltaY.value>0?a:r,S=re(u.target,e.value),{scrollHeight:d,offsetHeight:f,scrollTop:I}=S;let m="11";I===0?m=f>=d?"00":"01":I+f>=d&&(m="10"),m!=="11"&&o.isVertical()&&!(parseInt(m,2)&parseInt(h,2))&&M(u,!0)},n=()=>{document.addEventListener("touchstart",o.start),document.addEventListener("touchmove",l,{passive:!1}),P||document.body.classList.add(_),P++},c=()=>{P&&(document.removeEventListener("touchstart",o.start),document.removeEventListener("touchmove",l),P--,P||document.body.classList.remove(_))},w=()=>t()&&n(),O=()=>t()&&c();ce(w),L(O),ee(O),g(t,u=>{u?n():c()})}function G(e){const t=i(!1);return g(e,o=>{o&&(t.value=o)},{immediate:!0}),o=>()=>t.value?o():null}const[we,Pe]=j("overlay"),Se={show:Boolean,zIndex:b,duration:b,className:K,lockScroll:C,lazyRender:C,customStyle:Object,teleport:[String,Object]};var ke=B({name:we,props:Se,setup(e,{slots:t}){const o=i(),r=G(()=>e.show||!e.lazyRender),a=n=>{e.lockScroll&&M(n,!0)},l=r(()=>{var n;const c=$(ie(e.zIndex),e.customStyle);return H(e.duration)&&(c.animationDuration=`${e.duration}s`),Y(v("div",{ref:o,style:c,class:[Pe(),e.className]},[(n=t.default)==null?void 0:n.call(t)]),[[F,e.show]])});return X("touchmove",a,{target:o}),()=>{const n=v(R,{name:"van-fade",appear:!0},{default:l});return e.teleport?v(N,{to:e.teleport},{default:()=>[n]}):n}}});const be=U(ke),Te=$({},V,{round:Boolean,position:x("center"),closeIcon:x("cross"),closeable:Boolean,transition:String,iconPrefix:String,closeOnPopstate:Boolean,closeIconPosition:x("top-right"),safeAreaInsetTop:Boolean,safeAreaInsetBottom:Boolean}),[xe,p]=j("popup");var ge=B({name:xe,inheritAttrs:!1,props:Te,emits:["open","close","opened","closed","keydown","update:show","clickOverlay","clickCloseIcon"],setup(e,{emit:t,attrs:o,slots:r}){let a,l;const n=i(),c=i(),w=G(()=>e.show||!e.lazyRender),O=te(()=>{const s={zIndex:n.value};if(H(e.duration)){const y=e.position==="center"?"animationDuration":"transitionDuration";s[y]=`${e.duration}s`}return s}),u=()=>{a||(a=!0,n.value=e.zIndex!==void 0?+e.zIndex:he(),t("open"))},h=()=>{a&&me(e.beforeClose,{done(){a=!1,t("close"),t("update:show",!1)}})},S=s=>{t("clickOverlay",s),e.closeOnClickOverlay&&h()},d=()=>{if(e.overlay)return v(be,A({show:e.show,class:e.overlayClass,zIndex:n.value,duration:e.duration,customStyle:e.overlayStyle,role:e.closeOnClickOverlay?"button":void 0,tabindex:e.closeOnClickOverlay?0:void 0},E(),{onClick:S}),{default:r["overlay-content"]})},f=s=>{t("clickCloseIcon",s),h()},I=()=>{if(e.closeable)return v(ue,{role:"button",tabindex:0,name:e.closeIcon,class:[p("close-icon",e.closeIconPosition),ve],classPrefix:e.iconPrefix,onClick:f},null)};let m;const Z=()=>{m&&clearTimeout(m),m=setTimeout(()=>{t("opened")})},W=()=>t("closed"),q=s=>t("keydown",s),J=w(()=>{var s;const{round:y,position:k,safeAreaInsetTop:T,safeAreaInsetBottom:Q}=e;return Y(v("div",A({ref:c,style:O.value,role:"dialog",tabindex:0,class:[p({round:y,[k]:k}),{"van-safe-area-top":T,"van-safe-area-bottom":Q}],onKeydown:q},o,E()),[(s=r.default)==null?void 0:s.call(r),I()]),[[F,e.show]])}),z=()=>{const{position:s,transition:y,transitionAppear:k}=e,T=s==="center"?"van-fade":`van-popup-slide-${s}`;return v(R,{name:y||T,appear:k,onAfterEnter:Z,onAfterLeave:W},{default:J})};return g(()=>e.show,s=>{s&&!a&&(u(),o.tabindex===0&&oe(()=>{var y;(y=c.value)==null||y.focus()})),!s&&a&&(a=!1,t("close"))}),de({popupRef:c}),Ce(c,()=>e.show&&e.lockScroll),X("popstate",()=>{e.closeOnPopstate&&(h(),l=!1)}),ne(()=>{e.show&&u()}),ae(()=>{l&&(t("update:show",!0),l=!1)}),L(()=>{e.show&&e.teleport&&(h(),l=!0)}),se(fe,()=>e.show),()=>e.teleport?v(N,{to:e.teleport},{default:()=>[d(),z()]}):v(le,null,[d(),z()])}});const Le=U(ge);export{be as O,Le as P,pe as a,V as p,Oe as u};