index-c1d3cef3.js 5.1 KB

1
  1. import{r as i,V as p,M as ee,w as z,d as B,c as v,L as R,T as N,h as Y,v as K,a as te,z as oe,o as ne,p as ae,U as se,F as le,m as A}from"./index-ddf66cb5.js";import{n as b,t as C,G as M,a3 as D,a4 as ce,a0 as re,p as F,c as X,D as $,e as j,g as ie,k as H,w as G,z as x,H as ue,I as de}from"./index-e9453d64.js";import{u as ve,a as E}from"./use-scope-id-7611483c.js";import{P as fe,c as me}from"./on-popup-reopen-8ab517b6.js";let ye=2e3;const he=()=>++ye,U={show:Boolean,zIndex:b,overlay:C,duration:b,teleport:[String,Object],lockScroll:C,lazyRender:C,beforeClose:Function,overlayStyle:Object,overlayClass:M,transitionAppear:Boolean,closeOnClickOverlay:C},_e=Object.keys(U);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,k=re(u.target,e.value),{scrollHeight:d,offsetHeight:f,scrollTop:I}=k;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))&&F(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),p(O),ee(O),z(t,u=>{u?n():c()})}function V(e){const t=i(!1);return z(e,o=>{o&&(t.value=o)},{immediate:!0}),o=>()=>t.value?o():null}const[we,Pe]=X("overlay"),ke={show:Boolean,zIndex:b,duration:b,className:M,lockScroll:C,lazyRender:C,customStyle:Object,teleport:[String,Object]};var Se=B({name:we,props:ke,setup(e,{slots:t}){const o=i(),r=V(()=>e.show||!e.lazyRender),a=n=>{e.lockScroll&&F(n,!0)},l=r(()=>{var n;const c=j(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)]),[[K,e.show]])});return $("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=G(Se),Te=j({},U,{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,L]=X("popup");var ze=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=V(()=>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)}})},k=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:k}),{default:r["overlay-content"]})},f=s=>{t("clickCloseIcon",s),h()},I=()=>{if(e.closeable)return v(de,{role:"button",tabindex:0,name:e.closeIcon,class:[L("close-icon",e.closeIconPosition),ue],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:S,safeAreaInsetTop:T,safeAreaInsetBottom:Q}=e;return Y(v("div",A({ref:c,style:O.value,role:"dialog",tabindex:0,class:[L({round:y,[S]:S}),{"van-safe-area-top":T,"van-safe-area-bottom":Q}],onKeydown:q},o,E()),[(s=r.default)==null?void 0:s.call(r),I()]),[[K,e.show]])}),g=()=>{const{position:s,transition:y,transitionAppear:S}=e,T=s==="center"?"van-fade":`van-popup-slide-${s}`;return v(R,{name:y||T,appear:S,onAfterEnter:Z,onAfterLeave:W},{default:J})};return z(()=>e.show,s=>{s&&!a&&(u(),o.tabindex===0&&oe(()=>{var y;(y=c.value)==null||y.focus()})),!s&&a&&(a=!1,t("close"))}),ve({popupRef:c}),Ce(c,()=>e.show&&e.lockScroll),$("popstate",()=>{e.closeOnPopstate&&(h(),l=!1)}),ne(()=>{e.show&&u()}),ae(()=>{l&&(t("update:show",!0),l=!1)}),p(()=>{e.show&&e.teleport&&(h(),l=!0)}),se(fe,()=>e.show),()=>e.teleport?v(N,{to:e.teleport},{default:()=>[d(),g()]}):v(le,null,[d(),g()])}});const Le=G(ze);export{be as O,Le as P,_e as a,U as p,Oe as u};